[lld] [lld][ELF] Resolve Symbols with same comdat index as Defined Symbols (PR #115140)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 25 21:01:30 PST 2024
https://github.com/pranav-159 updated https://github.com/llvm/llvm-project/pull/115140
>From 63a1fc48a6c199c5cbfe8e60881d2dddeb85b929 Mon Sep 17 00:00:00 2001
From: pranav <Pranav.Gorantla at amd.com>
Date: Wed, 6 Nov 2024 14:45:43 +0530
Subject: [PATCH] [lld][ELF] Resolve Symbols with same comdat index as Defined
Symbols
---
lld/ELF/InputFiles.cpp | 13 +++++--
.../comdat-weakodr-linkonceodr-visibility.ll | 36 +++++++++++++++++++
2 files changed, 47 insertions(+), 2 deletions(-)
create mode 100644 lld/test/ELF/lto/comdat-weakodr-linkonceodr-visibility.ll
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 83a25e1b66cff0..4c80de28cee826 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1769,13 +1769,22 @@ static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
sym = ctx.symtab->insert(objSym.getName());
}
- int c = objSym.getComdatIndex();
- if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
+ if (objSym.isUndefined()) {
Undefined newSym(&f, StringRef(), binding, visibility, type);
sym->resolve(ctx, newSym);
sym->referenced = true;
return;
}
+ int c = objSym.getComdatIndex();
+ if (c != -1 && !keptComdats[c]) {
+ Defined newSym(ctx, &f, StringRef(), binding, visibility, type, 0, 0,
+ nullptr);
+ if (objSym.canBeOmittedFromSymbolTable())
+ newSym.exportDynamic = false;
+ sym->resolve(ctx, newSym);
+ sym->referenced = true;
+ return;
+ }
if (objSym.isCommon()) {
sym->resolve(ctx, CommonSymbol{ctx, &f, StringRef(), binding, visibility,
diff --git a/lld/test/ELF/lto/comdat-weakodr-linkonceodr-visibility.ll b/lld/test/ELF/lto/comdat-weakodr-linkonceodr-visibility.ll
new file mode 100644
index 00000000000000..776c7ff6f6bee7
--- /dev/null
+++ b/lld/test/ELF/lto/comdat-weakodr-linkonceodr-visibility.ll
@@ -0,0 +1,36 @@
+; RUN: rm -rf %t.dir
+; RUN: split-file %s %t.dir
+; RUN: cd %t.dir
+; RUN: echo %t.dir
+; RUN: llvm-as explicit.ll -o explicit.bc
+; RUN: llvm-as implicit.ll -o implicit.bc
+
+
+;; Case 1:
+; RUN: ld.lld explicit.bc implicit.bc -o case1.so -shared -save-temps
+; RUN: llvm-nm case1.so.0.2.internalize.bc | FileCheck %s
+
+;; Case 2:
+; RUN: ld.lld implicit.bc explicit.bc -o case2.so -shared -save-temps
+; RUN: llvm-nm case2.so.0.2.internalize.bc | FileCheck %s
+
+; CHECK: W foo
+
+;--- explicit.ll
+target triple = "x86_64-unknown-linux-gnu"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+$foo = comdat any
+define weak_odr void @foo() local_unnamed_addr comdat {
+ ret void
+}
+
+
+;--- implicit.ll
+target triple = "x86_64-unknown-linux-gnu"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+
+$foo = comdat any
+define linkonce_odr void @foo() local_unnamed_addr comdat {
+ ret void
+}
More information about the llvm-commits
mailing list