This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix undefined symbol handling in DSO.
Needs RevisionPublic

Authored by ruiu on Apr 6 2014, 9:58 PM.

Details

Summary

Currently LLD ignores undefined symbols found in DSOs when linking against
DSO files, if -shared flag is given. Internally, it's achieved by enabling
"useShlibUndefines" flag, which makes the file reader to ignore all undefined
symbols in DSO, so that Resolver don't see any undefined symbols when
handling DSO files.

The above behavior is not compatible with GNU LD.

GNU LD does not also warn on undefined symbols found in DSOs if -shared flag
is given. However, it actually tries to resolve such undefined symbols. As a
result, if an undefined symbol can be resolved by other objects/DSOs appears
later in the same command line, linking output will be different from LLD's
result.

This patch fixes the compatibilty issue. GNU LD seems to just not print
warning messages on undefined symbols if -shared is given. This patch
implements the same behavior.

Diff Detail

Event Timeline

atanasyan added inline comments.Apr 7 2014, 2:55 AM
lib/Driver/GnuLdDriver.cpp
178

It's a bit hard to understand that there is no functional changes here and the only code modification is a variable renaming. Maybe move such changes to the separate commit?

test/elf/dynamic-undef.test
23

IMHO we still need to check that --no-allow-shlib-undefined disallows undefined symbols in a shared library and lld returns an error in this case.

shankarke requested changes to this revision.Apr 7 2014, 5:31 AM

I am having some problem with my browser, with inline comments. and I also think this be converted to 2 patches.

a) to remove the option (use-shlib-undefines)
b) fix --[no]allow-shlib-undefined.

I am not sure the reason we added the option use-shlib-undefines, Bigcheese ?

Rui, can you wait on Bigcheese's review before removing the option use-shlib-undefines ?