From 5d9baa2f9385d66cdf2ff8f065d165385eb48a22 Mon Sep 17 00:00:00 2001 From: JoKern65 Date: Fri, 28 Apr 2023 13:07:53 +0000 Subject: [PATCH] 8306672: support offset in dll_address_to_library_name on AIX Reviewed-by: stuefe, clanger, mbaesken --- src/hotspot/os/aix/os_aix.cpp | 14 ++++++++++++-- src/hotspot/os/aix/porting_aix.cpp | 20 +++++++++++++++++++- src/hotspot/os/aix/porting_aix.hpp | 10 +++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/hotspot/os/aix/os_aix.cpp b/src/hotspot/os/aix/os_aix.cpp index e0b24e639db..fe86adcc40a 100644 --- a/src/hotspot/os/aix/os_aix.cpp +++ b/src/hotspot/os/aix/os_aix.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2012, 2021 SAP SE. All rights reserved. + * Copyright (c) 2012, 2023 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1077,7 +1077,17 @@ bool os::dll_address_to_library_name(address addr, char* buf, return false; } - return AixSymbols::get_module_name(addr, buf, buflen); + address base = nullptr; + if (!AixSymbols::get_module_name_and_base(addr, buf, buflen, &base) + || base == nullptr) { + return false; + } + assert(addr >= base && addr <= base + INT_MAX, "address not in library text range"); + if (offset != nullptr) { + *offset = addr - base; + } + + return true; } // Loads .dll/.so and in case of error it checks if .dll/.so was built diff --git a/src/hotspot/os/aix/porting_aix.cpp b/src/hotspot/os/aix/porting_aix.cpp index 1d6ce26f5a1..ab84dc81027 100644 --- a/src/hotspot/os/aix/porting_aix.cpp +++ b/src/hotspot/os/aix/porting_aix.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019 SAP SE. All rights reserved. + * Copyright (c) 2012, 2023 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -278,6 +278,24 @@ bool AixSymbols::get_module_name(address pc, return false; } +bool AixSymbols::get_module_name_and_base(address pc, + char* p_name, size_t namelen, + address* p_base) { + + if (p_base && p_name && namelen > 0) { + p_name[0] = '\0'; + loaded_module_t lm; + if (LoadedLibraries::find_for_text_address(pc, &lm)) { + strncpy(p_name, lm.shortname, namelen); + p_name[namelen - 1] = '\0'; + *p_base = (address) lm.text; + return true; + } + } + + return false; +} + // Special implementation of dladdr for Aix based on LoadedLibraries // Note: dladdr returns non-zero for ok, 0 for error! // Note: dladdr is not posix, but a non-standard GNU extension. So this tries to diff --git a/src/hotspot/os/aix/porting_aix.hpp b/src/hotspot/os/aix/porting_aix.hpp index 5c02d0efa88..2c4c0e002a8 100644 --- a/src/hotspot/os/aix/porting_aix.hpp +++ b/src/hotspot/os/aix/porting_aix.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015 SAP SE. All rights reserved. + * Copyright (c) 2012, 2023 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -83,6 +83,14 @@ class AixSymbols { char* p_name, size_t namelen // [out] module name ); + // Given a program counter, returns the name of the module (library and module) the pc points to + // and the base address of the module the pc points to + static bool get_module_name_and_base ( + address pc, // [in] program counter + char* p_name, size_t namelen, // [out] module name + address* p_base // [out] base address of library + ); + }; class AixNativeCallstack {