Skip to content

Commit

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

This reverts commit d8a0439.

Revert "Revert "Reland [X86] With large code model, put functions into .ltext with large section flag (llvm#73037)""

This reverts commit 76f78ec.

Revert "Reland [X86] With large code model, put functions into .ltext with large section flag (llvm#73037)"

This reverts commit 4bf8a68.

Revert "Revert "[X86] With large code model, put functions into .ltext with large section flag (llvm#73037)""

This reverts commit d8d9394.

Revert "[X86] With large code model, put functions into .ltext with large section flag (llvm#73037)"

This reverts commit 38e4358.
  • Loading branch information
Zentrik committed Jul 7, 2024
1 parent f4c6ef7 commit 1f98e2e
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 72 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 @@ -615,7 +615,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 @@ -649,7 +649,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 @@ -769,8 +772,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
11 changes: 3 additions & 8 deletions llvm/lib/Target/TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,11 @@ 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 (isa<Function>(GO))
return getCodeModel() == CodeModel::Large;

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

if (GV->isThreadLocal())
if (getCodeModel() != CodeModel::Medium && getCodeModel() != CodeModel::Large)
return false;

// Allowing large metadata sections in the presence of an explicit section is
Expand Down
37 changes: 25 additions & 12 deletions llvm/lib/Target/X86/X86Subtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,32 @@ X86Subtarget::classifyLocalReference(const GlobalValue *GV) const {
if (is64Bit()) {
// 64-bit ELF PIC local references may use GOTOFF relocations.
if (isTargetELF()) {
assert(CM != CodeModel::Tiny &&
"Tiny codesize model not supported on X86");
// In the large code model, even referencing a global under the large data
// threshold which is considered "small", we need to use GOTOFF.
if (CM == CodeModel::Large)
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;
// 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.
return X86II::MO_NO_FLAG;

// 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.

11 changes: 0 additions & 11 deletions llvm/test/CodeGen/X86/code-model-elf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@
; 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
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-PIC
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-PIC
; 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

; Check that the relocations we emit are valid.
; RUN: llc -verify-machineinstrs < %s -relocation-model=static -code-model=small -filetype=obj -o /dev/null
; RUN: llc -verify-machineinstrs < %s -relocation-model=static -code-model=medium -filetype=obj -o /dev/null
; RUN: llc -verify-machineinstrs < %s -relocation-model=static -code-model=large -filetype=obj -o /dev/null
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=small -filetype=obj -o /dev/null
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium -large-data-threshold=1000 -filetype=obj -o /dev/null
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium -filetype=obj -o /dev/null
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large -filetype=obj -o /dev/null
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large -large-data-threshold=1000 -filetype=obj -o /dev/null

; Generated from this C source:
;
Expand Down
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
82 changes: 82 additions & 0 deletions llvm/test/ExecutionEngine/OrcLazy/debug-objects-elf-minimal.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
; REQUIRES: native && target-x86_64

; In-memory debug-object contains some basic DWARF
;
; RUN: lli --jit-linker=rtdyld \
; RUN: --generate=__dump_jit_debug_objects %s | llvm-dwarfdump --diff - | FileCheck %s
;
; RUN: lli --jit-linker=jitlink \
; RUN: --generate=__dump_jit_debug_objects %s | llvm-dwarfdump --diff - | FileCheck %s
;
; CHECK: -: file format elf64-x86-64
; CHECK: .debug_info contents:
; CHECK: 0x00000000: Compile Unit: length = 0x00000047, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x0000004b)
; CHECK: DW_TAG_compile_unit
; CHECK: DW_AT_producer ("compiler version")
; CHECK: DW_AT_language (DW_LANG_C99)
; CHECK: DW_AT_name ("source-file.c")
; CHECK: DW_AT_stmt_list ()
; CHECK: DW_AT_comp_dir ("/workspace")
; CHECK: DW_AT_low_pc ()
; CHECK: DW_AT_high_pc ()
; CHECK: DW_TAG_subprogram
; CHECK: DW_AT_low_pc ()
; CHECK: DW_AT_high_pc ()
; CHECK: DW_AT_frame_base (DW_OP_reg7 RSP)
; CHECK: DW_AT_name ("main")
; CHECK: DW_AT_decl_file ("/workspace/source-file.c")
; CHECK: DW_AT_decl_line (4)
; CHECK: DW_AT_type ("int")
; CHECK: DW_AT_external (true)
; CHECK: DW_TAG_base_type
; CHECK: DW_AT_name ("int")
; CHECK: DW_AT_encoding (DW_ATE_signed)
; CHECK: DW_AT_byte_size (0x04)
; CHECK: NULL

; Text section of the in-memory debug-object has a non-null load-address
;
; RUN: lli --jit-linker=rtdyld \
; RUN: --generate=__dump_jit_debug_objects %s | llvm-objdump --section-headers - | \
; RUN: FileCheck --check-prefix=CHECK_LOAD_ADDR %s
;
; RUN: lli --jit-linker=jitlink \
; 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]*}} .text {{.*}} 0000000000000000 TEXT

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

; Built-in symbol provided by the JIT
declare void @__dump_jit_debug_objects(ptr)

; Host-process symbol from the GDB JIT interface
@__jit_debug_descriptor = external global i8, align 1

define i32 @main() !dbg !9 {
%1 = alloca i32, align 4
store i32 0, ptr %1, align 4
call void @__dump_jit_debug_objects(ptr @__jit_debug_descriptor), !dbg !13
ret i32 0, !dbg !14
}

!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.dbg.cu = !{!5}
!llvm.ident = !{!8}

!0 = !{i32 2, !"SDK Version", [3 x i32] [i32 10, i32 15, i32 6]}
!1 = !{i32 7, !"Dwarf Version", i32 4}
!2 = !{i32 2, !"Debug Info Version", i32 3}
!3 = !{i32 1, !"wchar_size", i32 4}
!4 = !{i32 7, !"PIC Level", i32 2}
!5 = distinct !DICompileUnit(language: DW_LANG_C99, file: !6, producer: "compiler version", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !7, nameTableKind: None)
!6 = !DIFile(filename: "source-file.c", directory: "/workspace")
!7 = !{}
!8 = !{!"compiler version"}
!9 = distinct !DISubprogram(name: "main", scope: !6, file: !6, line: 4, type: !10, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !5, retainedNodes: !7)
!10 = !DISubroutineType(types: !11)
!11 = !{!12}
!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!13 = !DILocation(line: 5, column: 3, scope: !9)
!14 = !DILocation(line: 6, column: 3, scope: !9)

0 comments on commit 1f98e2e

Please sign in to comment.