Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lld][ELF] Add --why-extract for bitcode libcalls #78781

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jan 19, 2024

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

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 19, 2024

@llvm/pr-subscribers-lld
@llvm/pr-subscribers-lld-elf

@llvm/pr-subscribers-lld-wasm

Author: Sam Clegg (sbc100)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/78781.diff

2 Files Affected:

  • (modified) lld/ELF/Driver.cpp (+4-1)
  • (modified) lld/wasm/Driver.cpp (+4-10)
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 07f4263c90e62b3..6e9b6ba6a2476b1 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 4a4f9a96227946d..862d095dc105184 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();
   }
 }
 

@MaskRay
Copy link
Member

MaskRay commented Jan 19, 2024

Can you add test? You can add --why-extract= to a libcall-* test

@MaskRay
Copy link
Member

MaskRay commented Feb 6, 2024

ping for a test

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 25, 2024

Sorry, I dropping this completely.. picking it up now.

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 25, 2024

Test added

The Wasm linker already records these and its seems useful to do
so.
@sbc100 sbc100 merged commit 3e046ee into llvm:main Mar 26, 2024
3 of 4 checks passed
@sbc100 sbc100 deleted the handleLibcall branch March 26, 2024 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants