Skip to content

Commit 9581069

Browse files
authored
[lld][test] Precommit test for ld -r links with FatLTO PIC objects (#92817)
Currently, with PIC relocatable links, FatLTO sections are treated as orphan sections and incorrectly concatenated together. This test verifies the current behavior, but should be fixed to either merge those sections into a single llvm module, similar to what `llvm-link` would produce, or to drop them altogether.
1 parent 4be3083 commit 9581069

File tree

1 file changed

+52
-26
lines changed

1 file changed

+52
-26
lines changed

lld/test/ELF/fatlto/fatlto.test

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,79 @@
11
;; Basic FatLTO tests.
22
; REQUIRES: x86
33

4-
; RUN: rm -rf %t && split-file %s %t
4+
; RUN: rm -rf %t && split-file %s %t && cd %t
55

66
;; Ensure that input files contain .llvm.lto section.
7-
; RUN: llc %t/a-LTO.ll --filetype=obj -o %t/a-fatLTO.o
8-
; RUN: opt < %t/a-LTO.ll --module-summary -o %t/a-fatLTO.bc
9-
; RUN: llvm-objcopy --add-section=.llvm.lto=%t/a-fatLTO.bc --set-section-flags=.llvm.lto=exclude %t/a-fatLTO.o
7+
; RUN: llc a-LTO.ll --filetype=obj -o a-fatLTO.o --relocation-model=pic
8+
; RUN: opt < a-LTO.ll --module-summary -o a-fatLTO.bc
9+
; RUN: llvm-objcopy --add-section=.llvm.lto=a-fatLTO.bc --set-section-flags=.llvm.lto=exclude --set-section-type=.llvm.lto=0x6fff4c0c a-fatLTO.o
1010

11-
; RUN: llc %t/main-LTO.ll --filetype=obj -o %t/main-fatLTO.o
12-
; RUN: opt < %t/main-LTO.ll --module-summary -o %t/main-fatLTO.bc
13-
; RUN: llvm-objcopy --add-section=.llvm.lto=%t/main-fatLTO.bc --set-section-flags=.llvm.lto=exclude %t/main-fatLTO.o
11+
12+
; RUN: llc main-LTO.ll --filetype=obj -o main-fatLTO.o --relocation-model=pic
13+
; RUN: opt < main-LTO.ll --module-summary -o main-fatLTO.bc
14+
; RUN: llvm-objcopy --add-section=.llvm.lto=main-fatLTO.bc --set-section-flags=.llvm.lto=exclude --set-section-type=.llvm.lto=0x6fff4c0c main-fatLTO.o
15+
16+
; RUN: llvm-readelf -S a-fatLTO.o | FileCheck --check-prefix=HAS_LLVM_LTO %s
17+
; RUN: llvm-readelf -S main-fatLTO.o | FileCheck --check-prefix=HAS_LLVM_LTO %s
18+
19+
;; Make sure that the section flags are set correctly
20+
; HA_LLVM_LTO: Name: .llvm.lto
21+
; HA_LLVM_LTO-NEXT: Type: SHT_LLVM_LTO
22+
; HA_LLVM_LTO-NEXT: Flags
23+
; HA_LLVM_LTO-NEXT: SHF_EXCLUDE
24+
25+
; HAS_LLVM_LTO: Name Type Address Off Size ES Flg Lk Inf Al
26+
; HAS_LLVM_LTO: .llvm.lto LLVM_LTO {{.*}} 00 WE 0 0 1
1427

1528
;; Final executable should not have .llvm.lto section no matter what the target is.
16-
; RUN: ld.lld -o %t/foo-fatLTO %t/a-fatLTO.o %t/main-fatLTO.o --fat-lto-objects
17-
; RUN: llvm-readobj -S %t/foo-fatLTO | FileCheck --check-prefix=CHECK-LTO-TARGET %s
29+
; RUN: ld.lld -o foo-fatLTO a-fatLTO.o main-fatLTO.o --fat-lto-objects
30+
; RUN: llvm-readelf -S foo-fatLTO | FileCheck --check-prefix=CHECK-LTO-TARGET %s
1831

1932
;; Check that fat objects work w/ --start-lib.
20-
; RUN: ld.lld -o %t/foo-fatLTO.start_lib --start-lib %t/a-fatLTO.o %t/main-fatLTO.o --fat-lto-objects
21-
; RUN: llvm-readobj -S %t/foo-fatLTO.start_lib | FileCheck --check-prefix=CHECK-LTO-TARGET %s
33+
; RUN: ld.lld -o foo-fatLTO.start_lib --start-lib a-fatLTO.o main-fatLTO.o --fat-lto-objects
34+
; RUN: llvm-readelf -S foo-fatLTO.start_lib | FileCheck --check-prefix=CHECK-LTO-TARGET %s
2235

2336
;; Check if .llvm.lto section gets aggregated in LTO target.
24-
; CHECK-LTO-TARGET-NOT: Name: .llvm.lto
37+
; CHECK-LTO-TARGET: Name Type Address Off Size ES Flg Lk Inf Al
38+
; CHECK-LTO-TARGET-NOT: .llvm.lto
2539

2640
;; Final executable should not have .llvm.lto section no matter what the target is.
27-
; RUN: ld.lld -o %t/foo-fatNoLTO %t/a-fatLTO.o %/t/main-fatLTO.o
28-
; RUN: llvm-readobj -S %t/foo-fatNoLTO | FileCheck --check-prefix=CHECK-NON-LTO-TARGET %s
41+
; RUN: ld.lld -o foo-fatNoLTO a-fatLTO.o %/t/main-fatLTO.o
42+
; RUN: llvm-readelf -S foo-fatNoLTO | FileCheck --check-prefix=CHECK-NON-LTO-TARGET %s
2943

3044
;; Check if .llvm.lto section gets aggregated in non-LTO target.
31-
; CHECK-NON-LTO-TARGET-NOT: Name: .llvm.lto
45+
; CHECK-NON-LTO-TARGET: Name Type Address Off Size ES Flg Lk Inf Al
46+
; CHECK-NON-LTO-TARGET-NOT: .llvm.lto
3247

3348
;; Check if the LTO target executable produced from FatLTO object file is
3449
;; identical to the one produced from LTO modules.
35-
; RUN: opt < %t/a-LTO.ll --module-summary -o %t/a-LTO.bc
36-
; RUN: opt < %t/main-LTO.ll --module-summary -o %t/main-LTO.bc
37-
; RUN: ld.lld -o %t/foo-LTO %t/a-LTO.bc %t/main-LTO.bc
38-
; RUN: cmp %t/foo-fatLTO %t/foo-LTO
50+
; RUN: opt < a-LTO.ll --module-summary -o a-LTO.bc
51+
; RUN: opt < main-LTO.ll --module-summary -o main-LTO.bc
52+
; RUN: ld.lld -o foo-LTO a-LTO.bc main-LTO.bc
53+
; RUN: cmp foo-fatLTO foo-LTO
3954

4055
;; Check if the no-LTO target executable produced from FatLTO object file is
4156
;; identical to the one produced from regular object files.
42-
; RUN: llc %t/a-LTO.ll --filetype=obj -o %t/a.o
43-
; RUN: llc %t/main-LTO.ll --filetype=obj -o %t/main.o
44-
; RUN: ld.lld -o %t/foo-noLTO %t/a.o %t/main.o
45-
; RUN: cmp %t/foo-fatNoLTO %t/foo-noLTO
57+
; RUN: llc a-LTO.ll --filetype=obj -o a.o
58+
; RUN: llc main-LTO.ll --filetype=obj -o main.o
59+
; RUN: ld.lld -o foo-noLTO a.o main.o
60+
; RUN: cmp foo-fatNoLTO foo-noLTO
4661

4762
;; Check archive support.
48-
; RUN: llvm-ar rcs %t/a.a %t/a-fatLTO.o
49-
; RUN: ld.lld -o %t/foo-fatLTO.archive %t/a.a %t/main-LTO.bc --fat-lto-objects
50-
; RUN: cmp %t/foo-fatLTO.archive %t/foo-LTO
63+
; RUN: llvm-ar rcs a.a a-fatLTO.o
64+
; RUN: ld.lld -o foo-fatLTO.archive a.a main-LTO.bc --fat-lto-objects
65+
; RUN: cmp foo-fatLTO.archive foo-LTO
66+
67+
;; Test FatLTO works with relocatable links using PIC objects
68+
;; Currently, with PIC relocatable links, FatLTO sections are treated as
69+
;; orphan sections and incorrectly concatenated together. This test verifies
70+
;; the current behavior, but should be fixed to either merge those sections
71+
;; correctly, or to drop them altogether.
72+
; RUN: llvm-ar rcs fatLTO-pic.a a-fatLTO.o main-fatLTO.o
73+
; RUN: llvm-readelf -S fatLTO-pic.a | FileCheck --check-prefix=HAS_LLVM_LTO %s
74+
75+
; RUN: ld.lld --whole-archive fatLTO-pic.a -r -o fatLTO-pic-reolcatable.o
76+
; RUN: llvm-readelf -S fatLTO-pic-reolcatable.o | FileCheck --check-prefix=HAS_LLVM_LTO %s
5177

5278
;--- a-LTO.ll
5379
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

0 commit comments

Comments
 (0)