[lld] 3e046ee - [lld][ELF] Add `--why-extract` for bitcode libcalls (#78781)

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 25 21:50:03 PDT 2024


Author: Sam Clegg
Date: 2024-03-25T21:50:00-07:00
New Revision: 3e046ee0c944b5a55f30b3ce0153791d91dbb134

URL: https://github.com/llvm/llvm-project/commit/3e046ee0c944b5a55f30b3ce0153791d91dbb134
DIFF: https://github.com/llvm/llvm-project/commit/3e046ee0c944b5a55f30b3ce0153791d91dbb134.diff

LOG: [lld][ELF] Add `--why-extract` for bitcode libcalls (#78781)

The Wasm linker already records these and its seems useful to do so.

Added: 
    

Modified: 
    lld/ELF/Driver.cpp
    lld/test/ELF/lto/libcall-archive.ll

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 048ef0a6061887..f14a2376601b08 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -2114,8 +2114,11 @@ static void handleUndefinedGlob(StringRef arg) {
 
 static void handleLibcall(StringRef name) {
   Symbol *sym = symtab.find(name);
-  if (sym && sym->isLazy() && isa<BitcodeFile>(sym->file))
+  if (sym && sym->isLazy() && isa<BitcodeFile>(sym->file)) {
+    if (!config->whyExtract.empty())
+      ctx.whyExtractRecords.emplace_back("<libcall>", sym->file, *sym);
     sym->extract();
+  }
 }
 
 static void writeArchiveStats() {

diff  --git a/lld/test/ELF/lto/libcall-archive.ll b/lld/test/ELF/lto/libcall-archive.ll
index bd91d0391dc274..84ddc1f5558724 100644
--- a/lld/test/ELF/lto/libcall-archive.ll
+++ b/lld/test/ELF/lto/libcall-archive.ll
@@ -4,11 +4,15 @@
 ; RUN: llvm-as -o %t2.o %S/Inputs/libcall-archive.ll
 ; RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux -o %t3.o %S/Inputs/libcall-archive.s
 ; RUN: llvm-ar rcs %t.a %t2.o %t3.o
-; RUN: ld.lld -o %t %t.o %t.a
+; RUN: ld.lld --why-extract=why.txt -o %t %t.o %t.a
+; RUN: FileCheck %s --input-file=why.txt --check-prefix=CHECK-WHY
 ; RUN: llvm-nm %t | FileCheck %s
 ; RUN: ld.lld -o %t2 %t.o --start-lib %t2.o %t3.o --end-lib
 ; RUN: llvm-nm %t2 | FileCheck %s
 
+; CHECK-WHY: reference extracted symbol
+; CHECK-WHY-NEXT: <libcall> {{.*}}tmp.a({{.*}}tmp2.o) memcpy
+
 ; CHECK-NOT: T __sync_val_compare_and_swap_8
 ; CHECK: T _start
 ; CHECK: T memcpy


        


More information about the llvm-commits mailing list