https://sourceware.org/bugzilla/show_bug.cgi?id=35006
Bug ID: 35006
Summary: LoongArch: R_LARCH_64 against a shared-library
function in read-only data of a non-PIE executable is
kept as a dynamic relocation
Product: binutils
Version: 2.48 (HEAD)
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: yegorslists at googlemail dot com
Target Milestone: ---
When linking a non-PIE executable, a pointer to a function defined in a
shared library and stored in read-only data (a const table) is left as
a dynamic R_LARCH_64 relocation, i.e. a text relocation. In the output,
libf and libg stay undefined dynamic symbols with value 0, and no
canonical PLT entry is created for them. On x86_64, ld creates a
canonical PLT entry in the executable and resolves the pointer to it
at link time. The LoongArch result fails with -z text ("read-only
segment has dynamic relocations")
and is unusable with musl, whose dynamic loader has no DT_TEXTREL
support.
Reproducer:
$ cat lib.c
int libf(int x) { return x + 1; }
int libg(int x) { return x + 2; }
$ cat main.c
int libf(int); int libg(int);
struct f { const char *n; int (*p)(int); };
static const struct f t[] = { { "a", libf }, { "b", libg } };
int main(int c, char **v) { return t[c & 1].p(c); }
$ loongarch64-linux-musl-gcc -fPIC -shared -o libl.so lib.c
$ loongarch64-linux-musl-gcc -O2 -fno-pie -no-pie -Wl,-z,text -o m main.c -L.
-ll
ld: read-only segment has dynamic relocations
Without -z text, the link succeeds but the executable has DT_TEXTREL.
The same test links fine with -pie, and on x86_64 with
-fno-pie -no-pie -Wl,-z,text. On x86_64 the table entries resolve to
the PLT entries of the executable, and only R_X86_64_JUMP_SLOT
relocations remain for libf/libg.
Seen with binutils 2.45.1 and 2.46.1 (gcc 15.3/16.2, musl). The
relevant code in bfd/elfnn-loongarch.c looks the same in 2.47 and on
master.
Real-world impact: Buildroot autobuilder failures on loongarch64 musl,
e.g. libgpiod 1.6.5 gpioinfo:
https://autobuild.buildroot.org/results/e72378903f18777571816d54a470a551c13d0c13
and earlier curl (worked around upstream in curl).
--
You are receiving this mail because:
You are on the CC list for the bug.