Skip to content

Commit ec0e4d6

Browse files
committed
linux: park -fno-semantic-interposition + -fno-plt (JNI alias clash)
Both flags are incompatible with default-visibility JNI export aliases emitted by NETTY_JNI_ALIAS in netty/netty-tcnative. Under -fno-semantic-interposition the compiler treats those aliases as PC-rel-addressable from inside the DSO, but the aarch64 linker (ld.lld) sees their declared default visibility and refuses the resulting relocation: ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 'Java_io_netty_channel_unix_Socket_recvFrom'; recompile with -fPIC Move both flags to labs.disabled.txt with the failure mode and the re-enable condition (move NETTY_JNI_ALIAS to STV_PROTECTED, or stop emitting default-visibility JNI aliases) inline.
1 parent c782f56 commit ec0e4d6

2 files changed

Lines changed: 32 additions & 16 deletions

File tree

labs.disabled.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@
6565
# and the userspace runtime contract is ready to require CET support.
6666
-fcf-protection=full
6767
#
68+
# Skip the dynamic-symbol interposition contract for own-DSO defs and
69+
# remove the lazy-binding PLT for external calls. Together they let
70+
# clang resolve intra-DSO calls/constants with PC-relative addressing
71+
# (-fno-semantic-interposition) and route external calls through a
72+
# read-only GOT (-fno-plt + -Wl,-z,now). Net effect on Linux: smaller
73+
# code, faster cold start, no writable PLT-stub gadget surface.
74+
#
75+
# Incompatible with our NETTY_JNI_ALIAS pattern: the macro emits the
76+
# `Java_<class>_<method>` entry symbols as `__attribute__((alias,
77+
# visibility("default")))`. Under -fno-semantic-interposition the
78+
# compiler treats them as protected-equivalent and addresses them with
79+
# `adrp+add` PC-relative, but ld.lld (correctly) sees their declared
80+
# default visibility and refuses the relocation:
81+
# ld.lld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used
82+
# against symbol 'Java_io_netty_channel_unix_Socket_recvFrom';
83+
# recompile with -fPIC
84+
# Re-enable only if NETTY_JNI_ALIAS moves to STV_PROTECTED (which keeps
85+
# dlsym discoverability while marking the alias non-interposable) or we
86+
# stop emitting default-visibility JNI aliases altogether.
87+
-fno-semantic-interposition
88+
-fno-plt
89+
#
6890
# Per-basic-block sections — prerequisite for a Propeller-style
6991
# symbol-ordering pass at the consumer's final link, where hot blocks
7092
# get reordered across function boundaries to shrink the icache

linux.txt

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,16 @@
2727
# darwin: cmake build aborts. Linux only.
2828
-fexperimental-relative-c++-abi-vtables
2929

30-
# Skip the dynamic-symbol interposition contract for our own definitions:
31-
# under ELF the linker assumes any global symbol in a shared library can
32-
# be replaced via LD_PRELOAD, which forces every intra-library call through
33-
# the GOT/PLT and disables a wide range of inlining + IPO. Disabling it
34-
# lets clang resolve calls and constants directly inside the same DSO.
35-
# Combined with -fno-plt below, the call-site overhead approaches a static
36-
# build's. Linux/ELF only — Mach-O has different visibility semantics and
37-
# clang ignores this flag there.
38-
-fno-semantic-interposition
39-
40-
# Skip the PLT for external calls and route them through GOT loads instead.
41-
# Pairs with -Wl,-z,now (full RELRO): the GOT is resolved at load time and
42-
# made read-only, so removing the lazy-binding PLT shrinks code size,
43-
# eliminates a layer of indirection on hot calls, and removes the writable
44-
# PLT-stub gadget surface from the binary. Linux/ELF only.
45-
-fno-plt
30+
# NOTE: -fno-semantic-interposition and -fno-plt are parked in
31+
# labs.disabled.txt — both are incompatible with default-visibility
32+
# `Java_*` aliases that JNI exports require. The compiler treats own-DSO
33+
# default-visibility symbols as PC-rel-addressable under
34+
# -fno-semantic-interposition, and the aarch64 linker (ld.lld) then
35+
# rejects the resulting `R_AARCH64_ADR_PREL_PG_HI21` relocation against
36+
# the alias with "cannot be used against symbol 'Java_…'; recompile with
37+
# -fPIC". Re-enable only if we move JNI exports to STV_PROTECTED (which
38+
# would need a coordinated change to NETTY_JNI_ALIAS) or stop emitting
39+
# default-visibility aliases altogether.
4640

4741
# NOTE: -U_FORTIFY_SOURCE, -D_FORTIFY_SOURCE=2, and
4842
# -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST are parked in

0 commit comments

Comments
 (0)