Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "[lld] Preliminary fat-lto-object support"
This patch adds support to lld for --fat-lto-objects. We add a new --fat-lto-objects option to LLD, and slightly change how it chooses input files in the driver when the option is set. Fat LTO objects contain both LTO compatible IR, as well as generated object code. This allows users to defer the choice of whether to use LTO or not to link-time. This is a feature available in GCC for some time, and makes the existing -ffat-lto-objects option functional in the same way as GCC's. If the --fat-lto-objects option is passed to LLD and the input files are fat object files, then the linker will chose the LTO compatible bitcode sections embedded within the fat object and link them together using LTO. Otherwise, standard object file linking is done using the assembly section in the object files. The previous version of this patch had a missing `REQUIRES: x86` line in `fatlto.invalid.s`. Additionally, it was reported that this patch caused a test failure in `export-dynamic-symbols.s`, however, 29112a9 disabled the `export-dynamic-symbols.s` test on Windows due to a quotation difference between platforms, unrelated to this patch. Original RFC: https://discourse.llvm.org/t/rfc-ffat-lto-objects-support/63977 Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D146778
- Loading branch information
Showing
7 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# REQUIRES: x86 | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t | ||
# RUN: not ld.lld %t -o /dev/null --fat-lto-objects 2>&1 | FileCheck %s | ||
|
||
# CHECK: error:{{.*}} Invalid bitcode signature | ||
|
||
.section .llvm.lto,"e",@progbits | ||
.Lllvm.embedded.object: | ||
.asciz "BC\300\3365\000" | ||
.size .Lllvm.embedded.object, 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
;; Basic FatLTO tests. | ||
; REQUIRES: x86 | ||
|
||
; RUN: rm -rf %t && split-file %s %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 %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 | ||
|
||
;; 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 | ||
|
||
;; 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 | ||
|
||
;; Check if .llvm.lto section gets aggregated in LTO target. | ||
; CHECK-LTO-TARGET-NOT: Name: .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 | ||
|
||
;; Check if .llvm.lto section gets aggregated in non-LTO target. | ||
; CHECK-NON-LTO-TARGET-NOT: Name: .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 | ||
|
||
;; 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 | ||
|
||
;; 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 | ||
|
||
;--- 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" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
; Function Attrs: noinline nounwind uwtable | ||
define dso_local i32 @_start() #0 { | ||
entry: | ||
ret i32 0 | ||
} | ||
|
||
attributes #0 = { noinline nounwind uwtable } | ||
|
||
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6} | ||
|
||
!0 = !{i32 1, !"wchar_size", i32 4} | ||
!1 = !{i32 7, !"PIC Level", i32 2} | ||
!2 = !{i32 7, !"PIE Level", i32 2} | ||
!3 = !{i32 7, !"uwtable", i32 2} | ||
!4 = !{i32 7, !"frame-pointer", i32 2} | ||
!5 = !{i32 1, !"ThinLTO", i32 0} | ||
!6 = !{i32 1, !"EnableSplitLTOUnit", i32 1} | ||
|
||
;--- main-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" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
; Function Attrs: noinline nounwind uwtable | ||
define dso_local i32 @main() #0 { | ||
entry: | ||
%retval = alloca i32, align 4 | ||
store i32 0, ptr %retval, align 4 | ||
%call = call i32 (...) @_start() | ||
ret i32 %call | ||
} | ||
|
||
declare i32 @_start(...) | ||
|
||
attributes #0 = { noinline nounwind uwtable } | ||
|
||
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6} | ||
|
||
!0 = !{i32 1, !"wchar_size", i32 4} | ||
!1 = !{i32 7, !"PIC Level", i32 2} | ||
!2 = !{i32 7, !"PIE Level", i32 2} | ||
!3 = !{i32 7, !"uwtable", i32 2} | ||
!4 = !{i32 7, !"frame-pointer", i32 2} | ||
!5 = !{i32 1, !"ThinLTO", i32 0} | ||
!6 = !{i32 1, !"EnableSplitLTOUnit", i32 1} |