Skip to content

Commit 7109f52

Browse files
committed
[ELF,test] Don't rely on --export-dynamic --gc-sections behavior for non-pie static linking
This mode does not retain definitions in GNU ld. While we do, it's not consistent with the decision that there is no .dynsym . We will change this and simplify some internal representations.
1 parent 2d06887 commit 7109f52

10 files changed

+47
-22
lines changed

lld/test/ELF/gc-sections.s

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=NOGC %s
66
# RUN: ld.lld --gc-sections --print-gc-sections %t -o %t2 | FileCheck --check-prefix=GC1-DISCARD %s
77
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC1 %s
8-
# RUN: ld.lld --export-dynamic --gc-sections %t -o %t2
8+
# RUN: ld.lld -pie --export-dynamic --gc-sections %t -o %t2
9+
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC2 %s
10+
11+
## In non-pie static linking, --export-dynamic currently retains the global 'd' even if it is not exported.
12+
# RUN: ld.lld --export-dynamic --gc-sections --print-gc-sections %t -o %t1
913
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC2 %s
1014

1115
# RUN: llvm-mc -filetype=obj -triple=x86_64 --crel %s -o %t.o
12-
# RUN: ld.lld --gc-sections --print-gc-sections %t.o -o %t2 | FileCheck --check-prefix=GC1-DISCARD %s
16+
# RUN: ld.lld -pie --gc-sections --print-gc-sections %t.o -o %t2 | FileCheck --check-prefix=GC1-DISCARD %s
1317
# RUN: llvm-readobj --sections --symbols %t2 | FileCheck -check-prefix=GC1 %s
1418

1519
# NOGC: Name: .eh_frame

lld/test/ELF/lto/devirt_vcall_vis_export_dynamic.ll

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828

2929
;; Check that all WPD fails with --export-dynamic.
3030

31+
; RUN: echo '.globl foo; foo:' > %ta.s
32+
; RUN: llvm-mc -filetype=obj %ta.s -o %ta.o
33+
; RUN: ld.lld -shared -soname=ta %ta.o -o %ta.so
34+
3135
;; Index based WPD
3236
; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \
3337
; RUN: -mllvm -pass-remarks=. \
@@ -49,19 +53,19 @@
4953
;; Check that WPD fails for target _ZN1D1mEi with --export-dynamic-symbol=_ZTV1D.
5054

5155
;; Index based WPD
52-
; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \
56+
; RUN: ld.lld %t2.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \
5357
; RUN: -mllvm -pass-remarks=. \
5458
; RUN: --export-dynamic-symbol=_ZTV1D 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY
5559
; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR
5660

5761
;; Hybrid WPD
58-
; RUN: ld.lld %t.o -o %t3 -save-temps --lto-whole-program-visibility \
62+
; RUN: ld.lld %t.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \
5963
; RUN: -mllvm -pass-remarks=. \
6064
; RUN: --export-dynamic-symbol=_ZTV1D 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY
6165
; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR
6266

6367
;; Regular LTO WPD
64-
; RUN: ld.lld %t4.o -o %t3 -save-temps --lto-whole-program-visibility \
68+
; RUN: ld.lld %t4.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \
6569
; RUN: -mllvm -pass-remarks=. \
6670
; RUN: --export-dynamic-symbol=_ZTV1D 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY
6771
; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR
@@ -74,19 +78,19 @@
7478
; RUN: echo "{ _ZTV1D; };" > %t.list
7579

7680
;; Index based WPD
77-
; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \
81+
; RUN: ld.lld %t2.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \
7882
; RUN: -mllvm -pass-remarks=. \
7983
; RUN: --dynamic-list=%t.list 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY
8084
; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR
8185

8286
;; Hybrid WPD
83-
; RUN: ld.lld %t.o -o %t3 -save-temps --lto-whole-program-visibility \
87+
; RUN: ld.lld %t.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \
8488
; RUN: -mllvm -pass-remarks=. \
8589
; RUN: --dynamic-list=%t.list 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY
8690
; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR
8791

8892
;; Regular LTO WPD
89-
; RUN: ld.lld %t4.o -o %t3 -save-temps --lto-whole-program-visibility \
93+
; RUN: ld.lld %t4.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \
9094
; RUN: -mllvm -pass-remarks=. \
9195
; RUN: --dynamic-list=%t.list 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY
9296
; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
; RUN: llvm-as a.ll -o a.bc
44
; RUN: llvm-as %p/Inputs/internalize-exportdyn.ll -o b.bc
55
; 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
6+
; RUN: ld.lld a.bc b.bc lib.o -o out --export-dynamic -save-temps -pie
77
; RUN: llvm-dis < out.0.2.internalize.bc | FileCheck %s
88
; RUN: ld.lld a.bc b.bc lib.o -o out2 -shared -save-temps
99
; RUN: llvm-dis < out2.0.2.internalize.bc | FileCheck %s --check-prefix=DSO

lld/test/ELF/lto/relocation-model-pic.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
1616
target triple = "x86_64-unknown-linux-gnu"
1717

1818
@foo = external global i32
19-
define i32 @main() {
19+
define i32 @_start() {
2020
%t = load i32, ptr @foo
2121
ret i32 %t
2222
}

lld/test/ELF/lto/relocation-model-static.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
1313
target triple = "x86_64-unknown-linux-gnu"
1414

1515
@foo = external dso_local global i32
16-
define i32 @main() {
16+
define i32 @_start() {
1717
%t = load i32, ptr @foo
1818
ret i32 %t
1919
}

lld/test/ELF/partition-errors.s

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// REQUIRES: x86, mips
2+
/// Link against a DSO to ensure that sections are not discarded by --gc-sections.
3+
// RUN: llvm-mc %S/Inputs/shared.s -o %ts.o -filetype=obj --triple=x86_64
4+
// RUN: ld.lld -shared -soname=ts %ts.o -o %ts.so
25
// RUN: llvm-mc -triple=x86_64-unknown-linux -filetype=obj -o %t.o %s
36
// RUN: echo "SECTIONS {}" > %t.script
4-
// RUN: not ld.lld --export-dynamic %t.o %t.script 2>&1 | FileCheck %s
7+
// RUN: not ld.lld --export-dynamic %ts.so %t.o %t.script 2>&1 | FileCheck %s
58
// RUN: echo "PHDRS { text PT_LOAD; }" > %t2.script
6-
// RUN: not ld.lld --export-dynamic %t.o %t2.script 2>&1 | FileCheck %s
7-
// RUN: not ld.lld --export-dynamic %t.o --section-start .text=0 2>&1 | FileCheck %s
8-
// RUN: not ld.lld --export-dynamic %t.o -Ttext=0 2>&1 | FileCheck %s
9-
// RUN: not ld.lld --export-dynamic %t.o -Tdata=0 2>&1 | FileCheck %s
10-
// RUN: not ld.lld --export-dynamic %t.o -Tbss=0 2>&1 | FileCheck %s
9+
// RUN: not ld.lld --export-dynamic %ts.so %t.o %t2.script 2>&1 | FileCheck %s
10+
// RUN: not ld.lld --export-dynamic %ts.so %t.o --section-start .text=0 2>&1 | FileCheck %s
11+
// RUN: not ld.lld --export-dynamic %ts.so %t.o -Ttext=0 2>&1 | FileCheck %s
12+
// RUN: not ld.lld --export-dynamic %ts.so %t.o -Tdata=0 2>&1 | FileCheck %s
13+
// RUN: not ld.lld --export-dynamic %ts.so %t.o -Tbss=0 2>&1 | FileCheck %s
1114

1215
// RUN: llvm-mc -triple=mipsel-unknown-linux -filetype=obj -o %t2.o %s
1316
// RUN: not ld.lld --export-dynamic %t2.o 2>&1 | FileCheck %s

lld/test/ELF/partition-icf.s

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// REQUIRES: x86
2+
/// Link against a DSO to ensure that sections are not discarded by --gc-sections.
3+
// RUN: llvm-mc -filetype=obj -triple=x86_64 %S/Inputs/shared.s -o %ts.o
4+
// RUN: ld.lld -shared -soname=ts %ts.o -o %ts.so
25
// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=x86_64-unknown-linux
3-
// RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections --icf=all
6+
// RUN: ld.lld %t.o %ts.so -o %t --export-dynamic --gc-sections --icf=all
47
// RUN: llvm-readelf -S -s %t | FileCheck %s
58

69
// CHECK: part1

lld/test/ELF/partition-move-to-main-startstop.s

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// REQUIRES: x86
2+
/// Link against a DSO to ensure that sections are not discarded by --gc-sections.
3+
// RUN: llvm-mc -filetype=obj -triple=x86_64 %S/Inputs/shared.s -o %ts.o
4+
// RUN: ld.lld -shared -soname=ts %ts.o -o %ts.so
25
// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=x86_64-unknown-linux
3-
// RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections
6+
// RUN: ld.lld %t.o %ts.so -o %t --export-dynamic --gc-sections
47
// RUN: llvm-readelf -S %t | FileCheck --implicit-check-not=has_startstop %s
58

69
// We can't let the has_startstop section be split by partition because it is

lld/test/ELF/partition-thunk-reuse.s

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// REQUIRES: arm
2+
/// Link against a DSO to ensure that sections are not discarded by --gc-sections.
3+
// RUN: llvm-mc -filetype=obj -triple=armv7-unknown-linux %S/Inputs/shared.s -o %ts.o
4+
// RUN: ld.lld -shared -soname=ts %ts.o -o %ts.so
25
// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=armv7-unknown-linux -arm-add-build-attributes
3-
// RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections
6+
// RUN: ld.lld %t.o %ts.so -o %t --export-dynamic --gc-sections
47
// RUN: llvm-nm %t | FileCheck %s
58

69
// CHECK: __Thumbv7ABSLongThunk__start

lld/test/ELF/partitions.s

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// REQUIRES: aarch64, x86
2+
/// Link against a DSO to ensure that sections are not discarded by --gc-sections.
3+
// RUN: llvm-mc %S/Inputs/shared.s -o %ts.o -filetype=obj --triple=x86_64
4+
// RUN: ld.lld -shared -soname=ts %ts.o -o %ts.so
25
// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=x86_64-unknown-linux
3-
// RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections -z max-page-size=65536
6+
// RUN: ld.lld %t.o %ts.so -o %t --export-dynamic --gc-sections -z max-page-size=65536
47
// RUN: llvm-readelf -S -s %t | FileCheck %s
58

9+
// RUN: llvm-mc %S/Inputs/shared.s -o %ts.o -filetype=obj --triple=aarch64
10+
// RUN: ld.lld -shared -soname=ts %ts.o -o %ts.so
611
// RUN: llvm-mc %s -o %t.o -filetype=obj --triple=aarch64 --crel
7-
// RUN: ld.lld %t.o -o %t --export-dynamic --gc-sections
12+
// RUN: ld.lld %t.o %ts.so -o %t --export-dynamic --gc-sections
813
// RUN: llvm-readelf -S -s %t | FileCheck %s
914

1015
// This is basically lld/docs/partitions.dot in object file form.

0 commit comments

Comments
 (0)