Skip to content

Commit 1cde8af

Browse files
pranavpranav
authored andcommitted
[lld][ELF] Resolve Symbols with same comdat index as Defined Symbols
1 parent bbd99d9 commit 1cde8af

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,13 +1726,22 @@ static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
17261726
sym = ctx.symtab->insert(objSym.getName());
17271727
}
17281728

1729-
int c = objSym.getComdatIndex();
1730-
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
1729+
if (objSym.isUndefined()) {
17311730
Undefined newSym(&f, StringRef(), binding, visibility, type);
17321731
sym->resolve(ctx, newSym);
17331732
sym->referenced = true;
17341733
return;
17351734
}
1735+
int c = objSym.getComdatIndex();
1736+
if (c != -1 && !keptComdats[c]) {
1737+
Defined newSym(ctx, &f, StringRef(), binding, visibility, type, 0, 0,
1738+
nullptr);
1739+
if (objSym.canBeOmittedFromSymbolTable())
1740+
newSym.exportDynamic = false;
1741+
sym->resolve(ctx, newSym);
1742+
sym->referenced = true;
1743+
return;
1744+
}
17361745

17371746
if (objSym.isCommon()) {
17381747
sym->resolve(ctx, CommonSymbol{ctx, &f, StringRef(), binding, visibility,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; RUN: rm -rf %t.dir
2+
; RUN: split-file %s %t.dir
3+
; RUN: cd %t.dir
4+
; RUN: echo %t.dir
5+
; RUN: llvm-as explicit.ll -o explicit.bc
6+
; RUN: llvm-as implicit.ll -o implicit.bc
7+
8+
9+
;; Case 1:
10+
; RUN: ld.lld explicit.bc implicit.bc -o case1.so -shared -save-temps
11+
; RUN: llvm-nm case1.so.0.2.internalize.bc | FileCheck %s
12+
13+
;; Case 2:
14+
; RUN: ld.lld implicit.bc explicit.bc -o case2.so -shared -save-temps
15+
; RUN: llvm-nm case2.so.0.2.internalize.bc | FileCheck %s
16+
17+
; CHECK: W foo
18+
19+
;--- explicit.ll
20+
target triple = "x86_64-unknown-linux-gnu"
21+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
22+
23+
$foo = comdat any
24+
define weak_odr void @foo() local_unnamed_addr comdat {
25+
ret void
26+
}
27+
28+
29+
;--- implicit.ll
30+
target triple = "x86_64-unknown-linux-gnu"
31+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
32+
33+
$foo = comdat any
34+
define linkonce_odr void @foo() local_unnamed_addr comdat {
35+
ret void
36+
}

0 commit comments

Comments
 (0)