llvm-project/lld/ELF
Nathan Lanza 2f65166056 [lld:elf] Weaken the requirement for a computed binding to be STB_LOCAL
Given the following scenario:

```
// Cat.cpp
struct Animal { virtual void makeNoise() const = 0; };
struct Cat : Animal { void makeNoise() const override; };

extern "C" int puts(char const *);
void Cat::makeNoise() const { puts("Meow"); }
void doThingWithCat(Animal *a) { static_cast<Cat *>(a)->makeNoise(); }

// CatUser.cpp
struct Animal { virtual void makeNoise() const = 0; };
struct Cat : Animal { void makeNoise() const override; };

void doThingWithCat(Animal *a);

void useDoThingWithCat() {
  Cat *d = new Cat;
  doThingWithCat(d);
}

// cat.ver
{
  global: _Z17useDoThingWithCatv;
  local: *;
};

$ clang++ Cat.cpp CatUser.cpp -fpic -flto=thin -fwhole-program-vtables
-shared -O3 -fuse-ld=lld -Wl,--lto-whole-program-visibility
-Wl,--version-script,cat.ver
```

We cannot devirtualize `Cat::makeNoise`. The issue is complex:

Due to `-fsplit-lto-unit` and usage of type metadata, we place the Cat
vtable declaration into module 0 and the Cat vtable definition with type
metadata into module 1, causing duplicate entries (Undefined followed by
Defined) in the `lto::InputFile::symbols()` output.
In `BitcodeFile::parse`, after processing the `Undefined` then the
`Defined`, the final state is `Defined`.
In `BitcodeCompiler::add`, for the first symbol, `computeBinding`
returns `STB_LOCAL`, then we reset it to `Undefined` because it is
prevailing (`versionId` is `preserved`). For the second symbol, because
the state is now `Undefined`, `computeBinding` returns `STB_GLOBAL`,
causing `ExportDynamic` to be true and suppressing devirtualization.

In D77280, the `computeBinding` change used a stricter `isDefined()`
condition to make weak``Lazy` symbol work.
This patch relaxes the condition to weaker `!isLazy()` to keep it
working while making the devirtualization work as well.

Differential Revision: https://reviews.llvm.org/D98686
2021-05-24 23:32:21 -04:00
..
Arch [lld][X86] Restore gotEntrySize. 2021-05-17 00:13:00 +01:00
AArch64ErrataFix.cpp [ELF] Move the outSecOff addend from relocAlloc/relocNonAlloc/... to InputSectionBase::relocate 2020-08-11 08:06:38 -07:00
AArch64ErrataFix.h [LLD][ELF] Optimize linker script filename glob pattern matching NFC 2020-09-16 10:26:11 +01:00
ARMErrataFix.cpp [ELF] Move the outSecOff addend from relocAlloc/relocNonAlloc/... to InputSectionBase::relocate 2020-08-11 08:06:38 -07:00
ARMErrataFix.h [LLD][ELF] Optimize linker script filename glob pattern matching NFC 2020-09-16 10:26:11 +01:00
CMakeLists.txt [CMake] Make `intrinsics_gen` dependency unconditional. 2020-07-17 16:43:17 -07:00
CallGraphSort.cpp [COFF] Port CallGraphSort to COFF from ELF 2020-07-30 15:21:44 -07:00
CallGraphSort.h
Config.h [ELF] Add -Bno-symbolic 2021-05-14 09:40:32 -07:00
DWARF.cpp [lib/Object] - Generalize the RelocationResolver API. 2020-11-20 10:32:49 +03:00
DWARF.h [ELF] --gdb-index: skip SHF_GROUP .debug_info 2020-08-13 09:11:01 -07:00
Driver.cpp [ELF] Add -Bno-symbolic 2021-05-14 09:40:32 -07:00
Driver.h [LLD] Rename lld port driver entry function to a consistent name 2020-12-18 12:18:37 +05:30
DriverUtils.cpp [ELF] Rewriting the path of sample profile file for --reproduce response.txt 2021-02-09 00:00:16 -08:00
EhFrame.cpp ELF: Teach the linker about the 'B' augmentation string character. 2021-01-05 19:51:11 -08:00
EhFrame.h [ELF] --icf: don't fold text sections with LSDA 2020-08-05 09:16:28 -07:00
ICF.cpp [LLD][ELF] Improve ICF for relocations to ineligible sections via "aliases" 2020-10-15 12:43:14 +01:00
ICF.h
InputFiles.cpp [LLD] Improve reporting unresolved symbols in shared libraries 2021-05-11 12:48:29 +07:00
InputFiles.h [LLD] Improve reporting unresolved symbols in shared libraries 2021-05-11 12:48:29 +07:00
InputSection.cpp [ELF] Support .rela.eh_frame with unordered r_offset values 2021-04-29 08:51:09 -07:00
InputSection.h [ELF] Don't consider SHF_ALLOC ".debug*" sections debug sections 2020-11-12 09:59:43 -08:00
LTO.cpp [WPD][ELF] Allow whole program devirtualization for version script localized symbols 2021-03-09 22:33:47 -08:00
LTO.h [Coding style change] Rename variables so that they start with a lowercase letter 2019-07-10 05:00:37 +00:00
LinkerScript.cpp fix typo to cycle bots 2021-04-14 14:52:53 -04:00
LinkerScript.h [LLD][ELF] Optimize linker script filename glob pattern matching NFC 2020-09-16 10:26:11 +01:00
MapFile.cpp [lld][ELF] Add additional time trace categories 2020-11-10 10:28:46 +00:00
MapFile.h [ELF] Add --print-archive-stats= 2020-04-29 18:04:37 -07:00
MarkLive.cpp [ELF] Default to -z start-stop-gc with a glibc "__libc_" special case 2021-04-16 12:18:46 -07:00
MarkLive.h
Options.td [ELF] Add -Bno-symbolic 2021-05-14 09:40:32 -07:00
OutputSections.cpp [ELF] --emit-relocs: fix a crash if .rela.dyn is an empty output section 2020-12-16 08:59:38 -08:00
OutputSections.h [ELF][NFCI] small cleanup to OutputSections.h 2021-01-12 23:09:16 +00:00
README.md
Relocations.cpp [ELF] Don't suggest alternative spelling of an empty name 2021-05-03 09:04:55 -07:00
Relocations.h [ELF] Support .rela.eh_frame with unordered r_offset values 2021-04-29 08:51:09 -07:00
ScriptLexer.cpp [LLD][ELF] - Linkerscript: report location for the "unclosed comment in a linker script" error. 2020-07-24 11:38:26 +03:00
ScriptLexer.h [LLD][ELF] - Linkerscript: report location for the "unclosed comment in a linker script" error. 2020-07-24 11:38:26 +03:00
ScriptParser.cpp [ELF] Support . and $ in symbol names in expressions 2021-03-11 09:34:36 -08:00
ScriptParser.h [ELF] Improve --export-dynamic-symbol performance by checking whether wildcard is really used 2020-06-17 17:12:10 -07:00
SymbolTable.cpp [ELF] --wrap: don't clear sym->isUsedInRegularObj if real->isUsedInRegularObj; set wrap's initial binding to sym's 2021-04-17 00:29:51 -07:00
SymbolTable.h [ELF] Replace SymbolTable::forEachSymbol with iterator_range symbols() 2019-11-26 09:09:32 -08:00
Symbols.cpp [lld:elf] Weaken the requirement for a computed binding to be STB_LOCAL 2021-05-24 23:32:21 -04:00
Symbols.h [LTO] Prevent devirtualization for symbols dynamically exported 2021-01-27 15:54:13 -08:00
SyntheticSections.cpp [lld][X86] Restore gotEntrySize. 2021-05-17 00:13:00 +01:00
SyntheticSections.h [LLD][ELF] - Use LLVM_ELF_IMPORT_TYPES_ELFT instead of multiple types definitions. NFCI. 2020-12-29 10:50:07 +03:00
Target.cpp [ELF] Rename adjustRelaxExpr to adjustTlsExpr and delete the unused `data` parameter. NFC 2020-11-25 09:00:55 -08:00
Target.h [lld][X86] Restore gotEntrySize. 2021-05-17 00:13:00 +01:00
Thunks.cpp [PowerPC][LLD] Make sure that the correct Thunks are used. 2021-05-06 12:00:04 -05:00
Thunks.h [PowerPC][PC Rel] Implement option to omit Power10 instructions from stubs 2021-03-04 13:27:46 -05:00
Writer.cpp [LLD] Improve reporting unresolved symbols in shared libraries 2021-05-11 12:48:29 +07:00
Writer.h Revert "Revert r370635, it caused PR43241." 2019-09-06 15:57:24 +00:00

README.md

See docs/NewLLD.rst