Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang] Preliminary fat-lto-object support
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 flag functional in the same way as GCC's. This patch adds support for that flag in the driver, as well as setting the necessary codegen options for the backend. Largely, this means we select the newly added pass pipeline for generating fat objects. Users are expected to pass -ffat-lto-objects to clang in addition to one of the -flto variants. Without the -flto flag, -ffat-lto-objects has no effect. // Compile and link. Use the object code from the fat object w/o LTO. clang -fno-lto -ffat-lto-objects -fuse-ld=lld foo.c // Compile and link. Select full LTO at link time. clang -flto -ffat-lto-objects -fuse-ld=lld foo.c // Compile and link. Select ThinLTO at link time. clang -flto=thin -ffat-lto-objects -fuse-ld=lld foo.c // Compile and link. Use ThinLTO with the UnifiedLTO pipeline. clang -flto=thin -ffat-lto-objects -funified-lto -fuse-ld=lld foo.c // Compile and link. Use full LTO with the UnifiedLTO pipeline. clang -flto -ffat-lto-objects -funified-lto -fuse-ld=lld foo.c // Link separately, using ThinLTO. clang -c -flto=thin -ffat-lto-objects foo.c clang -flto=thin -fuse-ld=lld foo.o -ffat-lto-objects # pass --lto=thin --fat-lto-objects to ld.lld // Link separately, using full LTO. clang -c -flto -ffat-lto-objects foo.c clang -flto -fuse-ld=lld foo.o # pass --lto=full --fat-lto-objects to ld.lld Original RFC: https://discourse.llvm.org/t/rfc-ffat-lto-objects-support/63977 Depends on D146776 Reviewed By: tejohnson, MaskRay Differential Revision: https://reviews.llvm.org/D146777
- Loading branch information
Showing
10 changed files
with
151 additions
and
5 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
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,57 @@ | ||
// REQUIRES: x86-registered-target | ||
|
||
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -emit-llvm < %s | FileCheck %s --check-prefixes=FULL,SPLIT | ||
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -emit-llvm < %s | FileCheck %s --check-prefixes=FULL,SPLIT | ||
|
||
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -fsplit-lto-unit -ffat-lto-objects -emit-llvm < %s | FileCheck %s --check-prefixes=THIN,SPLIT | ||
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -ffat-lto-objects -emit-llvm < %s | FileCheck %s --check-prefixes=THIN,NOSPLIT | ||
|
||
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -emit-obj < %s -o %t.full.split.o | ||
// RUN: llvm-readelf -S %t.full.split.o | FileCheck %s --check-prefixes=ELF | ||
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.full.split.bc %t.full.split.o | ||
// RUN: llvm-dis %t.full.split.bc -o - | FileCheck %s --check-prefixes=FULL,SPLIT,NOUNIFIED | ||
|
||
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -emit-obj < %s -o %t.full.nosplit.o | ||
// RUN: llvm-readelf -S %t.full.nosplit.o | FileCheck %s --check-prefixes=ELF | ||
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.full.nosplit.bc %t.full.nosplit.o | ||
// RUN: llvm-dis %t.full.nosplit.bc -o - | FileCheck %s --check-prefixes=FULL,NOSPLIT,NOUNIFIED | ||
|
||
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -fsplit-lto-unit -ffat-lto-objects -emit-obj < %s -o %t.thin.split.o | ||
// RUN: llvm-readelf -S %t.thin.split.o | FileCheck %s --check-prefixes=ELF | ||
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.thin.split.bc %t.thin.split.o | ||
// RUN: llvm-dis %t.thin.split.bc -o - | FileCheck %s --check-prefixes=THIN,SPLIT,NOUNIFIED | ||
|
||
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -ffat-lto-objects -emit-obj < %s -o %t.thin.nosplit.o | ||
// RUN: llvm-readelf -S %t.thin.nosplit.o | FileCheck %s --check-prefixes=ELF | ||
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.thin.nosplit.bc %t.thin.nosplit.o | ||
// RUN: llvm-dis %t.thin.nosplit.bc -o - | FileCheck %s --check-prefixes=THIN,NOSPLIT,NOUNIFIED | ||
|
||
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=thin -funified-lto -ffat-lto-objects -emit-obj < %s -o %t.unified.o | ||
// RUN: llvm-readelf -S %t.unified.o | FileCheck %s --check-prefixes=ELF | ||
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.unified.bc %t.unified.o | ||
// RUN: llvm-dis %t.unified.bc -o - | FileCheck %s --check-prefixes=THIN,NOSPLIT,UNIFIED | ||
|
||
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -S < %s -o - \ | ||
// RUN: | FileCheck %s --check-prefixes=ASM | ||
|
||
/// Check that the ThinLTO metadata is only set false for full LTO. | ||
// FULL: ![[#]] = !{i32 1, !"ThinLTO", i32 0} | ||
// THIN-NOT: ![[#]] = !{i32 1, !"ThinLTO", i32 0} | ||
|
||
/// Be sure we enable split LTO units correctly under -ffat-lto-objects. | ||
// SPLIT: ![[#]] = !{i32 1, !"EnableSplitLTOUnit", i32 1} | ||
// NOSPLIT: ![[#]] = !{i32 1, !"EnableSplitLTOUnit", i32 0} | ||
|
||
// UNIFIED: ![[#]] = !{i32 1, !"UnifiedLTO", i32 1} | ||
// NOUNIFIED-NOT: ![[#]] = !{i32 1, !"UnifiedLTO", i32 1} | ||
|
||
// ELF: .llvm.lto | ||
|
||
// ASM: .section .llvm.lto,"e",@progbits | ||
// ASM-NEXT: .Lllvm.embedded.object: | ||
// ASM-NEXT: .asciz "BC | ||
// ASM-NEXT: .size .Lllvm.embedded.object | ||
|
||
int test(void) { | ||
return 0xabcd; | ||
} |
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,34 @@ | ||
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC | ||
// CHECK-CC: -cc1 | ||
// CHECK-CC-SAME: -emit-obj | ||
// CHECK-CC-SAME: -ffat-lto-objects | ||
|
||
/// Without -flto -S will just emit normal ASM, so we don't expect -emit-{llvm,obj} or -ffat-lto-objects to be passed to cc1. | ||
// RUN: %clang --target=x86_64-unknown-linux-gnu -ffat-lto-objects -### %s -S 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S | ||
// CHECK-CC-S: -cc1 | ||
// CHECK-CC-S: -S | ||
// CHECK-CC-S-NOT: -emit-obj | ||
// CHECK-CC-S-NOT: -emit-llvm | ||
// CHECK-CC-S-NOT: -ffat-lto-objects | ||
|
||
/// When LTO is enabled, we expect LLVM IR output and -ffat-lto-objects to be passed to cc1. | ||
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-LTO | ||
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-LTO | ||
// CHECK-CC-S-LTO: -cc1 | ||
// CHECK-CC-S-LTO-SAME: -emit-llvm | ||
// CHECK-CC-S-LTO-SAME: -ffat-lto-objects | ||
|
||
/// Make sure we don't have a warning for -ffat-lto-objects being unused | ||
// RUN: %clang --target=x86_64-unknown-linux-gnu -ffat-lto-objects -fdriver-only -Werror -v %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-NOLTO | ||
// CHECK-CC-NOLTO: -cc1 | ||
// CHECK-CC-NOLTO-SAME: -emit-obj | ||
// CHECK-CC-NOLTO-NOT: -ffat-lto-objects | ||
|
||
/// We need to pass an additional flag (--fat-lto-objects) to lld when linking w/ -flto -ffat-lto-objects | ||
/// But it should not be there when LTO is disabled w/ -fno-lto | ||
// RUN: %clang --target=x86_64-unknown-linux-gnu --sysroot=%S/Inputs/basic_cross_linux_tree %s \ | ||
// RUN: -fuse-ld=lld -flto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=LTO %s | ||
// RUN: %clang --target=x86_64-unknown-linux-gnu --sysroot=%S/Inputs/basic_cross_linux_tree %s \ | ||
// RUN: -fuse-ld=lld -fno-lto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=NOLTO %s | ||
// LTO: "--fat-lto-objects" | ||
// NOLTO-NOT: "--fat-lto-objects" |