Skip to content

Commit b1038ce

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.5-bogner
1 parent 7fa5743 commit b1038ce

File tree

3 files changed

+76
-11
lines changed

3 files changed

+76
-11
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,6 @@ static uint8_t mapVisibility(GlobalValue::VisibilityTypes gvVisibility) {
17091709
}
17101710

17111711
static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
1712-
const std::vector<bool> &keptComdats,
17131712
const lto::InputFile::Symbol &objSym,
17141713
BitcodeFile &f) {
17151714
uint8_t binding = objSym.isWeak() ? STB_WEAK : STB_GLOBAL;
@@ -1726,8 +1725,7 @@ static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
17261725
sym = ctx.symtab->insert(objSym.getName());
17271726
}
17281727

1729-
int c = objSym.getComdatIndex();
1730-
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
1728+
if (objSym.isUndefined()) {
17311729
Undefined newSym(&f, StringRef(), binding, visibility, type);
17321730
sym->resolve(ctx, newSym);
17331731
sym->referenced = true;
@@ -1766,10 +1764,10 @@ void BitcodeFile::parse() {
17661764
// ObjFile<ELFT>::initializeSymbols.
17671765
for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
17681766
if (!irSym.isUndefined())
1769-
createBitcodeSymbol(ctx, symbols[i], keptComdats, irSym, *this);
1767+
createBitcodeSymbol(ctx, symbols[i], irSym, *this);
17701768
for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
17711769
if (irSym.isUndefined())
1772-
createBitcodeSymbol(ctx, symbols[i], keptComdats, irSym, *this);
1770+
createBitcodeSymbol(ctx, symbols[i], irSym, *this);
17731771

17741772
for (auto l : obj->getDependentLibraries())
17751773
addDependentLibrary(ctx, l, this);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
target triple = "x86_64-unknown-linux-gnu"
22
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
33

4+
$ext_and_ext = comdat any
5+
$lo_and_ext = comdat any
6+
$lo_and_wo = comdat any
7+
$wo_and_lo = comdat any
8+
9+
declare void @foo(i64)
10+
411
define weak_odr void @bah() {
512
ret void
613
}
14+
15+
define void @ext_and_ext() local_unnamed_addr comdat {
16+
call void @foo(i64 2)
17+
ret void
18+
}
19+
20+
define linkonce_odr void @lo_and_ext() local_unnamed_addr comdat {
21+
call void @foo(i64 2)
22+
ret void
23+
}
24+
25+
define weak_odr void @lo_and_wo() local_unnamed_addr comdat {
26+
ret void
27+
}
28+
29+
define linkonce_odr void @wo_and_lo() local_unnamed_addr comdat {
30+
ret void
31+
}

lld/test/ELF/lto/internalize-exportdyn.ll

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
; REQUIRES: x86
2-
; RUN: llvm-as %s -o %t.o
3-
; RUN: llvm-as %p/Inputs/internalize-exportdyn.ll -o %t2.o
4-
; RUN: ld.lld %t.o %t2.o -o %t2 --export-dynamic -save-temps
5-
; RUN: llvm-dis < %t2.0.2.internalize.bc | FileCheck %s
6-
; RUN: ld.lld %t.o %t2.o -o %t3 -shared -save-temps
7-
; RUN: llvm-dis < %t3.0.2.internalize.bc | FileCheck %s --check-prefix=DSO
2+
; RUN: rm -rf %t && split-file %s %t && cd %t
3+
; RUN: llvm-as a.ll -o a.bc
4+
; RUN: llvm-as %p/Inputs/internalize-exportdyn.ll -o b.bc
5+
; RUN: llvm-mc -filetype=obj -triple=x86_64 lib.s -o lib.o
6+
; RUN: ld.lld a.bc b.bc lib.o -o out --export-dynamic -save-temps
7+
; RUN: llvm-dis < out.0.2.internalize.bc | FileCheck %s
8+
; RUN: ld.lld a.bc b.bc lib.o -o out2 -shared -save-temps
9+
; RUN: llvm-dis < out2.0.2.internalize.bc | FileCheck %s --check-prefix=DSO
810

11+
;--- a.ll
912
target triple = "x86_64-unknown-linux-gnu"
1013
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
1114

15+
$ext_and_ext = comdat any
16+
$lo_and_ext = comdat any
17+
$lo_and_wo = comdat any
18+
$wo_and_lo = comdat any
19+
1220
@c = linkonce_odr constant i32 1
1321
@g = linkonce_odr global i32 1
1422
@u_c = linkonce_odr unnamed_addr constant i32 1
1523
@u_g = linkonce_odr unnamed_addr global i32 1
1624
@lu_c = linkonce_odr local_unnamed_addr constant i32 1
1725
@lu_g = linkonce_odr local_unnamed_addr global i32 1
1826

27+
declare void @lib(i64)
28+
1929
define void @_start() {
2030
ret void
2131
}
@@ -46,6 +56,24 @@ define linkonce_odr void @baz() {
4656

4757
@use_baz = global ptr @baz
4858

59+
define void @ext_and_ext() local_unnamed_addr comdat {
60+
call void @foo(i64 1)
61+
ret void
62+
}
63+
64+
define linkonce_odr void @lo_and_ext() local_unnamed_addr comdat {
65+
call void @foo(i64 1)
66+
ret void
67+
}
68+
69+
define linkonce_odr void @lo_and_wo() local_unnamed_addr comdat {
70+
ret void
71+
}
72+
73+
define weak_odr void @wo_and_lo() local_unnamed_addr comdat {
74+
ret void
75+
}
76+
4977
; Check what gets internalized.
5078
; CHECK: @c = weak_odr dso_local constant i32 1
5179
; CHECK: @g = weak_odr dso_local global i32 1
@@ -60,6 +88,12 @@ define linkonce_odr void @baz() {
6088
; CHECK: define internal void @zed2()
6189
; CHECK: define weak_odr dso_local void @bah()
6290
; CHECK: define weak_odr dso_local void @baz()
91+
; CHECK: define dso_local void @ext_and_ext() comdat
92+
; CHECK-NEXT: call void @foo(i64 1)
93+
; CHECK: define internal void @lo_and_ext() comdat
94+
; CHECK-NEXT: call void @foo(i64 1)
95+
; CHECK: define weak_odr dso_local void @lo_and_wo() comdat
96+
; CHECK: define weak_odr dso_local void @wo_and_lo() comdat
6397

6498
; DSO: @c = weak_odr constant i32 1
6599
; DSO: @g = weak_odr global i32 1
@@ -74,3 +108,11 @@ define linkonce_odr void @baz() {
74108
; DSO: define internal void @zed2()
75109
; DSO: define weak_odr void @bah()
76110
; DSO: define weak_odr void @baz()
111+
; DSO: define void @ext_and_ext() comdat
112+
; DSO: define internal void @lo_and_ext() comdat
113+
; DSO: define weak_odr void @lo_and_wo() comdat
114+
; DSO: define weak_odr void @wo_and_lo() comdat
115+
116+
;--- lib.s
117+
.globl lib
118+
lib:

0 commit comments

Comments
 (0)