Skip to content

Commit 62663f7

Browse files
committed
[clang][llvm] Enable fat-lto-object support for COFF targets
1 parent c05ce9b commit 62663f7

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7789,7 +7789,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
77897789
options::OPT_fno_fat_lto_objects)) {
77907790
if (IsUsingLTO && A->getOption().matches(options::OPT_ffat_lto_objects)) {
77917791
assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin);
7792-
if (!Triple.isOSBinFormatELF()) {
7792+
if (!Triple.isOSBinFormatELF() && !Triple.isOSBinFormatCOFF()) {
77937793
D.Diag(diag::err_drv_unsupported_opt_for_target)
77947794
<< A->getAsString(Args) << TC.getTripleString();
77957795
}

clang/test/CodeGen/fat-lto-objects.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -flto=full -ffat-lto-objects -fsplit-lto-unit -S < %s -o - \
3636
// RUN: | FileCheck %s --check-prefixes=ASM
3737

38+
// RUN: %clang -cc1 -triple i386-pc-win32 -flto=full -ffat-lto-objects -fsplit-lto-unit -S < %s -o - \
39+
// RUN: | FileCheck %s --check-prefixes=ASM-COFF
40+
3841
/// Make sure that FatLTO generates .llvm.lto sections that are the same as the output from normal LTO compilations
3942
// RUN: %clang -O2 --target=x86_64-unknown-linux-gnu -fPIE -flto=full -ffat-lto-objects -c %s -o %t.fatlto.full.o
4043
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.fatlto.full.bc %t.fatlto.full.o
@@ -43,6 +46,13 @@
4346
// RUN: llvm-dis < %t.nofat.full.bc -o %t.nofat.full.ll
4447
// RUN: diff %t.fatlto.full.ll %t.nofat.full.ll
4548

49+
// RUN: %clang -O2 --target=i386-pc-win32 -flto=full -ffat-lto-objects -c %s -o %t.fatlto.full.coff.o
50+
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.fatlto.full.coff.bc %t.fatlto.full.coff.o
51+
// RUN: llvm-dis < %t.fatlto.full.coff.bc -o %t.fatlto.full.coff.ll
52+
// RUN: %clang -O2 --target=i386-pc-win32 -flto=full -c %s -o %t.nofat.full.coff.bc
53+
// RUN: llvm-dis < %t.nofat.full.coff.bc -o %t.nofat.full.coff.ll
54+
// RUN: diff %t.fatlto.full.coff.ll %t.nofat.full.coff.ll
55+
4656
// RUN: %clang -O2 --target=x86_64-unknown-linux-gnu -fPIE -flto=thin -ffat-lto-objects -c %s -o %t.fatlto.thin.o
4757
// RUN: llvm-objcopy --dump-section=.llvm.lto=%t.fatlto.thin.bc %t.fatlto.thin.o
4858
// RUN: llvm-dis < %t.fatlto.thin.bc -o %t.fatlto.thin.ll
@@ -67,6 +77,10 @@
6777
// ASM-NEXT: .asciz "BC
6878
// ASM-NEXT: .size .Lllvm.embedded.object
6979

80+
// ASM-COFF: .section .llvm.lto,"ynD"
81+
// ASM-COFF-NEXT: L_llvm.embedded.object:
82+
// ASM-COFF-NEXT: .asciz "BC
83+
7084
const char* foo = "foo";
7185

7286
int test(void) {

clang/test/Driver/fat-lto-objects.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC
2+
// RUN: %clang --target=i386-pc-win32 -flto -ffat-lto-objects -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC
23
// CHECK-CC: -cc1
34
// CHECK-CC-SAME: -emit-obj
45
// CHECK-CC-SAME: -ffat-lto-objects
56

67
/// 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.
78
// RUN: %clang --target=x86_64-unknown-linux-gnu -ffat-lto-objects -### %s -S 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S
9+
// RUN: %clang --target=i386-pc-win32 -ffat-lto-objects -### %s -S 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S
810
// CHECK-CC-S: -cc1
911
// CHECK-CC-S: -S
1012
// CHECK-CC-S-NOT: -emit-obj
@@ -13,35 +15,41 @@
1315

1416
/// When fat LTO is enabled with -S, we expect asm output and -ffat-lto-objects to be passed to cc1.
1517
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -S 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-LTO
18+
// RUN: %clang --target=i386-pc-win32 -flto -ffat-lto-objects -### %s -S 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-LTO
1619
// CHECK-CC-S-LTO: -cc1
1720
// CHECK-CC-S-NOT: -emit-llvm
1821
// CHECK-CC-S-LTO-SAME: -ffat-lto-objects
1922

2023
/// When fat LTO is enabled with -S and -emit-llvm, we expect IR output and -ffat-lto-objects to be passed to cc1.
2124
// 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-EL-LTO
25+
// RUN: %clang --target=i386-pc-win32 -flto -ffat-lto-objects -### %s -S -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-CC-S-EL-LTO
2226
// CHECK-CC-S-EL-LTO: -cc1
2327
// CHECK-CC-S-EL-LTO-SAME: -emit-llvm
2428
// CHECK-CC-S-EL-LTO-SAME: -ffat-lto-objects
2529

2630
/// When fat LTO is enabled without -S we expect native object output and -ffat-lto-object to be passed to cc1.
2731
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-C-LTO
32+
// RUN: %clang --target=i386-pc-win32 -flto -ffat-lto-objects -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-C-LTO
2833
// CHECK-CC-C-LTO: -cc1
2934
// CHECK-CC-C-LTO-SAME: -emit-obj
3035
// CHECK-CC-C-LTO-SAME: -ffat-lto-objects
3136

3237
/// When fat LTO is enabled with -c and -emit-llvm we expect bitcode output and -ffat-lto-object to be passed to cc1.
3338
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -### %s -c -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-CC-C-EL-LTO
39+
// RUN: %clang --target=i386-pc-win32 -flto -ffat-lto-objects -### %s -c -emit-llvm 2>&1 | FileCheck %s -check-prefix=CHECK-CC-C-EL-LTO
3440
// CHECK-CC-C-EL-LTO: -cc1
3541
// CHECK-CC-C-EL-LTO-SAME: -emit-llvm-bc
3642
// CHECK-CC-C-EL-LTO-SAME: -ffat-lto-objects
3743

3844
/// Make sure we don't have a warning for -ffat-lto-objects being unused
3945
// 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
46+
// RUN: %clang --target=i386-pc-win32 -ffat-lto-objects -fdriver-only -Werror -v %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-NOLTO
4047
// CHECK-CC-NOLTO: -cc1
4148
// CHECK-CC-NOLTO-SAME: -emit-obj
4249
// CHECK-CC-NOLTO-NOT: -ffat-lto-objects
4350

4451
// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects -fno-fat-lto-objects -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-NOLTO
52+
// RUN: %clang --target=i386-pc-win32 -flto -ffat-lto-objects -fno-fat-lto-objects -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-NOLTO
4553

4654
/// We need to pass an additional flag (--fat-lto-objects) to lld when linking w/ -flto -ffat-lto-objects
4755
/// But it should not be there when LTO is disabled w/ -fno-lto

llvm/lib/Transforms/IPO/EmbedBitcodePass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ PreservedAnalyses EmbedBitcodePass::run(Module &M, ModuleAnalysisManager &AM) {
2727
reportFatalUsageError("Can only embed the module once");
2828

2929
Triple T(M.getTargetTriple());
30-
if (T.getObjectFormat() != Triple::ELF)
31-
reportFatalUsageError(
32-
"EmbedBitcode pass currently only supports ELF object format");
30+
if (T.getObjectFormat() != Triple::ELF && T.getObjectFormat() != Triple::COFF)
31+
reportFatalUsageError("EmbedBitcode pass currently only supports COFF and "
32+
"ELF object formats");
3333

3434
std::string Data;
3535
raw_string_ostream OS(Data);

llvm/test/Transforms/EmbedBitcode/embed-unsupported-object-format.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
@a = global i32 1
44

5-
; CHECK: LLVM ERROR: EmbedBitcode pass currently only supports ELF object format
5+
; CHECK: LLVM ERROR: EmbedBitcode pass currently only supports COFF and ELF object formats

0 commit comments

Comments
 (0)