Skip to content

Commit adc2d31

Browse files
committed
[lld][ELF] Add --why-extract for bitcode libcalls
The Wasm linker already records these and its seems useful to do so.
1 parent 213eda1 commit adc2d31

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lld/ELF/Driver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2114,8 +2114,11 @@ static void handleUndefinedGlob(StringRef arg) {
21142114

21152115
static void handleLibcall(StringRef name) {
21162116
Symbol *sym = symtab.find(name);
2117-
if (sym && sym->isLazy() && isa<BitcodeFile>(sym->file))
2117+
if (sym && sym->isLazy() && isa<BitcodeFile>(sym->file)) {
2118+
if (!config->whyExtract.empty())
2119+
ctx.whyExtractRecords.emplace_back("<libcall>", sym->file, *sym);
21182120
sym->extract();
2121+
}
21192122
}
21202123

21212124
static void writeArchiveStats() {

lld/test/ELF/lto/libcall-archive.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
; RUN: llvm-as -o %t2.o %S/Inputs/libcall-archive.ll
55
; RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux -o %t3.o %S/Inputs/libcall-archive.s
66
; RUN: llvm-ar rcs %t.a %t2.o %t3.o
7-
; RUN: ld.lld -o %t %t.o %t.a
7+
; RUN: ld.lld --why-extract=why.txt -o %t %t.o %t.a
8+
; RUN: FileCheck %s --input-file=why.txt --check-prefix=CHECK-WHY
89
; RUN: llvm-nm %t | FileCheck %s
910
; RUN: ld.lld -o %t2 %t.o --start-lib %t2.o %t3.o --end-lib
1011
; RUN: llvm-nm %t2 | FileCheck %s
1112

13+
; CHECK-WHY: reference extracted symbol
14+
; CHECK-WHY-NEXT: <libcall> {{.*}}tmp.a({{.*}}tmp2.o) memcpy
15+
1216
; CHECK-NOT: T __sync_val_compare_and_swap_8
1317
; CHECK: T _start
1418
; CHECK: T memcpy

0 commit comments

Comments
 (0)