Skip to content

Commit d8d9394

Browse files
committed
Revert "[X86] With large code model, put functions into .ltext with large section flag (#73037)"
This reverts commit 38e4358. May be culprit for https://lab.llvm.org/buildbot/#/builders/37/builds/28079/steps/9/logs/stdio.
1 parent 3661eb1 commit d8d9394

File tree

7 files changed

+52
-64
lines changed

7 files changed

+52
-64
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
@@ -616,7 +616,7 @@ static unsigned getEntrySizeForKind(SectionKind Kind) {
616616
/// DataSections.
617617
static StringRef getSectionPrefixForGlobal(SectionKind Kind, bool IsLarge) {
618618
if (Kind.isText())
619-
return IsLarge ? ".ltext" : ".text";
619+
return ".text";
620620
if (Kind.isReadOnly())
621621
return IsLarge ? ".lrodata" : ".rodata";
622622
if (Kind.isBSS())
@@ -650,7 +650,10 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
650650
Name = ".rodata.cst";
651651
Name += utostr(EntrySize);
652652
} else {
653-
Name = getSectionPrefixForGlobal(Kind, TM.isLargeGlobalObject(GO));
653+
bool IsLarge = false;
654+
if (auto *GV = dyn_cast<GlobalVariable>(GO))
655+
IsLarge = TM.isLargeData(GV);
656+
Name = getSectionPrefixForGlobal(Kind, IsLarge);
654657
}
655658

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

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: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +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-
CodeModel::Model CM = TM.getCodeModel();
87-
assert(CM != CodeModel::Tiny &&
88-
"Tiny codesize model not supported on X86");
89-
// Large objects use GOTOFF, otherwise use RIP-rel access.
90-
if (auto *GO = dyn_cast_or_null<GlobalObject>(GV))
91-
return TM.isLargeGlobalObject(GO) ? X86II::MO_GOTOFF
92-
: X86II::MO_NO_FLAG;
93-
94-
// For non-GlobalObjects, the small and medium code models treat them as
95-
// accessible with a RIP-rel access. The large code model uses GOTOFF to
96-
// access everything that's not explicitly small.
97-
return CM == CodeModel::Large ? X86II::MO_GOTOFF : X86II::MO_NO_FLAG;
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:
96+
return X86II::MO_GOTOFF;
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");
98112
}
99113

100114
// 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/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
}

llvm/test/ExecutionEngine/OrcLazy/debug-objects-elf-minimal.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
; RUN: --generate=__dump_jit_debug_objects %s | llvm-objdump --section-headers - | \
4545
; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
4646
;
47-
; CHECK_LOAD_ADDR-NOT: {{[0-9]*}} .ltext {{.*}} 0000000000000000 TEXT
47+
; CHECK_LOAD_ADDR-NOT: {{[0-9]*}} .text {{.*}} 0000000000000000 TEXT
4848

4949
target triple = "x86_64-unknown-unknown-elf"
5050

0 commit comments

Comments
 (0)