Skip to content

Commit df3397b

Browse files
committed
[ELF] Improve canBeOmittedFromSymbolTable tests
A linkonce_odr definition can be omitted in LTO compilation if `canBeOmittedFromSymbolTable()` is true in all bitcode files. Test more linkage merge scenarios. The lo_and_wo symbol tests #111341.
1 parent c5ab70c commit df3397b

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed
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 internal 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 internal 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)