@@ -903,6 +903,17 @@ int os::current_process_id() {
903
903
904
904
const char * os::dll_file_extension () { return JNI_LIB_SUFFIX; }
905
905
906
+ static int local_dladdr (const void * addr, Dl_info* info) {
907
+ #ifdef __APPLE__
908
+ if (addr == (void *)-1 ) {
909
+ // dladdr() in macOS12/Monterey returns success for -1, but that addr
910
+ // value should not be allowed to work to avoid confusion.
911
+ return 0 ;
912
+ }
913
+ #endif
914
+ return dladdr (addr, info);
915
+ }
916
+
906
917
// This must be hard coded because it's the system's temporary
907
918
// directory not the java application's temp directory, ala java.io.tmpdir.
908
919
#ifdef __APPLE__
@@ -942,19 +953,15 @@ bool os::address_is_in_vm(address addr) {
942
953
return false ;
943
954
}
944
955
945
-
946
- #define MACH_MAXSYMLEN 256
947
-
948
956
bool os::dll_address_to_function_name (address addr, char *buf,
949
957
int buflen, int *offset,
950
958
bool demangle) {
951
959
// buf is not optional, but offset is optional
952
960
assert (buf != NULL , " sanity check" );
953
961
954
962
Dl_info dlinfo;
955
- char localbuf[MACH_MAXSYMLEN];
956
963
957
- if (dladdr ((void *)addr, &dlinfo) != 0 ) {
964
+ if (local_dladdr ((void *)addr, &dlinfo) != 0 ) {
958
965
// see if we have a matching symbol
959
966
if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL ) {
960
967
if (!(demangle && Decoder::demangle (dlinfo.dli_sname , buf, buflen))) {
@@ -963,6 +970,14 @@ bool os::dll_address_to_function_name(address addr, char *buf,
963
970
if (offset != NULL ) *offset = addr - (address)dlinfo.dli_saddr ;
964
971
return true ;
965
972
}
973
+
974
+ #ifndef __APPLE__
975
+ // The 6-parameter Decoder::decode() function is not implemented on macOS.
976
+ // The Mach-O binary format does not contain a "list of files" with address
977
+ // ranges like ELF. That makes sense since Mach-O can contain binaries for
978
+ // than one instruction set so there can be more than one address range for
979
+ // each "file".
980
+
966
981
// no matching symbol so try for just file info
967
982
if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL ) {
968
983
if (Decoder::decode ((address)(addr - (address)dlinfo.dli_fbase ),
@@ -971,6 +986,10 @@ bool os::dll_address_to_function_name(address addr, char *buf,
971
986
}
972
987
}
973
988
989
+ #else // __APPLE__
990
+ #define MACH_MAXSYMLEN 256
991
+
992
+ char localbuf[MACH_MAXSYMLEN];
974
993
// Handle non-dynamic manually:
975
994
if (dlinfo.dli_fbase != NULL &&
976
995
Decoder::decode (addr, localbuf, MACH_MAXSYMLEN, offset,
@@ -980,6 +999,9 @@ bool os::dll_address_to_function_name(address addr, char *buf,
980
999
}
981
1000
return true ;
982
1001
}
1002
+
1003
+ #undef MACH_MAXSYMLEN
1004
+ #endif // __APPLE__
983
1005
}
984
1006
buf[0 ] = ' \0 ' ;
985
1007
if (offset != NULL ) *offset = -1 ;
@@ -994,7 +1016,7 @@ bool os::dll_address_to_library_name(address addr, char* buf,
994
1016
995
1017
Dl_info dlinfo;
996
1018
997
- if (dladdr ((void *)addr, &dlinfo) != 0 ) {
1019
+ if (local_dladdr ((void *)addr, &dlinfo) != 0 ) {
998
1020
if (dlinfo.dli_fname != NULL ) {
999
1021
jio_snprintf (buf, buflen, " %s" , dlinfo.dli_fname );
1000
1022
}
0 commit comments