|
599 | 599 | <echo message="Setup flags to use during linking" /> |
600 | 600 |
|
601 | 601 | <!-- If we compile on linux we need to adjust the ldflags to correct link libstdc++ --> |
602 | | - <!-- NOTE: -static-libgcc was tried here to drop the DT_NEEDED on libgcc_s.so.1 |
603 | | - (not a musl-reserved name). It is a no-op in this build: the library is linked |
604 | | - with the C driver, so the _Unwind_* symbols pulled in by libstdc++.a stay |
605 | | - undefined and libgcc_s.so.1 remains genuinely required. Alpine satisfies it |
606 | | - with the `libgcc` package, which the JDK images already install. --> |
| 602 | + <!-- The libgcc archives must come *after* libstdc++.a: it is what pulls in the |
| 603 | + _Unwind_* symbols, and libgcc_eh.a is what defines them. Linking them |
| 604 | + statically is what keeps libgcc_s.so.1 out of DT_NEEDED - `gcc_s.` is not a |
| 605 | + musl-reserved stem, so on Alpine that entry is a real file lookup and fails |
| 606 | + outright on any image without the `libgcc` package (Amazon Corretto and many |
| 607 | + vendor JDK images ship none; eclipse-temurin does, which is why this went |
| 608 | + unnoticed). scripts/check_musl_compat.sh asserts both halves. |
| 609 | +
|
| 610 | + NOTE: spell this as `-l:` and never `-static-libgcc`. GNU libtool 2.4.6 links |
| 611 | + the shared library via archive_cmds, which expands only $libobjs $deplibs |
| 612 | + $compiler_flags; `-l*` is parsed into deplibs, but `-static-lib*` falls into |
| 613 | + func_mode_link's catch-all `-* | +*)` branch and reaches only the *program* |
| 614 | + link path, so gcc never sees it. That is why -static-libgcc looked like a |
| 615 | + no-op here. `-static-libstdc++` was dropped from this line for the same |
| 616 | + reason - it was silently discarded, and -l:libstdc++.a is what actually |
| 617 | + linked libstdc++ statically. See docs/musl-compatibility.md. --> |
607 | 618 | <if> |
608 | 619 | <equals arg1="${os.detected.name}" arg2="linux" /> |
609 | 620 | <then> |
610 | | - <property name="hawtjniLdflags" value="-L${boringsslHome} -lssl -lcrypto -static-libstdc++ -l:libstdc++.a" /> |
| 621 | + <property name="hawtjniLdflags" value="-L${boringsslHome} -lssl -lcrypto -l:libstdc++.a -l:libgcc.a -l:libgcc_eh.a" /> |
611 | 622 | </then> |
612 | 623 | <else> |
613 | 624 | <property name="hawtjniLdflags" value="${ldflags}" /> |
|
1095 | 1106 | <configureArg>--libdir=${project.build.directory}/native-build/target/lib</configureArg> |
1096 | 1107 | <configureArg>CFLAGS=-O3 -Werror -fno-omit-frame-pointer -fvisibility=hidden -Wunused -Wno-unused-value</configureArg> |
1097 | 1108 | <configureArg>CPPFLAGS=-DHAVE_OPENSSL -I${boringsslSourceDir}/include</configureArg> |
1098 | | - <configureArg>LDFLAGS=-L${boringsslHome} -lssl -lcrypto -static-libstdc++ -l:libstdc++.a</configureArg> |
| 1109 | + <!-- Keep in sync with the boringssl-static-default profile: the two Linux |
| 1110 | + profiles duplicate the whole native build, so a change to one does not apply |
| 1111 | + to the other. The libgcc archives must follow libstdc++.a, and must be |
| 1112 | + spelled `-l:` rather than -static-libgcc because libtool drops the latter - |
| 1113 | + see the comment on hawtjniLdflags in that profile. On aarch64 this also pulls |
| 1114 | + libgcc's init_have_lse_atomics constructor into the library, whose |
| 1115 | + __getauxval reference is satisfied by musl_compat.c; check_musl_compat.sh |
| 1116 | + fails the build if that ever stops being true, because an unresolved symbol |
| 1117 | + in an ELF constructor SIGSEGVs the JVM inside dlopen rather than raising |
| 1118 | + UnsatisfiedLinkError. --> |
| 1119 | + <configureArg>LDFLAGS=-L${boringsslHome} -lssl -lcrypto -l:libstdc++.a -l:libgcc.a -l:libgcc_eh.a</configureArg> |
1099 | 1120 | <configureArg>--host=aarch64-linux-gnu</configureArg> |
1100 | 1121 | <configureArg>CC=aarch64-none-linux-gnu-gcc</configureArg> |
1101 | 1122 | </configureArgs> |
|
0 commit comments