[lld] [lld][ELF] Add `--why-extract` for bitcode libcalls (PR #78781)
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 19 12:51:09 PST 2024
https://github.com/sbc100 created https://github.com/llvm/llvm-project/pull/78781
The Wasm linker already records these and its seems useful to do so.
Also mirror the simplications of this function from # in the Wasm linker #78659.
>From 5fccda03779127d616f939e90a94d404d51e70b9 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Fri, 19 Jan 2024 20:45:16 +0000
Subject: [PATCH] [lld][ELF] Add `--why-extract` for bitcode libcalls
The Wasm linker already records these and its seems useful to do
so.
Also mirror the simplications of this function from # in the Wasm
linker #78659.
---
lld/ELF/Driver.cpp | 5 ++++-
lld/wasm/Driver.cpp | 14 ++++----------
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 07f4263c90e62b..6e9b6ba6a2476b 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -2081,8 +2081,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/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 4a4f9a96227946..862d095dc10518 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -716,16 +716,10 @@ static Symbol *handleUndefined(StringRef name, const char *option) {
static void handleLibcall(StringRef name) {
Symbol *sym = symtab->find(name);
- if (!sym)
- return;
-
- if (auto *lazySym = dyn_cast<LazySymbol>(sym)) {
- MemoryBufferRef mb = lazySym->getMemberBuffer();
- if (isBitcode(mb)) {
- if (!config->whyExtract.empty())
- ctx.whyExtractRecords.emplace_back("<libcall>", sym->getFile(), *sym);
- lazySym->extract();
- }
+ if (sym && sym->isLazy() && isa<BitcodeFile>(sym->file)) {
+ if (!config->whyExtract.empty())
+ ctx.whyExtractRecords.emplace_back("<libcall>", sym->getFile(), *sym);
+ lazySym->extract();
}
}
More information about the llvm-commits
mailing list