[llvm-bugs] [Bug 28335] New: Correctly handle weak references to DSO symbols which do not appear in DT_NEEDED because of --as-needed
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jun 27 14:23:36 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=28335
Bug ID: 28335
Summary: Correctly handle weak references to DSO symbols which
do not appear in DT_NEEDED because of --as-needed
Product: lld
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: ELF
Assignee: unassignedbugs at nondot.org
Reporter: peter at pcc.me.uk
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Consider:
declare extern_weak i32 @__pthread_key_create(i32*, void (i8*)*)
(a symbol defined in libpthread)
then later:
br i1 icmp ne (i8* bitcast (i32 (i32*, void (i8*)*)* @__pthread_key_create to
i8*), i8* null), label %if.then.i.i.i, label %if.else.i.i.i
In a non-PIC object, the reference to __pthread_key_create does not go via the
GOT. As a result the static linker needs to create a "pseudo PLT" entry for
__pthread_key_create. This entry is used by the dynamic loader as the canonical
address of __pthread_key_create.
The documented behavior of --as-needed is that if all references to a DSO are
weak, the DSO does not appear in DT_NEEDED. However, this currently does not
affect whether we emit the pseudo PLT entry. As a result, the symbol
__pthread_key_create will be resolved to non-zero regardless of whether
libpthread is dynamically linked, and code which tests the address of
__pthread_key_create to determine whether libpthread was dynamically linked
will get the wrong result.
I see three possible solutions:
1) Treat weak references to non-needed DSOs as non-preemptible. This allows the
static linker to resolve references to zero and will inhibit the creation of a
pseudo PLT entry.
2) Change how we handle --as-needed: any symbol reference no matter the binding
will cause a DT_NEEDED entry to be created. This would be a divergence from the
documented behavior of --as-needed.
3) Treat a copy relocation or a pseudo PLT entry for a symbol as a "use" of
that symbol. That would force the linker to emit a DT_NEEDED for its DSO.
Either 1 or 3 seem like good solutions to me. I'll try implementing 3 first of
all.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160627/39d8f5ed/attachment-0001.html>
More information about the llvm-bugs
mailing list