[PATCH] [ELF] Export strong defined symbol if it coalesces away a weak symbol defined in a shared library
Simon Atanasyan
simon at atanasyan.com
Wed Sep 3 01:06:26 PDT 2014
Hi Bigcheese, shankarke, kledzik, ruiu,
Now LLD does not export a strong defined symbol if it coalesces away a weak symbol defined in a shared library. This bug affects all ELF architectures and leads to segfault:
% cat foo.c
extern int __attribute__((weak)) flag;
int foo() { return flag; }
% cat main.c
int flag = 1;
int foo();
int main() { return foo() == 1 ? 0 : -1; }
% clang -c -fPIC foo.c main.c
% lld -flavor gnu -target x86_64 -shared -o libfoo.so ... foo.o
% lld -flavor gnu -target x86_64 -o a.out ... main.o libfoo.so
% ./a.out
Segmentation fault
The problem is caused by the fact that we lose all information about coalesced symbols after the `Resolver::resolve()` method is finished.
The patch solves the problem by overriding the `LinkingContext::notifySymbolTableCoalesce()` method and adding new reference `kindDynExport` to all defined atoms which coalesce weak atoms defined in a shared library.
Notes:
- I use const_cast's where I need to add a new edge to the graph to make the patch smaller. It looks like we need to make the atom's graph mutable but I prefer to do that in a separate patch.
- The `ELFDefinedAtom` class did not maintain its own container for references and used a shared reference container populated when the ELF file read from disk. Now we can add a 'marker' reference to the defined atom in an arbitrary moment. That is why I add a separate container for 'marker' references to the `ELFDefinedAtom` class.
http://reviews.llvm.org/D5164
Files:
include/lld/Core/Reference.h
include/lld/ReaderWriter/ELFLinkingContext.h
lib/ReaderWriter/ELF/Atoms.h
lib/ReaderWriter/ELF/DefaultTargetHandler.h
lib/ReaderWriter/ELF/ELFFile.h
lib/ReaderWriter/ELF/ELFLinkingContext.cpp
lib/ReaderWriter/Reader.cpp
test/elf/X86_64/dynsym-weak.test
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5164.13192.patch
Type: text/x-patch
Size: 11461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140903/13ae065b/attachment.bin>
More information about the llvm-commits
mailing list