Skip to content

Commit 421e402

Browse files
committed
[gold] Add preliminary FatLTO support to the Gold plugin
This changes the definition if `isSectionBitcode` to only be valid for the `.llvm.lto` section, since this API is only called from LTO, and the `.llvmbc` section was not intended to be used for LTO. This allows the gold plugin to keep its existing behavior without introducing any significant changes. Depends on D146778 Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D152973
1 parent 3a45b84 commit 421e402

File tree

8 files changed

+152
-22
lines changed

8 files changed

+152
-22
lines changed

llvm/lib/Object/ObjectFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ uint32_t ObjectFile::getSymbolAlignment(DataRefImpl DRI) const { return 0; }
7979
bool ObjectFile::isSectionBitcode(DataRefImpl Sec) const {
8080
Expected<StringRef> NameOrErr = getSectionName(Sec);
8181
if (NameOrErr)
82-
return *NameOrErr == ".llvmbc" || *NameOrErr == ".llvm.lto";
82+
return *NameOrErr == ".llvm.lto";
8383
consumeError(NameOrErr.takeError());
8484
return false;
8585
}

llvm/test/LTO/X86/Inputs/bcsection.macho.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
.asciz "Wrong Section"
33

44
.section __LLVM,__bitcode
5-
.incbin "bcsection.bc"
5+
.incbin "llvm.lto.section.bc"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.section .llvm.lto
2+
.incbin "llvm.lto.section.bc"

llvm/test/LTO/X86/bcsection.ll

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,17 @@
22
; RUN: llvm-as -o %t/bcsection.bc %s
33

44
; RUN: llvm-mc -I=%t -filetype=obj -triple=x86_64-pc-win32 -o %t/bcsection.coff.bco %p/Inputs/bcsection.s
5-
; RUN: llvm-nm %t/bcsection.coff.bco | FileCheck %s
6-
; RUN: llvm-lto -exported-symbol=main -exported-symbol=_main -o %t/bcsection.coff.o %t/bcsection.coff.bco
7-
; RUN: llvm-nm %t/bcsection.coff.o | FileCheck %s
5+
; RUN: llvm-nm %t/bcsection.coff.bco | FileCheck %s --allow-empty
6+
; RUN: not llvm-lto -exported-symbol=main -exported-symbol=_main -o %t/bcsection.coff.o %t/bcsection.coff.bco
87

98
; RUN: llvm-mc -I=%t -filetype=obj -triple=x86_64-unknown-linux-gnu -o %t/bcsection.elf.bco %p/Inputs/bcsection.s
10-
; RUN: llvm-nm %t/bcsection.elf.bco | FileCheck %s
11-
; RUN: llvm-lto -exported-symbol=main -exported-symbol=_main -o %t/bcsection.elf.o %t/bcsection.elf.bco
12-
; RUN: llvm-nm %t/bcsection.elf.o | FileCheck %s
13-
14-
; RUN: llvm-mc -I=%t -filetype=obj -triple=x86_64-apple-darwin11 -o %t/bcsection.macho.bco %p/Inputs/bcsection.macho.s
15-
; RUN: llvm-nm %t/bcsection.macho.bco | FileCheck %s
16-
; RUN: llvm-lto -exported-symbol=main -exported-symbol=_main -o %t/bcsection.macho.o %t/bcsection.macho.bco
17-
; RUN: llvm-nm %t/bcsection.macho.o | FileCheck %s
9+
; RUN: llvm-nm %t/bcsection.elf.bco | FileCheck %s --allow-empty
10+
; RUN: not llvm-lto -exported-symbol=main -exported-symbol=_main -o %t/bcsection.elf.o %t/bcsection.elf.bco
1811

1912
target triple = "x86_64-unknown-linux-gnu"
2013

21-
; CHECK: main
14+
;; The .llvmbc section is not intended for use with LTO, so there should be nothing here
15+
; CHECK-NOT: main
2216
define i32 @main() {
2317
ret i32 0
2418
}

llvm/test/LTO/X86/llvm.lto.section.ll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: rm -rf %t && mkdir -p %t
2+
; RUN: llvm-as -o %t/llvm.lto.section.bc %s
3+
4+
; RUN: llvm-mc -I=%t -filetype=obj -triple=x86_64-pc-win32 -o %t/llvm.lto.section.coff.bco %p/Inputs/llvm.lto.section.s
5+
; RUN: llvm-nm %t/llvm.lto.section.coff.bco | FileCheck %s
6+
; RUN: llvm-lto -exported-symbol=main -exported-symbol=_main -o %t/llvm.lto.section.coff.o %t/llvm.lto.section.coff.bco
7+
; RUN: llvm-nm %t/llvm.lto.section.coff.o | FileCheck %s
8+
9+
; RUN: llvm-mc -I=%t -filetype=obj -triple=x86_64-unknown-linux-gnu -o %t/llvm.lto.section.elf.bco %p/Inputs/llvm.lto.section.s
10+
; RUN: llvm-nm %t/llvm.lto.section.elf.bco | FileCheck %s
11+
; RUN: llvm-lto -exported-symbol=main -exported-symbol=_main -o %t/llvm.lto.section.elf.o %t/llvm.lto.section.elf.bco
12+
; RUN: llvm-nm %t/llvm.lto.section.elf.o | FileCheck %s
13+
14+
15+
; RUN: llvm-mc -I=%t -filetype=obj -triple=x86_64-apple-darwin11 -o %t/bcsection.macho.bco %p/Inputs/bcsection.macho.s
16+
; RUN: llvm-nm %t/bcsection.macho.bco | FileCheck %s
17+
; RUN: llvm-lto -exported-symbol=main -exported-symbol=_main -o %t/bcsection.macho.o %t/bcsection.macho.bco
18+
; RUN: llvm-nm %t/bcsection.macho.o | FileCheck %s
19+
20+
target triple = "x86_64-unknown-linux-gnu"
21+
22+
; CHECK: main
23+
define i32 @main() {
24+
ret i32 0
25+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
2+
# RUN: not %gold -plugin %llvmshlibdir/LLVMgold%shlibext %t -o /dev/null 2>&1 | FileCheck %s
3+
4+
# CHECK: error:{{.*}} Invalid bitcode signature
5+
6+
.section .llvm.lto,"e",@progbits
7+
.Lllvm.embedded.object:
8+
.asciz "BC\300\3365\000"
9+
.size .Lllvm.embedded.object, 12
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
;; Basic FatLTO tests.
2+
3+
; RUN: rm -rf %t && split-file %s %t
4+
5+
;; Ensure that input files contain .llvm.lto section
6+
; RUN: llc %t/a-LTO.ll --filetype=obj -o %t/a-fatLTO.o
7+
; RUN: opt --module-summary %t/a-LTO.ll -o %t/a-fatLTO.bc
8+
; RUN: llvm-objcopy --add-section=.llvm.lto=%t/a-fatLTO.bc %t/a-fatLTO.o
9+
; RUN: llvm-objcopy --set-section-flags=.llvm.lto=readonly,exclude %t/a-fatLTO.o
10+
; RUN: llvm-readobj -S %t/a-fatLTO.o | FileCheck --check-prefix=CHECK-A %s
11+
12+
; CHECK-A: Name: .llvm.lto
13+
14+
; RUN: llc %t/main-LTO.ll --filetype=obj -o %t/main-fatLTO.o
15+
; RUN: opt --module-summary %t/main-LTO.ll -o %t/main-fatLTO.bc
16+
; RUN: llvm-objcopy --add-section=.llvm.lto=%t/main-fatLTO.bc %t/main-fatLTO.o
17+
; RUN: llvm-objcopy --set-section-flags=.llvm.lto=readonly,exclude %t/main-fatLTO.o
18+
; RUN: llvm-readobj -S %t/main-fatLTO.o | FileCheck --check-prefix=CHECK-MAIN %s
19+
20+
; CHECK-MAIN: Name: .llvm.lto
21+
22+
;; Final executable should not have .llvm.lto section no matter what the target is
23+
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext -o %t/foo-fatLTO %t/a-fatLTO.o %t/main-fatLTO.o
24+
; RUN: llvm-readobj -S %t/foo-fatLTO | FileCheck --check-prefix=CHECK-LTO-TARGET %s
25+
26+
;; Check that fat objects work w/ s=--start-lib
27+
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext -o %t/foo-fatLTO.start_lib --start-lib %t/a-fatLTO.o %t/main-fatLTO.o --end-lib
28+
; RUN: llvm-readobj -S %t/foo-fatLTO.start_lib | FileCheck --check-prefix=CHECK-LTO-TARGET %s
29+
30+
;; Check if .llvm.lto section gets aggregated in LTO target
31+
; CHECK-LTO-TARGET-NOT: Name: .llvm.lto
32+
33+
;; Final executable should not have .llvm.lto section no matter what the target is
34+
; RUN: %gold -o %t/foo-fatNoLTO %t/a-fatLTO.o %/t/main-fatLTO.o
35+
; RUN: llvm-readobj -S %t/foo-fatNoLTO | FileCheck --check-prefix=CHECK-NON-LTO-TARGET %s
36+
37+
;; Check if .llvm.lto section gets aggregated in non-LTO target
38+
; CHECK-NON-LTO-TARGET-NOT: Name: .llvm.lto
39+
40+
;; Check if the LTO target executable produced from FatLTO object file is
41+
;; identical to the one produced from LTO modules
42+
; RUN: opt --module-summary %t/a-LTO.ll -o %t/a-LTO.bc
43+
; RUN: opt --module-summary %t/main-LTO.ll -o %t/main-LTO.bc
44+
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext -o %t/foo-LTO %t/a-LTO.bc %t/main-LTO.bc
45+
; RUN: cmp %t/foo-fatLTO %t/foo-LTO
46+
47+
;; Check if the no-LTO target executable produced from FatLTO object file is
48+
;; identical to the one produced from regular object files
49+
50+
; RUN: llc %t/a-LTO.ll --filetype=obj -o %t/a.o
51+
; RUN: llc %t/main-LTO.ll --filetype=obj -o %t/main.o
52+
53+
; RUN: %gold -o %t/foo-noLTO %t/a.o %t/main.o
54+
; RUN: cmp %t/foo-fatNoLTO %t/foo-noLTO
55+
56+
;; Check archive support
57+
; RUN: llvm-ar rcs %t/a.a %t/a-fatLTO.o
58+
; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext -o %t/foo-fatLTO.archive %t/main-LTO.bc %t/a.a
59+
; RUN: cmp %t/foo-fatLTO.archive %t/foo-LTO
60+
61+
;--- a-LTO.ll
62+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
63+
target triple = "x86_64-unknown-linux-gnu"
64+
65+
; Function Attrs: noinline nounwind uwtable
66+
define dso_local i32 @_start() #0 {
67+
entry:
68+
ret i32 0
69+
}
70+
71+
attributes #0 = { noinline nounwind uwtable }
72+
73+
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6}
74+
75+
!0 = !{i32 1, !"wchar_size", i32 4}
76+
!1 = !{i32 7, !"PIC Level", i32 2}
77+
!2 = !{i32 7, !"PIE Level", i32 2}
78+
!3 = !{i32 7, !"uwtable", i32 2}
79+
!4 = !{i32 7, !"frame-pointer", i32 2}
80+
!5 = !{i32 1, !"ThinLTO", i32 0}
81+
!6 = !{i32 1, !"EnableSplitLTOUnit", i32 1}
82+
83+
;--- main-LTO.ll
84+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
85+
target triple = "x86_64-unknown-linux-gnu"
86+
87+
; Function Attrs: noinline nounwind uwtable
88+
define dso_local i32 @main() #0 {
89+
entry:
90+
%retval = alloca i32, align 4
91+
store i32 0, ptr %retval, align 4
92+
%call = call i32 (...) @_start()
93+
ret i32 %call
94+
}
95+
96+
declare i32 @_start(...)
97+
98+
attributes #0 = { noinline nounwind uwtable }
99+
100+
!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6}
101+
102+
!0 = !{i32 1, !"wchar_size", i32 4}
103+
!1 = !{i32 7, !"PIC Level", i32 2}
104+
!2 = !{i32 7, !"PIE Level", i32 2}
105+
!3 = !{i32 7, !"uwtable", i32 2}
106+
!4 = !{i32 7, !"frame-pointer", i32 2}
107+
!5 = !{i32 1, !"ThinLTO", i32 0}
108+
!6 = !{i32 1, !"EnableSplitLTOUnit", i32 1}

llvm/tools/gold/gold-plugin.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,6 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file,
538538
BufferRef = Buffer->getMemBufferRef();
539539
}
540540

541-
// Only use bitcode files for LTO. InputFile::create() will load bitcode
542-
// from the .llvmbc section within a binary object, this bitcode is typically
543-
// generated by -fembed-bitcode and is not to be used by LLVMgold.so for LTO.
544-
if (identify_magic(BufferRef.getBuffer()) != file_magic::bitcode) {
545-
*claimed = 0;
546-
return LDPS_OK;
547-
}
548-
549541
*claimed = 1;
550542

551543
Expected<std::unique_ptr<InputFile>> ObjOrErr = InputFile::create(BufferRef);

0 commit comments

Comments
 (0)