Skip to content

Commit f57d7f0

Browse files
committed
8273967.cr0.patch
1 parent b7104ba commit f57d7f0

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

src/hotspot/os/bsd/decoder_machO.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ bool MachODecoder::demangle(const char* symbol, char *buf, int buflen) {
5252

5353
bool MachODecoder::decode(address addr, char *buf,
5454
int buflen, int *offset, const void *mach_base) {
55+
if (addr == (address)(intptr_t)-1) {
56+
// dladdr() in macOS12/Monterey returns success for -1, but that addr value
57+
// won't work in this function. Should have been handled by the caller.
58+
ShouldNotReachHere();
59+
return false;
60+
}
5561
struct symtab_command * symt = (struct symtab_command *)
5662
mach_find_command((struct mach_header_64 *)mach_base, LC_SYMTAB);
5763
if (symt == NULL) {

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,9 @@ bool os::address_is_in_vm(address addr) {
878878
}
879879

880880

881+
#if defined(__APPLE__)
881882
#define MACH_MAXSYMLEN 256
883+
#endif
882884

883885
bool os::dll_address_to_function_name(address addr, char *buf,
884886
int buflen, int *offset,
@@ -887,9 +889,18 @@ bool os::dll_address_to_function_name(address addr, char *buf,
887889
assert(buf != NULL, "sanity check");
888890

889891
Dl_info dlinfo;
890-
char localbuf[MACH_MAXSYMLEN];
891892

892893
if (dladdr((void*)addr, &dlinfo) != 0) {
894+
#if defined(__APPLE__)
895+
if (addr == (address)(intptr_t)-1) {
896+
// dladdr() in macOS12/Monterey returns success for -1, but that addr
897+
// value should not be allowed to work to avoid confusion.
898+
buf[0] = '\0';
899+
if (offset) *offset = -1;
900+
return false;
901+
}
902+
#endif
903+
893904
// see if we have a matching symbol
894905
if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL) {
895906
if (!(demangle && Decoder::demangle(dlinfo.dli_sname, buf, buflen))) {
@@ -898,14 +909,25 @@ bool os::dll_address_to_function_name(address addr, char *buf,
898909
if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
899910
return true;
900911
}
912+
913+
#if !defined(__APPLE__)
914+
// The 6-parameter Decoder::decode() function is not implemented on macOS.
915+
// The Mach-O binary format does not contain a "list of files" with address
916+
// ranges like ELF. That makes sense since Mach-O can contain binaries for
917+
// than one instruction set so there can be more than one address range for
918+
// each "file".
919+
901920
// no matching symbol so try for just file info
902921
if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) {
903922
if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
904923
buf, buflen, offset, dlinfo.dli_fname, demangle)) {
905924
return true;
906925
}
907926
}
927+
#endif
908928

929+
#if defined(__APPLE__)
930+
char localbuf[MACH_MAXSYMLEN];
909931
// Handle non-dynamic manually:
910932
if (dlinfo.dli_fbase != NULL &&
911933
Decoder::decode(addr, localbuf, MACH_MAXSYMLEN, offset,
@@ -916,6 +938,8 @@ bool os::dll_address_to_function_name(address addr, char *buf,
916938
return true;
917939
}
918940
}
941+
#endif
942+
919943
buf[0] = '\0';
920944
if (offset != NULL) *offset = -1;
921945
return false;
@@ -930,6 +954,16 @@ bool os::dll_address_to_library_name(address addr, char* buf,
930954
Dl_info dlinfo;
931955

932956
if (dladdr((void*)addr, &dlinfo) != 0) {
957+
#if defined(__APPLE__)
958+
if (addr == (address)(intptr_t)-1) {
959+
// dladdr() in macOS12/Monterey returns success for -1, but that addr
960+
// value should not be allowed to work to avoid confusion.
961+
buf[0] = '\0';
962+
if (offset) *offset = -1;
963+
return false;
964+
}
965+
#endif
966+
933967
if (dlinfo.dli_fname != NULL) {
934968
jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
935969
}

src/hotspot/share/runtime/os.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ bool os::print_function_and_library_name(outputStream* st,
907907
addr = addr2;
908908
}
909909
}
910-
#endif // HANDLE_FUNCTION_DESCRIPTORS
910+
#endif // HAVE_FUNCTION_DESCRIPTORS
911911

912912
if (have_function_name) {
913913
// Print function name, optionally demangled

test/hotspot/gtest/runtime/test_os.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -709,11 +709,7 @@ TEST_VM(os, pagesizes_test_print) {
709709
ASSERT_EQ(strcmp(expected, buffer), 0);
710710
}
711711

712-
#if defined(__APPLE__) // See JDK-8273967.
713-
TEST_VM(os, DISABLED_dll_address_to_function_and_library_name) {
714-
#else
715-
TEST_VM(os, dll_address_to_function_and_library_name) {
716-
#endif
712+
TEST_VM(os, dll_address_to_function_and_library_name) {
717713
char tmp[1024];
718714
char output[1024];
719715
stringStream st(output, sizeof(output));
@@ -726,8 +722,10 @@ TEST_VM(os, pagesizes_test_print) {
726722
#define LOG(...)
727723

728724
// Invalid addresses
725+
LOG("os::print_function_and_library_name(st, -1) expects FALSE.");
729726
address addr = (address)(intptr_t)-1;
730727
EXPECT_FALSE(os::print_function_and_library_name(&st, addr));
728+
LOG("os::print_function_and_library_name(st, NULL) expects FALSE.");
731729
addr = NULL;
732730
EXPECT_FALSE(os::print_function_and_library_name(&st, addr));
733731

0 commit comments

Comments
 (0)