Skip to content

Commit fbdd454

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

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
@@ -1756,13 +1756,22 @@ static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
17561756
sym = ctx.symtab->insert(objSym.getName());
17571757
}
17581758

1759-
int c = objSym.getComdatIndex();
1760-
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
1759+
if (objSym.isUndefined()) {
17611760
Undefined newSym(&f, StringRef(), binding, visibility, type);
17621761
sym->resolve(ctx, newSym);
17631762
sym->referenced = true;
17641763
return;
17651764
}
1765+
int c = objSym.getComdatIndex();
1766+
if (c != -1 && !keptComdats[c]) {
1767+
Defined newSym(ctx, &f, StringRef(), binding, visibility, type, 0, 0,
1768+
nullptr);
1769+
if (objSym.canBeOmittedFromSymbolTable())
1770+
newSym.exportDynamic = false;
1771+
sym->resolve(ctx, newSym);
1772+
sym->referenced = true;
1773+
return;
1774+
}
17661775

17671776
if (objSym.isCommon()) {
17681777
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)