Skip to content

Commit 00ad0c5

Browse files
committed
Revert "Reland [X86] With large code model, put functions into .ltext with large section flag (llvm#73037)"
This reverts commit d8a0439.
1 parent 8a1a9f1 commit 00ad0c5

File tree

8 files changed

+132
-74
lines changed

8 files changed

+132
-74
lines changed

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class TargetMachine {
239239
void setCodeModel(CodeModel::Model CM) { CMModel = CM; }
240240

241241
void setLargeDataThreshold(uint64_t LDT) { LargeDataThreshold = LDT; }
242-
bool isLargeGlobalObject(const GlobalObject *GO) const;
242+
bool isLargeData(const GlobalVariable *GV) const;
243243

244244
bool isPositionIndependent() const;
245245

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ static unsigned getEntrySizeForKind(SectionKind Kind) {
615615
/// DataSections.
616616
static StringRef getSectionPrefixForGlobal(SectionKind Kind, bool IsLarge) {
617617
if (Kind.isText())
618-
return IsLarge ? ".ltext" : ".text";
618+
return ".text";
619619
if (Kind.isReadOnly())
620620
return IsLarge ? ".lrodata" : ".rodata";
621621
if (Kind.isBSS())
@@ -649,7 +649,10 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
649649
Name = ".rodata.cst";
650650
Name += utostr(EntrySize);
651651
} else {
652-
Name = getSectionPrefixForGlobal(Kind, TM.isLargeGlobalObject(GO));
652+
bool IsLarge = false;
653+
if (auto *GV = dyn_cast<GlobalVariable>(GO))
654+
IsLarge = TM.isLargeData(GV);
655+
Name = getSectionPrefixForGlobal(Kind, IsLarge);
653656
}
654657

655658
bool HasPrefix = false;
@@ -769,8 +772,12 @@ getGlobalObjectInfo(const GlobalObject *GO, const TargetMachine &TM) {
769772
Group = C->getName();
770773
IsComdat = C->getSelectionKind() == Comdat::Any;
771774
}
772-
if (TM.isLargeGlobalObject(GO))
773-
Flags |= ELF::SHF_X86_64_LARGE;
775+
if (auto *GV = dyn_cast<GlobalVariable>(GO)) {
776+
if (TM.isLargeData(GV)) {
777+
assert(TM.getTargetTriple().getArch() == Triple::x86_64);
778+
Flags |= ELF::SHF_X86_64_LARGE;
779+
}
780+
}
774781
return {Group, IsComdat, Flags};
775782
}
776783

llvm/lib/Target/TargetMachine.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,13 @@ TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString,
3939

4040
TargetMachine::~TargetMachine() = default;
4141

42-
bool TargetMachine::isLargeGlobalObject(const GlobalObject *GO) const {
43-
if (getTargetTriple().getArch() != Triple::x86_64)
42+
bool TargetMachine::isLargeData(const GlobalVariable *GV) const {
43+
if (getTargetTriple().getArch() != Triple::x86_64 || GV->isThreadLocal())
4444
return false;
4545

4646
if (getCodeModel() != CodeModel::Medium && getCodeModel() != CodeModel::Large)
4747
return false;
4848

49-
if (isa<Function>(GO))
50-
return getCodeModel() == CodeModel::Large;
51-
52-
auto *GV = cast<GlobalVariable>(GO);
53-
54-
if (GV->isThreadLocal())
55-
return false;
56-
5749
// Allowing large metadata sections in the presence of an explicit section is
5850
// useful, even if GCC does not allow them. However, we should not mark
5951
// certain well-known prefixes as large, because it would make the whole

llvm/lib/Target/X86/X86Subtarget.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,32 @@ X86Subtarget::classifyLocalReference(const GlobalValue *GV) const {
8383
if (is64Bit()) {
8484
// 64-bit ELF PIC local references may use GOTOFF relocations.
8585
if (isTargetELF()) {
86-
assert(CM != CodeModel::Tiny &&
87-
"Tiny codesize model not supported on X86");
88-
// In the large code model, even referencing a global under the large data
89-
// threshold which is considered "small", we need to use GOTOFF.
90-
if (CM == CodeModel::Large)
86+
switch (TM.getCodeModel()) {
87+
// 64-bit small code model is simple: All rip-relative.
88+
case CodeModel::Tiny:
89+
llvm_unreachable("Tiny codesize model not supported on X86");
90+
case CodeModel::Small:
91+
case CodeModel::Kernel:
92+
return X86II::MO_NO_FLAG;
93+
94+
// The large PIC code model uses GOTOFF.
95+
case CodeModel::Large:
9196
return X86II::MO_GOTOFF;
92-
// Large objects use GOTOFF, otherwise use RIP-rel access.
93-
if (auto *GO = dyn_cast_or_null<GlobalObject>(GV))
94-
return TM.isLargeGlobalObject(GO) ? X86II::MO_GOTOFF
95-
: X86II::MO_NO_FLAG;
96-
// For non-GlobalObjects, the small and medium code models treat them as
97-
// accessible with a RIP-rel access.
98-
return X86II::MO_NO_FLAG;
97+
98+
// Medium is a hybrid: RIP-rel for code and non-large data, GOTOFF for
99+
// remaining DSO local data.
100+
case CodeModel::Medium:
101+
// Constant pool and jump table handling pass a nullptr to this
102+
// function so we need to use isa_and_nonnull.
103+
if (isa_and_nonnull<Function>(GV))
104+
return X86II::MO_NO_FLAG; // All code is RIP-relative
105+
if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV)) {
106+
if (TM.isLargeData(GVar))
107+
return X86II::MO_GOTOFF;
108+
}
109+
return X86II::MO_NO_FLAG; // Local symbols use GOTOFF.
110+
}
111+
llvm_unreachable("invalid code model");
99112
}
100113

101114
// Otherwise, this is either a RIP-relative reference or a 64-bit movabsq,

llvm/test/CodeGen/X86/code-model-elf-text-sections.ll

Lines changed: 0 additions & 25 deletions
This file was deleted.

llvm/test/CodeGen/X86/code-model-elf.ll

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@
99
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium -large-data-threshold=1000 | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-SMALL-DATA-PIC
1010
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-PIC
1111
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-PIC
12-
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large -large-data-threshold=1000 | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-SMALL-DATA-PIC
13-
14-
; Check that the relocations we emit are valid.
15-
; RUN: llc -verify-machineinstrs < %s -relocation-model=static -code-model=small -filetype=obj -o /dev/null
16-
; RUN: llc -verify-machineinstrs < %s -relocation-model=static -code-model=medium -filetype=obj -o /dev/null
17-
; RUN: llc -verify-machineinstrs < %s -relocation-model=static -code-model=large -filetype=obj -o /dev/null
18-
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=small -filetype=obj -o /dev/null
19-
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium -large-data-threshold=1000 -filetype=obj -o /dev/null
20-
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium -filetype=obj -o /dev/null
21-
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large -filetype=obj -o /dev/null
22-
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large -large-data-threshold=1000 -filetype=obj -o /dev/null
2312

2413
; Generated from this C source:
2514
;

llvm/test/CodeGen/X86/pcsections.ll

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ define void @empty_no_aux() !pcsections !0 {
1919
; CHECK: # %bb.0: # %entry
2020
; CHECK-NEXT: retq
2121
; CHECK-NEXT: .Lfunc_end0:
22-
; CHECK: .section section_no_aux,"awo",@progbits,.{{l?}}text
22+
; CHECK: .section section_no_aux,"awo",@progbits,.text
2323
; CHECK-NEXT: .Lpcsection_base0:
2424
; DEFCM-NEXT: .long .Lfunc_begin0-.Lpcsection_base0
2525
; LARGE-NEXT: .quad .Lfunc_begin0-.Lpcsection_base0
2626
; CHECK-NEXT: .long .Lfunc_end0-.Lfunc_begin0
27-
; CHECK-NEXT: .{{l?}}text
27+
; CHECK-NEXT: .text
2828
entry:
2929
ret void
3030
}
@@ -35,15 +35,15 @@ define void @empty_aux() !pcsections !1 {
3535
; CHECK: # %bb.0: # %entry
3636
; CHECK-NEXT: retq
3737
; CHECK-NEXT: .Lfunc_end1:
38-
; CHECK: .section section_aux,"awo",@progbits,.{{l?}}text
38+
; CHECK: .section section_aux,"awo",@progbits,.text
3939
; CHECK-NEXT: .Lpcsection_base1:
4040
; DEFCM-NEXT: .long .Lfunc_begin1-.Lpcsection_base1
4141
; LARGE-NEXT: .quad .Lfunc_begin1-.Lpcsection_base1
4242
; CHECK-NEXT: .long .Lfunc_end1-.Lfunc_begin1
4343
; CHECK-NEXT: .long 10
4444
; CHECK-NEXT: .long 20
4545
; CHECK-NEXT: .long 30
46-
; CHECK-NEXT: .{{l?}}text
46+
; CHECK-NEXT: .text
4747
entry:
4848
ret void
4949
}
@@ -56,44 +56,44 @@ define i64 @multiple() !pcsections !0 {
5656
; CHECK-NEXT: movq
5757
; CHECK-NEXT: retq
5858
; CHECK-NEXT: .Lfunc_end2:
59-
; CHECK: .section section_no_aux,"awo",@progbits,.{{l?}}text
59+
; CHECK: .section section_no_aux,"awo",@progbits,.text
6060
; CHECK-NEXT: .Lpcsection_base2:
6161
; DEFCM-NEXT: .long .Lfunc_begin2-.Lpcsection_base2
6262
; LARGE-NEXT: .quad .Lfunc_begin2-.Lpcsection_base2
6363
; CHECK-NEXT: .long .Lfunc_end2-.Lfunc_begin2
64-
; CHECK-NEXT: .section section_aux_42,"awo",@progbits,.{{l?}}text
64+
; CHECK-NEXT: .section section_aux_42,"awo",@progbits,.text
6565
; CHECK-NEXT: .Lpcsection_base3:
6666
; DEFCM-NEXT: .long .Lpcsection0-.Lpcsection_base3
6767
; LARGE-NEXT: .quad .Lpcsection0-.Lpcsection_base3
6868
; CHECK-NEXT: .long 42
69-
; CHECK-NEXT: .section section_aux_21264,"awo",@progbits,.{{l?}}text
69+
; CHECK-NEXT: .section section_aux_21264,"awo",@progbits,.text
7070
; CHECK-NEXT: .Lpcsection_base4:
7171
; DEFCM-NEXT: .long .Lpcsection0-.Lpcsection_base4
7272
; LARGE-NEXT: .quad .Lpcsection0-.Lpcsection_base4
7373
; CHECK-NEXT: .long 21264
74-
; CHECK-NEXT: .{{l?}}text
74+
; CHECK-NEXT: .text
7575
entry:
7676
%0 = load i64, ptr @bar, align 8, !pcsections !2
7777
ret i64 %0
7878
}
7979

8080
define void @multiple_uleb128() !pcsections !6 {
8181
; CHECK-LABEL: multiple_uleb128:
82-
; CHECK: .section section_aux,"awo",@progbits,.{{l?}}text
82+
; CHECK: .section section_aux,"awo",@progbits,.text
8383
; CHECK-NEXT: .Lpcsection_base5:
8484
; DEFCM-NEXT: .long .Lfunc_begin3-.Lpcsection_base5
8585
; LARGE-NEXT: .quad .Lfunc_begin3-.Lpcsection_base5
8686
; CHECK-NEXT: .uleb128 .Lfunc_end3-.Lfunc_begin3
8787
; CHECK-NEXT: .byte 42
8888
; CHECK-NEXT: .ascii "\345\216&"
8989
; CHECK-NEXT: .byte 255
90-
; CHECK-NEXT: .section section_aux_21264,"awo",@progbits,.{{l?}}text
90+
; CHECK-NEXT: .section section_aux_21264,"awo",@progbits,.text
9191
; CHECK-NEXT: .Lpcsection_base6:
9292
; DEFCM-NEXT: .long .Lfunc_begin3-.Lpcsection_base6
9393
; LARGE-NEXT: .quad .Lfunc_begin3-.Lpcsection_base6
9494
; CHECK-NEXT: .long .Lfunc_end3-.Lfunc_begin3
9595
; CHECK-NEXT: .long 21264
96-
; CHECK-NEXT: .{{l?}}text
96+
; CHECK-NEXT: .text
9797
entry:
9898
ret void
9999
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
; REQUIRES: native && target-x86_64
2+
3+
; In-memory debug-object contains some basic DWARF
4+
;
5+
; RUN: lli --jit-linker=rtdyld \
6+
; RUN: --generate=__dump_jit_debug_objects %s | llvm-dwarfdump --diff - | FileCheck %s
7+
;
8+
; RUN: lli --jit-linker=jitlink \
9+
; RUN: --generate=__dump_jit_debug_objects %s | llvm-dwarfdump --diff - | FileCheck %s
10+
;
11+
; CHECK: -: file format elf64-x86-64
12+
; CHECK: .debug_info contents:
13+
; CHECK: 0x00000000: Compile Unit: length = 0x00000047, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000004b)
14+
; CHECK: DW_TAG_compile_unit
15+
; CHECK: DW_AT_producer ("compiler version")
16+
; CHECK: DW_AT_language (DW_LANG_C99)
17+
; CHECK: DW_AT_name ("source-file.c")
18+
; CHECK: DW_AT_stmt_list ()
19+
; CHECK: DW_AT_comp_dir ("/workspace")
20+
; CHECK: DW_AT_low_pc ()
21+
; CHECK: DW_AT_high_pc ()
22+
; CHECK: DW_TAG_subprogram
23+
; CHECK: DW_AT_low_pc ()
24+
; CHECK: DW_AT_high_pc ()
25+
; CHECK: DW_AT_frame_base (DW_OP_reg7 RSP)
26+
; CHECK: DW_AT_name ("main")
27+
; CHECK: DW_AT_decl_file ("/workspace/source-file.c")
28+
; CHECK: DW_AT_decl_line (4)
29+
; CHECK: DW_AT_type ("int")
30+
; CHECK: DW_AT_external (true)
31+
; CHECK: DW_TAG_base_type
32+
; CHECK: DW_AT_name ("int")
33+
; CHECK: DW_AT_encoding (DW_ATE_signed)
34+
; CHECK: DW_AT_byte_size (0x04)
35+
; CHECK: NULL
36+
37+
; Text section of the in-memory debug-object has a non-null load-address
38+
;
39+
; RUN: lli --jit-linker=rtdyld \
40+
; RUN: --generate=__dump_jit_debug_objects %s | llvm-objdump --section-headers - | \
41+
; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
42+
;
43+
; RUN: lli --jit-linker=jitlink \
44+
; RUN: --generate=__dump_jit_debug_objects %s | llvm-objdump --section-headers - | \
45+
; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
46+
;
47+
; CHECK_LOAD_ADDR-NOT: {{[0-9]*}} .text {{.*}} 0000000000000000 TEXT
48+
49+
target triple = "x86_64-unknown-unknown-elf"
50+
51+
; Built-in symbol provided by the JIT
52+
declare void @__dump_jit_debug_objects(ptr)
53+
54+
; Host-process symbol from the GDB JIT interface
55+
@__jit_debug_descriptor = external global i8, align 1
56+
57+
define i32 @main() !dbg !9 {
58+
%1 = alloca i32, align 4
59+
store i32 0, ptr %1, align 4
60+
call void @__dump_jit_debug_objects(ptr @__jit_debug_descriptor), !dbg !13
61+
ret i32 0, !dbg !14
62+
}
63+
64+
!llvm.module.flags = !{!0, !1, !2, !3, !4}
65+
!llvm.dbg.cu = !{!5}
66+
!llvm.ident = !{!8}
67+
68+
!0 = !{i32 2, !"SDK Version", [3 x i32] [i32 10, i32 15, i32 6]}
69+
!1 = !{i32 7, !"Dwarf Version", i32 4}
70+
!2 = !{i32 2, !"Debug Info Version", i32 3}
71+
!3 = !{i32 1, !"wchar_size", i32 4}
72+
!4 = !{i32 7, !"PIC Level", i32 2}
73+
!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "compiler version", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, nameTableKind: None)
74+
!6 = !DIFile(filename: "source-file.c", directory: "/workspace")
75+
!7 = !{}
76+
!8 = !{!"compiler version"}
77+
!9 = distinct !DISubprogram(name: "main", scope: !6, file: !6, line: 4, type: !10, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
78+
!10 = !DISubroutineType(types: !11)
79+
!11 = !{!12}
80+
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
81+
!13 = !DILocation(line: 5, column: 3, scope: !9)
82+
!14 = !DILocation(line: 6, column: 3, scope: !9)

0 commit comments

Comments
 (0)