Why do we need both - export maps AND -fvisibility=hidden/__attribute__((visibility("default")))

Volker Simonis volker.simonis at gmail.com
Tue Feb 4 08:18:58 PST 2014


I know this is an old topic and actually I was involved myself in some
of these discussions. Nevertheless, the topic regularly pops up again
and every time this happens and I take a deeper look at the topic I
have the feeling I still haven’t completely understood it.

Current state:

On Linux, we are currently compiling the HotSpot with the
'-fvisibility=hidden' flag which effectively hides all symbols except
the ones which are explicitely declared to have default visibility
(with the macro JNIEXPORT which expands to

This was introduced by "6588413: Use -fvisibility=hidden for gcc
compiles" [1] in HS 21 and it is potentially a good change because it
hides all symbols by default and it enables certain compiler
optimizations on some platforms (see "How To Write Shared Libraries"

However, independently of this change, we still use export maps (i.e.
--version-script=mapfile_reorder) in addition to setting the explicit
symbol visibility. While [2] recommends this as good practice, I don't
see the real benefit of having both -
-fvisibility=hidden/__attribute__((visibility("default"))) and export
maps except if we were maintaining a versioned ABI. But as far as I
can tell, that's not the case for HotSpot.

So finally my question: is there any real reason (except the fact that
"we always did it that way") why we would still need to use export
maps on Linux where symbol hiding is done with
-fvisibility=hidden/__attribute__((visibility("default"))) anyway?
Dropping the maps would make the maintenance of exported symbols
easier as we wouldn't have to keep the export map files and the
JNIEXPORT functions in sync.

Thank you and best regards,

[1] https://bugs.openjdk.java.net/browse/JDK-6588413
[2] http://www.akkadia.org/drepper/dsohowto.pdf

More information about the hotspot-dev mailing list