hanchenye-llvm-project/lld/test
Fangrui Song 51fe635f81 [ELF] Move IsNeeded logic from SymbolTable::addShared to MarkLive, and check IsUsedInRegularObj
Summary:
In glibc, libc.so is a linker script with an as-needed dependency on ld-linux-x86-64.so.2

    GROUP ( /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libc_nonshared.a  AS_NEEDED ( /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ) )

ld-linux-x86-64.so.2 (as-needed) defines some symbols which resolve undefined references in libc.so.6, it will therefore be added as a DT_NEEDED entry, which isn't necessary.

The test case as-needed-not-in-regular.s emulates the libc.so scenario, where ld.bfd and gold don't add DT_NEEDED for a.so

The relevant code in gold/resolve.cc:

  // If we have a non-WEAK reference from a regular object to a
  // dynamic object, mark the dynamic object as needed.
  if (to->is_from_dynobj() && to->in_reg() && !to->is_undef_binding_weak())
    to->object()->set_is_needed();

in_reg() appears to do something similar to IsUsedInRegularObj.

This patch makes lld do the similar thing, but moves the check from
addShared to a later stage MarkLive where all symbols are scanned.

Reviewers: ruiu, pcc, espindola

Reviewed By: ruiu

Subscribers: emaste, arichardson, llvm-commits

Differential Revision: https://reviews.llvm.org/D55902

llvm-svn: 349849
2018-12-20 22:46:01 +00:00
..
COFF [COFF] Set the CPU string for LTO like ELF does 2018-12-18 01:59:33 +00:00
Driver/Inputs
ELF [ELF] Move IsNeeded logic from SymbolTable::addShared to MarkLive, and check IsUsedInRegularObj 2018-12-20 22:46:01 +00:00
MinGW [MinGW] Pass libpath to the COFF linker 2018-10-10 09:00:03 +00:00
Unit
darwin
mach-o Make YAML quote forward slashes. 2018-10-12 16:31:20 +00:00
wasm Update for an llvm-dwarfdump change in output 2018-12-12 18:46:43 +00:00
CMakeLists.txt [CMake] Add an lld-test-depends target 2018-08-29 17:30:45 +00:00
lit.cfg.py [test] Capture stderr from 'tar --version' call as well 2018-12-14 22:38:01 +00:00
lit.site.cfg.py.in Import lit.llvm after rLLD341134 2018-08-31 00:23:09 +00:00