Skip to content

Commit

Permalink
Revert "[X86] With large code model, put functions into .ltext with l…
Browse files Browse the repository at this point in the history
…arge section flag (#73037)"

This reverts commit 38e4358.

May be culprit for https://lab.llvm.org/buildbot/#/builders/37/builds/28079/steps/9/logs/stdio.
  • Loading branch information
aeubanks committed Nov 28, 2023
1 parent 3661eb1 commit d8d9394
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 64 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Target/TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class TargetMachine {
void setCodeModel(CodeModel::Model CM) { CMModel = CM; }

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

bool isPositionIndependent() const;

Expand Down
15 changes: 11 additions & 4 deletions llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ static unsigned getEntrySizeForKind(SectionKind Kind) {
/// DataSections.
static StringRef getSectionPrefixForGlobal(SectionKind Kind, bool IsLarge) {
if (Kind.isText())
return IsLarge ? ".ltext" : ".text";
return ".text";
if (Kind.isReadOnly())
return IsLarge ? ".lrodata" : ".rodata";
if (Kind.isBSS())
Expand Down Expand Up @@ -650,7 +650,10 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
Name = ".rodata.cst";
Name += utostr(EntrySize);
} else {
Name = getSectionPrefixForGlobal(Kind, TM.isLargeGlobalObject(GO));
bool IsLarge = false;
if (auto *GV = dyn_cast<GlobalVariable>(GO))
IsLarge = TM.isLargeData(GV);
Name = getSectionPrefixForGlobal(Kind, IsLarge);
}

bool HasPrefix = false;
Expand Down Expand Up @@ -770,8 +773,12 @@ getGlobalObjectInfo(const GlobalObject *GO, const TargetMachine &TM) {
Group = C->getName();
IsComdat = C->getSelectionKind() == Comdat::Any;
}
if (TM.isLargeGlobalObject(GO))
Flags |= ELF::SHF_X86_64_LARGE;
if (auto *GV = dyn_cast<GlobalVariable>(GO)) {
if (TM.isLargeData(GV)) {
assert(TM.getTargetTriple().getArch() == Triple::x86_64);
Flags |= ELF::SHF_X86_64_LARGE;
}
}
return {Group, IsComdat, Flags};
}

Expand Down
12 changes: 2 additions & 10 deletions llvm/lib/Target/TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,13 @@ TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString,

TargetMachine::~TargetMachine() = default;

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

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

if (isa<Function>(GO))
return getCodeModel() == CodeModel::Large;

auto *GV = cast<GlobalVariable>(GO);

if (GV->isThreadLocal())
return false;

// Allowing large metadata sections in the presence of an explicit section is
// useful, even if GCC does not allow them. However, we should not mark
// certain well-known prefixes as large, because it would make the whole
Expand Down
38 changes: 26 additions & 12 deletions llvm/lib/Target/X86/X86Subtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,32 @@ X86Subtarget::classifyLocalReference(const GlobalValue *GV) const {
if (is64Bit()) {
// 64-bit ELF PIC local references may use GOTOFF relocations.
if (isTargetELF()) {
CodeModel::Model CM = TM.getCodeModel();
assert(CM != CodeModel::Tiny &&
"Tiny codesize model not supported on X86");
// Large objects use GOTOFF, otherwise use RIP-rel access.
if (auto *GO = dyn_cast_or_null<GlobalObject>(GV))
return TM.isLargeGlobalObject(GO) ? X86II::MO_GOTOFF
: X86II::MO_NO_FLAG;

// For non-GlobalObjects, the small and medium code models treat them as
// accessible with a RIP-rel access. The large code model uses GOTOFF to
// access everything that's not explicitly small.
return CM == CodeModel::Large ? X86II::MO_GOTOFF : X86II::MO_NO_FLAG;
switch (TM.getCodeModel()) {
// 64-bit small code model is simple: All rip-relative.
case CodeModel::Tiny:
llvm_unreachable("Tiny codesize model not supported on X86");
case CodeModel::Small:
case CodeModel::Kernel:
return X86II::MO_NO_FLAG;

// The large PIC code model uses GOTOFF.
case CodeModel::Large:
return X86II::MO_GOTOFF;

// Medium is a hybrid: RIP-rel for code and non-large data, GOTOFF for
// remaining DSO local data.
case CodeModel::Medium:
// Constant pool and jump table handling pass a nullptr to this
// function so we need to use isa_and_nonnull.
if (isa_and_nonnull<Function>(GV))
return X86II::MO_NO_FLAG; // All code is RIP-relative
if (auto *GVar = dyn_cast_or_null<GlobalVariable>(GV)) {
if (TM.isLargeData(GVar))
return X86II::MO_GOTOFF;
}
return X86II::MO_NO_FLAG; // Local symbols use GOTOFF.
}
llvm_unreachable("invalid code model");
}

// Otherwise, this is either a RIP-relative reference or a 64-bit movabsq,
Expand Down
25 changes: 0 additions & 25 deletions llvm/test/CodeGen/X86/code-model-elf-text-sections.ll

This file was deleted.

22 changes: 11 additions & 11 deletions llvm/test/CodeGen/X86/pcsections.ll
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ define void @empty_no_aux() !pcsections !0 {
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: retq
; CHECK-NEXT: .Lfunc_end0:
; CHECK: .section section_no_aux,"awo",@progbits,.{{l?}}text
; CHECK: .section section_no_aux,"awo",@progbits,.text
; CHECK-NEXT: .Lpcsection_base0:
; DEFCM-NEXT: .long .Lfunc_begin0-.Lpcsection_base0
; LARGE-NEXT: .quad .Lfunc_begin0-.Lpcsection_base0
; CHECK-NEXT: .long .Lfunc_end0-.Lfunc_begin0
; CHECK-NEXT: .{{l?}}text
; CHECK-NEXT: .text
entry:
ret void
}
Expand All @@ -35,15 +35,15 @@ define void @empty_aux() !pcsections !1 {
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: retq
; CHECK-NEXT: .Lfunc_end1:
; CHECK: .section section_aux,"awo",@progbits,.{{l?}}text
; CHECK: .section section_aux,"awo",@progbits,.text
; CHECK-NEXT: .Lpcsection_base1:
; DEFCM-NEXT: .long .Lfunc_begin1-.Lpcsection_base1
; LARGE-NEXT: .quad .Lfunc_begin1-.Lpcsection_base1
; CHECK-NEXT: .long .Lfunc_end1-.Lfunc_begin1
; CHECK-NEXT: .long 10
; CHECK-NEXT: .long 20
; CHECK-NEXT: .long 30
; CHECK-NEXT: .{{l?}}text
; CHECK-NEXT: .text
entry:
ret void
}
Expand All @@ -56,44 +56,44 @@ define i64 @multiple() !pcsections !0 {
; CHECK-NEXT: movq
; CHECK-NEXT: retq
; CHECK-NEXT: .Lfunc_end2:
; CHECK: .section section_no_aux,"awo",@progbits,.{{l?}}text
; CHECK: .section section_no_aux,"awo",@progbits,.text
; CHECK-NEXT: .Lpcsection_base2:
; DEFCM-NEXT: .long .Lfunc_begin2-.Lpcsection_base2
; LARGE-NEXT: .quad .Lfunc_begin2-.Lpcsection_base2
; CHECK-NEXT: .long .Lfunc_end2-.Lfunc_begin2
; CHECK-NEXT: .section section_aux_42,"awo",@progbits,.{{l?}}text
; CHECK-NEXT: .section section_aux_42,"awo",@progbits,.text
; CHECK-NEXT: .Lpcsection_base3:
; DEFCM-NEXT: .long .Lpcsection0-.Lpcsection_base3
; LARGE-NEXT: .quad .Lpcsection0-.Lpcsection_base3
; CHECK-NEXT: .long 42
; CHECK-NEXT: .section section_aux_21264,"awo",@progbits,.{{l?}}text
; CHECK-NEXT: .section section_aux_21264,"awo",@progbits,.text
; CHECK-NEXT: .Lpcsection_base4:
; DEFCM-NEXT: .long .Lpcsection0-.Lpcsection_base4
; LARGE-NEXT: .quad .Lpcsection0-.Lpcsection_base4
; CHECK-NEXT: .long 21264
; CHECK-NEXT: .{{l?}}text
; CHECK-NEXT: .text
entry:
%0 = load i64, ptr @bar, align 8, !pcsections !2
ret i64 %0
}

define void @multiple_uleb128() !pcsections !6 {
; CHECK-LABEL: multiple_uleb128:
; CHECK: .section section_aux,"awo",@progbits,.{{l?}}text
; CHECK: .section section_aux,"awo",@progbits,.text
; CHECK-NEXT: .Lpcsection_base5:
; DEFCM-NEXT: .long .Lfunc_begin3-.Lpcsection_base5
; LARGE-NEXT: .quad .Lfunc_begin3-.Lpcsection_base5
; CHECK-NEXT: .uleb128 .Lfunc_end3-.Lfunc_begin3
; CHECK-NEXT: .byte 42
; CHECK-NEXT: .ascii "\345\216&"
; CHECK-NEXT: .byte 255
; CHECK-NEXT: .section section_aux_21264,"awo",@progbits,.{{l?}}text
; CHECK-NEXT: .section section_aux_21264,"awo",@progbits,.text
; CHECK-NEXT: .Lpcsection_base6:
; DEFCM-NEXT: .long .Lfunc_begin3-.Lpcsection_base6
; LARGE-NEXT: .quad .Lfunc_begin3-.Lpcsection_base6
; CHECK-NEXT: .long .Lfunc_end3-.Lfunc_begin3
; CHECK-NEXT: .long 21264
; CHECK-NEXT: .{{l?}}text
; CHECK-NEXT: .text
entry:
ret void
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
; RUN: --generate=__dump_jit_debug_objects %s | llvm-objdump --section-headers - | \
; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
;
; CHECK_LOAD_ADDR-NOT: {{[0-9]*}} .ltext {{.*}} 0000000000000000 TEXT
; CHECK_LOAD_ADDR-NOT: {{[0-9]*}} .text {{.*}} 0000000000000000 TEXT

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

Expand Down

0 comments on commit d8d9394

Please sign in to comment.