aboutsummaryrefslogtreecommitdiff
path: root/lld/test
diff options
context:
space:
mode:
authorPaul Kirth <paulkirth@google.com>2024-05-31 11:52:57 -0700
committerGitHub <noreply@github.com>2024-05-31 11:52:57 -0700
commit95810690287283b3180a4a4f2452b4e4d51e217b (patch)
tree58e256356a187f6008d02ba505eb77bcdd2f498c /lld/test
parent4be3083bb39836466680a15f970ecc883d2e362a (diff)
downloadllvm-95810690287283b3180a4a4f2452b4e4d51e217b.zip
llvm-95810690287283b3180a4a4f2452b4e4d51e217b.tar.gz
llvm-95810690287283b3180a4a4f2452b4e4d51e217b.tar.bz2
[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.
Diffstat (limited to 'lld/test')
-rw-r--r--lld/test/ELF/fatlto/fatlto.test78
1 files changed, 52 insertions, 26 deletions
diff --git a/lld/test/ELF/fatlto/fatlto.test b/lld/test/ELF/fatlto/fatlto.test
index edf4ef2..ed13708 100644
--- a/lld/test/ELF/fatlto/fatlto.test
+++ b/lld/test/ELF/fatlto/fatlto.test
@@ -1,53 +1,79 @@
;; Basic FatLTO tests.
; REQUIRES: x86
-; RUN: rm -rf %t && split-file %s %t
+; RUN: rm -rf %t && split-file %s %t && cd %t
;; Ensure that input files contain .llvm.lto section.
-; RUN: llc %t/a-LTO.ll --filetype=obj -o %t/a-fatLTO.o
-; RUN: opt < %t/a-LTO.ll --module-summary -o %t/a-fatLTO.bc
-; RUN: llvm-objcopy --add-section=.llvm.lto=%t/a-fatLTO.bc --set-section-flags=.llvm.lto=exclude %t/a-fatLTO.o
+; RUN: llc a-LTO.ll --filetype=obj -o a-fatLTO.o --relocation-model=pic
+; RUN: opt < a-LTO.ll --module-summary -o a-fatLTO.bc
+; 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
-; RUN: llc %t/main-LTO.ll --filetype=obj -o %t/main-fatLTO.o
-; RUN: opt < %t/main-LTO.ll --module-summary -o %t/main-fatLTO.bc
-; RUN: llvm-objcopy --add-section=.llvm.lto=%t/main-fatLTO.bc --set-section-flags=.llvm.lto=exclude %t/main-fatLTO.o
+
+; RUN: llc main-LTO.ll --filetype=obj -o main-fatLTO.o --relocation-model=pic
+; RUN: opt < main-LTO.ll --module-summary -o main-fatLTO.bc
+; 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
+
+; RUN: llvm-readelf -S a-fatLTO.o | FileCheck --check-prefix=HAS_LLVM_LTO %s
+; RUN: llvm-readelf -S main-fatLTO.o | FileCheck --check-prefix=HAS_LLVM_LTO %s
+
+;; Make sure that the section flags are set correctly
+; HA_LLVM_LTO: Name: .llvm.lto
+; HA_LLVM_LTO-NEXT: Type: SHT_LLVM_LTO
+; HA_LLVM_LTO-NEXT: Flags
+; HA_LLVM_LTO-NEXT: SHF_EXCLUDE
+
+; HAS_LLVM_LTO: Name Type Address Off Size ES Flg Lk Inf Al
+; HAS_LLVM_LTO: .llvm.lto LLVM_LTO {{.*}} 00 WE 0 0 1
;; Final executable should not have .llvm.lto section no matter what the target is.
-; RUN: ld.lld -o %t/foo-fatLTO %t/a-fatLTO.o %t/main-fatLTO.o --fat-lto-objects
-; RUN: llvm-readobj -S %t/foo-fatLTO | FileCheck --check-prefix=CHECK-LTO-TARGET %s
+; RUN: ld.lld -o foo-fatLTO a-fatLTO.o main-fatLTO.o --fat-lto-objects
+; RUN: llvm-readelf -S foo-fatLTO | FileCheck --check-prefix=CHECK-LTO-TARGET %s
;; Check that fat objects work w/ --start-lib.
-; RUN: ld.lld -o %t/foo-fatLTO.start_lib --start-lib %t/a-fatLTO.o %t/main-fatLTO.o --fat-lto-objects
-; RUN: llvm-readobj -S %t/foo-fatLTO.start_lib | FileCheck --check-prefix=CHECK-LTO-TARGET %s
+; RUN: ld.lld -o foo-fatLTO.start_lib --start-lib a-fatLTO.o main-fatLTO.o --fat-lto-objects
+; RUN: llvm-readelf -S foo-fatLTO.start_lib | FileCheck --check-prefix=CHECK-LTO-TARGET %s
;; Check if .llvm.lto section gets aggregated in LTO target.
-; CHECK-LTO-TARGET-NOT: Name: .llvm.lto
+; CHECK-LTO-TARGET: Name Type Address Off Size ES Flg Lk Inf Al
+; CHECK-LTO-TARGET-NOT: .llvm.lto
;; Final executable should not have .llvm.lto section no matter what the target is.
-; RUN: ld.lld -o %t/foo-fatNoLTO %t/a-fatLTO.o %/t/main-fatLTO.o
-; RUN: llvm-readobj -S %t/foo-fatNoLTO | FileCheck --check-prefix=CHECK-NON-LTO-TARGET %s
+; RUN: ld.lld -o foo-fatNoLTO a-fatLTO.o %/t/main-fatLTO.o
+; RUN: llvm-readelf -S foo-fatNoLTO | FileCheck --check-prefix=CHECK-NON-LTO-TARGET %s
;; Check if .llvm.lto section gets aggregated in non-LTO target.
-; CHECK-NON-LTO-TARGET-NOT: Name: .llvm.lto
+; CHECK-NON-LTO-TARGET: Name Type Address Off Size ES Flg Lk Inf Al
+; CHECK-NON-LTO-TARGET-NOT: .llvm.lto
;; Check if the LTO target executable produced from FatLTO object file is
;; identical to the one produced from LTO modules.
-; RUN: opt < %t/a-LTO.ll --module-summary -o %t/a-LTO.bc
-; RUN: opt < %t/main-LTO.ll --module-summary -o %t/main-LTO.bc
-; RUN: ld.lld -o %t/foo-LTO %t/a-LTO.bc %t/main-LTO.bc
-; RUN: cmp %t/foo-fatLTO %t/foo-LTO
+; RUN: opt < a-LTO.ll --module-summary -o a-LTO.bc
+; RUN: opt < main-LTO.ll --module-summary -o main-LTO.bc
+; RUN: ld.lld -o foo-LTO a-LTO.bc main-LTO.bc
+; RUN: cmp foo-fatLTO foo-LTO
;; Check if the no-LTO target executable produced from FatLTO object file is
;; identical to the one produced from regular object files.
-; RUN: llc %t/a-LTO.ll --filetype=obj -o %t/a.o
-; RUN: llc %t/main-LTO.ll --filetype=obj -o %t/main.o
-; RUN: ld.lld -o %t/foo-noLTO %t/a.o %t/main.o
-; RUN: cmp %t/foo-fatNoLTO %t/foo-noLTO
+; RUN: llc a-LTO.ll --filetype=obj -o a.o
+; RUN: llc main-LTO.ll --filetype=obj -o main.o
+; RUN: ld.lld -o foo-noLTO a.o main.o
+; RUN: cmp foo-fatNoLTO foo-noLTO
;; Check archive support.
-; RUN: llvm-ar rcs %t/a.a %t/a-fatLTO.o
-; RUN: ld.lld -o %t/foo-fatLTO.archive %t/a.a %t/main-LTO.bc --fat-lto-objects
-; RUN: cmp %t/foo-fatLTO.archive %t/foo-LTO
+; RUN: llvm-ar rcs a.a a-fatLTO.o
+; RUN: ld.lld -o foo-fatLTO.archive a.a main-LTO.bc --fat-lto-objects
+; RUN: cmp foo-fatLTO.archive foo-LTO
+
+;; Test FatLTO works with relocatable links using PIC objects
+;; 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
+;; correctly, or to drop them altogether.
+; RUN: llvm-ar rcs fatLTO-pic.a a-fatLTO.o main-fatLTO.o
+; RUN: llvm-readelf -S fatLTO-pic.a | FileCheck --check-prefix=HAS_LLVM_LTO %s
+
+; RUN: ld.lld --whole-archive fatLTO-pic.a -r -o fatLTO-pic-reolcatable.o
+; RUN: llvm-readelf -S fatLTO-pic-reolcatable.o | FileCheck --check-prefix=HAS_LLVM_LTO %s
;--- a-LTO.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"