Skip to content

Commit c8808ba

Browse files
committed
Revert "Reapply "[X86] Set SHF_X86_64_LARGE for globals with explicit well-known large section name (llvm#74381)""
This reverts commit 7433b1c. Revert "Revert "[X86] Set SHF_X86_64_LARGE for globals with explicit well-known large section name (llvm#74381)"" This reverts commit 19fff85. Revert "[X86] Set SHF_X86_64_LARGE for globals with explicit well-known large section name (llvm#74381)" This reverts commit 323451a.
1 parent 6a016c5 commit c8808ba

File tree

2 files changed

+19
-58
lines changed

2 files changed

+19
-58
lines changed

llvm/lib/Target/TargetMachine.cpp

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ bool TargetMachine::isLargeGlobalObject(const GlobalObject *GO) const {
4343
if (getTargetTriple().getArch() != Triple::x86_64)
4444
return false;
4545

46-
auto *GV = dyn_cast<GlobalVariable>(GO);
46+
if (getCodeModel() != CodeModel::Medium && getCodeModel() != CodeModel::Large)
47+
return false;
48+
49+
if (isa<Function>(GO))
50+
return getCodeModel() == CodeModel::Large;
4751

4852
// Functions/GlobalIFuncs are only large under the large code model.
4953
if (!GV)
@@ -52,41 +56,22 @@ bool TargetMachine::isLargeGlobalObject(const GlobalObject *GO) const {
5256
if (GV->isThreadLocal())
5357
return false;
5458

55-
// We should properly mark well-known section name prefixes as small/large,
56-
// because otherwise the output section may have the wrong section flags and
57-
// the linker will lay it out in an unexpected way.
59+
// Allowing large metadata sections in the presence of an explicit section is
60+
// useful, even if GCC does not allow them. However, we should not mark
61+
// certain well-known prefixes as large, because it would make the whole
62+
// output section large and cause the linker to move it, which is almost
63+
// always undesired.
5864
StringRef Name = GV->getSection();
59-
if (!Name.empty()) {
60-
auto IsPrefix = [&](StringRef Prefix) {
61-
StringRef S = Name;
62-
return S.consume_front(Prefix) && (S.empty() || S[0] == '.');
63-
};
64-
if (IsPrefix(".bss") || IsPrefix(".data") || IsPrefix(".rodata"))
65-
return false;
66-
if (IsPrefix(".lbss") || IsPrefix(".ldata") || IsPrefix(".lrodata"))
67-
return true;
68-
}
69-
70-
// For x86-64, we treat an explicit GlobalVariable small code model to mean
71-
// that the global should be placed in a small section, and ditto for large.
72-
// Well-known section names above take precedence for correctness.
73-
if (auto CM = GV->getCodeModel()) {
74-
if (*CM == CodeModel::Small)
75-
return false;
76-
if (*CM == CodeModel::Large)
77-
return true;
78-
}
79-
80-
if (getCodeModel() == CodeModel::Medium ||
81-
getCodeModel() == CodeModel::Large) {
82-
if (!GV->getValueType()->isSized())
83-
return true;
84-
const DataLayout &DL = GV->getParent()->getDataLayout();
85-
uint64_t Size = DL.getTypeSizeInBits(GV->getValueType()) / 8;
86-
return Size == 0 || Size > LargeDataThreshold;
87-
}
65+
auto IsPrefix = [&](StringRef Prefix) {
66+
StringRef S = Name;
67+
return S.consume_front(Prefix) && (S.empty() || S[0] == '.');
68+
};
69+
if (IsPrefix(".bss") || IsPrefix(".data") || IsPrefix(".rodata"))
70+
return false;
8871

89-
return false;
72+
const DataLayout &DL = GV->getParent()->getDataLayout();
73+
uint64_t Size = DL.getTypeSizeInBits(GV->getValueType()) / 8;
74+
return Size == 0 || Size > LargeDataThreshold;
9075
}
9176

9277
bool TargetMachine::isPositionIndependent() const {

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,21 @@
2121
; SMALL: .data {{.*}} WA {{.*}}
2222
; SMALL: .data.x {{.*}} WA {{.*}}
2323
; SMALL: .data0 {{.*}} WA {{.*}}
24-
; SMALL: .ldata {{.*}} WAl {{.*}}
25-
; SMALL: .ldata.x {{.*}} WAl {{.*}}
26-
; SMALL: .ldata0 {{.*}} WA {{.*}}
27-
; SMALL: force_small {{.*}} WA {{.*}}
28-
; SMALL: force_large {{.*}} WAl {{.*}}
2924
; SMALL: foo {{.*}} WA {{.*}}
3025
; SMALL: .bss {{.*}} WA {{.*}}
31-
; SMALL: .lbss {{.*}} WAl {{.*}}
3226
; SMALL: .rodata {{.*}} A {{.*}}
33-
; SMALL: .lrodata {{.*}} Al {{.*}}
3427
; SMALL: .data.rel.ro {{.*}} WA {{.*}}
3528
; SMALL: .tbss {{.*}} WAT {{.*}}
3629
; SMALL: .tdata {{.*}} WAT {{.*}}
3730

3831
; SMALL-DS: .data {{.*}} WA {{.*}}
3932
; SMALL-DS: .data.x {{.*}} WA {{.*}}
4033
; SMALL-DS: .data0 {{.*}} WA {{.*}}
41-
; SMALL-DS: .ldata {{.*}} WAl {{.*}}
42-
; SMALL-DS: .ldata.x {{.*}} WAl {{.*}}
43-
; SMALL-DS: .ldata0 {{.*}} WA {{.*}}
4434
; SMALL-DS: .data.data {{.*}} WA {{.*}}
4535
; SMALL-DS: force_small {{.*}} WA {{.*}}
4636
; SMALL-DS: force_large {{.*}} WAl {{.*}}
4737
; SMALL-DS: foo {{.*}} WA {{.*}}
48-
; SMALL-DS: .lbss {{.*}} WAl {{.*}}
4938
; SMALL-DS: .bss.bss {{.*}} WA {{.*}}
50-
; SMALL-DS: .lrodata {{.*}} Al {{.*}}
5139
; SMALL-DS: .rodata.rodata {{.*}} A {{.*}}
5240
; SMALL-DS: .data.rel.ro.relro {{.*}} WA {{.*}}
5341
; SMALL-DS: .tbss.tbss {{.*}} WAT {{.*}}
@@ -57,10 +45,6 @@
5745
; LARGE: .data.x {{.*}} WA {{.*}}
5846
; LARGE: .data0 {{.*}} WAl {{.*}}
5947
; LARGE: .ldata {{.*}} WAl {{.*}}
60-
; LARGE: .ldata.x {{.*}} WAl {{.*}}
61-
; LARGE: .ldata0 {{.*}} WAl {{.*}}
62-
; LARGE: force_small {{.*}} WA {{.*}}
63-
; LARGE: force_large {{.*}} WAl {{.*}}
6448
; LARGE: foo {{.*}} WAl {{.*}}
6549
; LARGE: .bss {{.*}} WA {{.*}}
6650
; LARGE: .lbss {{.*}} WAl {{.*}}
@@ -73,9 +57,6 @@
7357
; LARGE-DS: .data {{.*}} WA {{.*}}
7458
; LARGE-DS: .data.x {{.*}} WA {{.*}}
7559
; LARGE-DS: .data0 {{.*}} WAl {{.*}}
76-
; LARGE-DS: .ldata {{.*}} WAl {{.*}}
77-
; LARGE-DS: .ldata.x {{.*}} WAl {{.*}}
78-
; LARGE-DS: .ldata0 {{.*}} WAl {{.*}}
7960
; LARGE-DS: .ldata.data {{.*}} WAl {{.*}}
8061
; LARGE-DS: force_small {{.*}} WA {{.*}}
8162
; LARGE-DS: force_large {{.*}} WAl {{.*}}
@@ -94,20 +75,15 @@ target triple = "x86_64--linux"
9475
@data_with_explicit_section = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], section ".data"
9576
@data_with_explicit_section2 = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], section ".data.x"
9677
@data_with_explicit_section0 = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], section ".data0"
97-
@ldata_with_explicit_section = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], section ".ldata"
98-
@ldata_with_explicit_section2 = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], section ".ldata.x"
99-
@ldata_with_explicit_section0 = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], section ".ldata0"
10078
@data = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0]
10179
@data_force_small = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], code_model "small", section "force_small"
10280
@data_force_large = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], code_model "large", section "force_large"
10381
@data_force_small_ldata = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], code_model "small", section ".ldata"
10482
@data_force_large_data = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], code_model "large", section ".data"
10583
@foo_with_explicit_section = internal global [10 x i64] [i64 1, i64 2, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0], section "foo"
10684
@bss_with_explicit_section = internal global [10 x i64] zeroinitializer, section ".bss"
107-
@lbss_with_explicit_section = internal global [10 x i64] zeroinitializer, section ".lbss"
10885
@bss = internal global [10 x i64] zeroinitializer
10986
@rodata_with_explicit_section = internal constant [10 x i64] zeroinitializer, section ".rodata"
110-
@lrodata_with_explicit_section = internal constant [10 x i64] zeroinitializer, section ".lrodata"
11187
@rodata = internal constant [10 x i64] zeroinitializer
11288
@relro = internal constant [10 x ptr] [ptr @func, ptr @func, ptr @func, ptr @func, ptr @func, ptr @func, ptr @func, ptr @func, ptr @func, ptr @func]
11389
@tbss = internal thread_local global [10 x i64] zeroinitializer

0 commit comments

Comments
 (0)