-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8273967: gtest os.dll_address_to_function_and_library_name_vm fails on macOS12 #6193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -838,6 +838,17 @@ int os::current_process_id() { | |
|
|
||
| const char* os::dll_file_extension() { return JNI_LIB_SUFFIX; } | ||
|
|
||
| static int local_dladdr(const void* addr, Dl_info* info) { | ||
| #ifdef __APPLE__ | ||
| if (addr == (void*)-1) { | ||
| // dladdr() in macOS12/Monterey returns success for -1, but that addr | ||
| // value should not be allowed to work to avoid confusion. | ||
| return 0; | ||
| } | ||
| #endif | ||
| return dladdr(addr, info); | ||
| } | ||
|
|
||
| // This must be hard coded because it's the system's temporary | ||
| // directory not the java application's temp directory, ala java.io.tmpdir. | ||
| #ifdef __APPLE__ | ||
|
|
@@ -877,19 +888,15 @@ bool os::address_is_in_vm(address addr) { | |
| return false; | ||
| } | ||
|
|
||
|
|
||
| #define MACH_MAXSYMLEN 256 | ||
|
|
||
| bool os::dll_address_to_function_name(address addr, char *buf, | ||
| int buflen, int *offset, | ||
| bool demangle) { | ||
| // buf is not optional, but offset is optional | ||
| assert(buf != NULL, "sanity check"); | ||
|
|
||
| Dl_info dlinfo; | ||
| char localbuf[MACH_MAXSYMLEN]; | ||
|
|
||
| if (dladdr((void*)addr, &dlinfo) != 0) { | ||
| if (local_dladdr((void*)addr, &dlinfo) != 0) { | ||
| // see if we have a matching symbol | ||
| if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL) { | ||
| if (!(demangle && Decoder::demangle(dlinfo.dli_sname, buf, buflen))) { | ||
|
|
@@ -898,6 +905,14 @@ bool os::dll_address_to_function_name(address addr, char *buf, | |
| if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr; | ||
| return true; | ||
| } | ||
|
|
||
| #ifndef __APPLE__ | ||
| // The 6-parameter Decoder::decode() function is not implemented on macOS. | ||
| // The Mach-O binary format does not contain a "list of files" with address | ||
| // ranges like ELF. That makes sense since Mach-O can contain binaries for | ||
| // than one instruction set so there can be more than one address range for | ||
| // each "file". | ||
|
|
||
| // no matching symbol so try for just file info | ||
| if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) { | ||
| if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase), | ||
|
|
@@ -906,6 +921,10 @@ bool os::dll_address_to_function_name(address addr, char *buf, | |
| } | ||
| } | ||
|
|
||
| #else // __APPLE__ | ||
| #define MACH_MAXSYMLEN 256 | ||
|
|
||
| char localbuf[MACH_MAXSYMLEN]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This here (i.e. just the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm.... I'll take a look at cleaning this up a bit. |
||
| // Handle non-dynamic manually: | ||
| if (dlinfo.dli_fbase != NULL && | ||
| Decoder::decode(addr, localbuf, MACH_MAXSYMLEN, offset, | ||
|
|
@@ -915,6 +934,9 @@ bool os::dll_address_to_function_name(address addr, char *buf, | |
| } | ||
| return true; | ||
| } | ||
|
|
||
| #undef MACH_MAXSYMLEN | ||
| #endif // __APPLE__ | ||
| } | ||
| buf[0] = '\0'; | ||
| if (offset != NULL) *offset = -1; | ||
|
|
@@ -929,7 +951,7 @@ bool os::dll_address_to_library_name(address addr, char* buf, | |
|
|
||
| Dl_info dlinfo; | ||
|
|
||
| if (dladdr((void*)addr, &dlinfo) != 0) { | ||
| if (local_dladdr((void*)addr, &dlinfo) != 0) { | ||
| if (dlinfo.dli_fname != NULL) { | ||
| jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit, it seems confusing to have a Mac-specific comment in the BSD section.
Maybe this would be better in MachDecoder? E.g. implement the 6-arg version of decode() but stubbed out returning false, and with your comment there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually fairly common to have Mac-specific stuff in the BSD files. The macOS
port was built on top of the BSD port and the BSD port was built by copying a LOT
of code from Linux into BSD specific files with modifications as needed.
If I pushed this change down into MachDecoder, then I would have to lose the
ShouldNotReachHere()call in order to not assert in non-release bits. I don'tthink I want to do that since this may not be the only place that calls the
6-arg version of decode().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always wondered whether anyone actually builds the BSDs in head. I assume Oracle does not, right? I know there are downstream porters somewhere but only for old releases, or?
Fair enough, thanks for the clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oracle does not build BSD in head. At one point, Dmitry Samersoff used to build BSD
in his lab, but I don't know if he still does that.