Skip to content

[lld][test] Precommit test for ld -r links with FatLTO PIC objects #92817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 52 additions & 26 deletions lld/test/ELF/fatlto/fatlto.test
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading