RFR: 8345683: Remove special flags for files compiled for static libraries
Magnus Ihse Bursie
ihse at openjdk.org
Fri Dec 6 15:11:46 UTC 2024
For various reasons, we have added some extra flags to the compiler command line when compiling C/C++ for static libraries. This is a blocker for the goal of compiling once, linking twice for static and dynamic library. Fortunately, these extra flags are not needed.
Note that `-DSTATIC_BUILD=1` is still kept, but set in `SetupNativeCompilation`. Going forward, this flag should only be sent to the very small set of files that actually need to know if we're creating a static or dynamic library. (But that is a future follow-up.)
The flags I removed, with rationales for removing them:
* (gcc/clang) `ffunction-sections -fdata-sections`: This forces the compiler to create a separate section for each and every function and data entry. The idea is that the linker can use this to get rid of dead code when creating the static library, and hence saving space. The idea is perhaps good, but it does not work. libjvm.so gets about 10% **larger** with these flags than without them, so they are not only useless, but actually harmful.
* (gcc/clang) `-DJNIEXPORT='__attribute__((visibility("default")))'`: This is default now anyway so it does not contribute anything.
* (microsoft)`-DJNIEXPORT=`: The static launcher still does not work fully on Windows. (It is an ongoing project to get it to work) However, removing this flag is an essential first step, since it otherwise removes the `__declspec(dllexport)` annotation, and we are hence renders us unable to lookup symbols in the static libraries. (I don't understand why this was introduced in the first place.)
* (gcc) `-Xassembler -mrelax-relocations=no`: This was apparently added for compatibility with "older" linkers. Unfortunately, no version was given, and the original author of the code does not remember. I can build with no ill effects without this flag, so I assume that in the years that has passed, our toolchain version increments has made this unnecessary.
There is a small risk of breakage for some old/odd gcc toolchain out there. But I can see of no other realistic way of solving this than to remove the flag, and if it breaks somewhere, we can re-introduce the flag, but with a valid GCC version number attached to it.
-------------
Commit messages:
- 8345683: Remove special flags for files compiled for static libraries
Changes: https://git.openjdk.org/jdk/pull/22606/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=22606&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8345683
Stats: 20 lines in 3 files changed: 0 ins; 19 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/22606.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/22606/head:pull/22606
PR: https://git.openjdk.org/jdk/pull/22606
More information about the build-dev
mailing list