Exporting symbols on OSX ?

David DeHaven david.dehaven at oracle.com
Tue May 7 23:53:49 UTC 2013

>>> We just discovered that every symbol is libjvm is being exported on OSX. The OSX/BSD makefiles were copied from the linux ones and so have the options for linker scripts and mapfiles, but as OSX doesn't support linker scripts this is disabled by setting LDNOMAP=true - hence all symbols are exported.
>>> However the OSX linker does support -exported_symbols_list
>>> https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/ld.1.html
>>> so I was wondering why the build wasn't modified to use that so that we only export the JVM symbols we intend to export? (That's a question for the macosx-port-dev folk :) ).
>>> Does anyone have experience using this such that we can get the hotspot build fixed?
>> Exports should be handled by the visibility settings. Until recently the JNIEXPORT macro resolved to nothing, now it sets __attribute__(("visibility" ("default))) (at least in 8, that should be backported to 7u if it hasn't already). The "default" visibility means export that symbol. To hide non-exported symbols you need to provide --fvisibility=hidden to gcc or clang when compiling.
>> Hotspot has it's own jni_md.h headers with macros to determine JNIEXPORT, but they were wrong last I checked. It appears they attempted to clear the macro if a certain version of gcc was used, but what happens is it disables it for all versions of gcc above a particular release (which hasn't been used on Mac is quite some time). I pointed this out when the JNIEXPORT patch was posted for review to core-libs-dev (I think...), it was CC'd to the hotspot list too so someone has to have seen it. I'm not sure if it's been fixed or not.
> The visibility setting changes should aid with the primary exported interfaces (JNI_ and JVM_) but looking at the build there are other symbols (for Serviceability Agent I think) that get dynamically added to the mapfiles - so I'm not sure if the visibility setting alone will help here. I think we will still want the "exported_symbol_file" (but it seems whatever ld we are using for OSX builds doesn't actually recognize that option ?? :(  Or I'm doing something wrong in trying to pass it)

Apple's ld supports "-exported_symbols_list filename" which is similar to (but not the same as) export map files for GNU ld. I don't know if the use of that argument overrides the -fvisibility setting though. Some minor experimentation should provide answers to that question...

Can those symbols just be marked with JNIEXPORT or some similar macro?


More information about the build-dev mailing list