[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug ld/26551] New: A definition referenced by an unneeded (--as-needed)
From: |
i at maskray dot me |
Subject: |
[Bug ld/26551] New: A definition referenced by an unneeded (--as-needed) shared object should be exported |
Date: |
Sat, 29 Aug 2020 06:56:25 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=26551
Bug ID: 26551
Summary: A definition referenced by an unneeded (--as-needed)
shared object should be exported
Product: binutils
Version: unspecified
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: i at maskray dot me
Target Milestone: ---
echo '.global _start; _start: ret' | as -o a.o
echo 'call _start' | as -o b.o
ld.bfd -shared b.o -o b.so
ld.bfd a.o b.so -o bfd.needed
ld.bfd a.o --as-needed b.so -o bfd.unneeded
ld.gold a.o b.so -o gold.needed
ld.gold a.o --as-needed b.so -o gold.unneeded
ld.lld a.o b.so -o lld.needed
ld.lld a.o --as-needed b.so -o lld.unneeded
bfd.unneeded does not export _start. All other 5 executables export _start.
_start should be exported. In a larger application, b.so may be referenced
through a shared object chain. Linking the executable against b.so makes the
intention clear that the definitions in regular objects resolving shared object
references are needed.
----
Here is a larger example related to --allow-shlib-undefined, demonstrating why
the GNU ld behavior (a definition referenced by an unneeded (--as-needed)
shared object is not exported) is not good. This may be related to bug 18652.
echo '.globl _start, myexit; _start: jmp foo; myexit: movq $60, %rax; movq $42,
%rdi; syscall' | as -o a.o
echo '.globl foo; foo: jmp bar' | as -o b.o
echo '.globl bar; bar: jmp myexit' | as -o c.o
ld.bfd -shared c.o -o c.so
ld.bfd -shared b.o ./c.so -o b.so
ld.bfd --dynamic-linker /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 a.o
/usr/lib/x86_64-linux-gnu/libc.so --as-needed ./b.so ./c.so -y myexit
--allow-shlib-undefined -o bfd.bad
ld.bfd --dynamic-linker /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 a.o
/usr/lib/x86_64-linux-gnu/libc.so --as-needed ./b.so ./c.so -y myexit -o
bfd.good
c.so is an "unneeded" (in the sense of --as-needed) shared object. In the
--allow-shlib-undefined command line, myexit is somehow not exported.
bfd.good exits with code 42.
% ./bfd.bad
./bfd.bad: symbol lookup error: ./c.so: undefined symbol: myexit
--
You are receiving this mail because:
You are on the CC list for the bug.
- [Bug ld/26551] New: A definition referenced by an unneeded (--as-needed) shared object should be exported,
i at maskray dot me <=
- [Bug ld/26551] A definition referenced by an unneeded (--as-needed) shared object should be exported, hjl.tools at gmail dot com, 2020/08/29
- [Bug ld/26551] A definition referenced by an unneeded (--as-needed) shared object should be exported, hjl.tools at gmail dot com, 2020/08/29
- [Bug ld/26551] A definition referenced by an unneeded (--as-needed) shared object should be exported, hjl.tools at gmail dot com, 2020/08/29
- [Bug ld/26551] A definition referenced by an unneeded (--as-needed) shared object should be exported, i at maskray dot me, 2020/08/29
- [Bug ld/26551] A definition referenced by an unneeded (--as-needed) shared object should be exported, hjl.tools at gmail dot com, 2020/08/29