llvm-capstone/lld
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
..
cmake/modules [cmake] Add support for multiple distributions 2021-05-12 11:13:18 -07:00
COFF lld-coff: Simplify a few lambda uses after 7975dd033c 2021-05-24 17:26:46 -07:00
Common [ELF] Simplify isValidCIdentifier. NFC 2021-03-11 09:38:15 -08:00
docs [docs] ld.lld.1: Mention -z nostart-stop-gc 2021-05-21 19:57:51 -07:00
ELF [lld:elf] Weaken the requirement for a computed binding to be STB_LOCAL 2021-05-24 23:32:21 -04:00
include/lld [lld] Add missing header guard (NFC) 2021-04-02 11:12:23 +08:00
lib [NFC] Fix "not used" warning 2021-04-26 22:09:23 -07:00
MachO [lld][MachO] Fix code formatting 2021-05-23 20:35:55 -07:00
MinGW [LLD] [MinGW] Pass the canExitEarly parameter through properly 2021-05-18 15:09:07 +03:00
test [lld:elf] Weaken the requirement for a computed binding to be STB_LOCAL 2021-05-24 23:32:21 -04:00
tools/lld Fix lld macho standalone build by including llvm/Config/llvm-config.h instead of llvm/Config/config.h 2021-05-19 11:15:07 -04:00
unittests Use INTERFACE_COMPILE_OPTIONS to disable -Wsuggest-override for any target that links to gtest 2020-07-27 08:37:01 -07:00
utils Python 2/3 compatibility 2019-03-20 07:42:13 +00:00
wasm [lld][WebAssembly] Fix for PIC output + TLS + non-shared-memory 2021-05-21 15:16:47 -07:00
.clang-format
.clang-tidy [lld] Add .clang-tidy to customize readability-identifier-naming.{Member,Parameter,Variable}Case => camelBack 2020-03-09 08:26:41 -07:00
.gitignore
CMakeLists.txt Fix lld macho standalone build by including llvm/Config/llvm-config.h instead of llvm/Config/config.h 2021-05-19 11:15:07 -04:00
CODE_OWNERS.TXT Add code owners of new MachO port 2020-09-02 19:32:12 -07:00
LICENSE.TXT
README.md [doc] Place sha256 in lld/README.md into backticks 2021-01-12 10:19:40 -08:00

LLVM Linker (lld)

This directory and its subdirectories contain source code for the LLVM Linker, a modular cross platform linker which is built as part of the LLVM compiler infrastructure project.

lld is open source software. You may freely distribute it under the terms of the license agreement found in LICENSE.txt.

Benchmarking

In order to make sure various developers can evaluate patches over the same tests, we create a collection of self contained programs.

It is hosted at https://s3-us-west-2.amazonaws.com/linker-tests/lld-speed-test.tar.xz

The current sha256 is 10eec685463d5a8bbf08d77f4ca96282161d396c65bd97dc99dbde644a31610f.