Skip to content

Commit fb3d647

Browse files
committed
[X86] Don't respect large data threshold for globals with an explicit section
If multiple globals are placed in an explicit section, there's a chance that the large data threshold will cause the different globals to be inconsistent in whether they're large or small. Mixing sections with mismatched large section flags can cause undesirable issues like increased relocation pressure because there may be 32-bit references to the section in some TUs, but the section is considered large since input section flags are unioned and other TUs added the large section flag. An explicit code model on the global still overrides the decision. We can do this for globals without any references to them, like what we did with asan_globals in llvm#74514. If we have some precompiled small code model files where asan_globals is not considered large mixed with medium/large code model files, that's ok because the section is considered large and placed farther. However, overriding the code model for globals in some TUs but not others and having references to them from code will still result in the above undesired behavior. This mitigates a whole class of mismatched large section flag issues like what llvm#77986 was trying to fix. This ends up not adding the SHF_X86_64_LARGE section flag on explicit sections in the medium/large code model. This is ok for the large code model since all references from large text must use 64-bit relocations anyway.
1 parent 1847846 commit fb3d647

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

llvm/lib/Target/TargetMachine.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ bool TargetMachine::isLargeGlobalValue(const GlobalValue *GVal) const {
8383
return true;
8484
}
8585

86-
if (getCodeModel() == CodeModel::Medium ||
87-
getCodeModel() == CodeModel::Large) {
86+
// Respect large data threshold for medium and large code models.
87+
// ... But only for globals without an explicit section. If multiple globals
88+
// are placed in an explicit section, there's a good chance that the data
89+
// threshold will cause the different globals to be inconsistent in whether
90+
// they're large or small. Mixing large section flags can cause undesirable
91+
// issues like increased relocation pressure.
92+
if (!GV->hasSection() && (getCodeModel() == CodeModel::Medium ||
93+
getCodeModel() == CodeModel::Large)) {
8894
if (!GV->getValueType()->isSized())
8995
return true;
9096
const DataLayout &DL = GV->getParent()->getDataLayout();

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@
5555

5656
; LARGE: .data {{.*}} WA {{.*}}
5757
; LARGE: .data.x {{.*}} WA {{.*}}
58-
; LARGE: .data0 {{.*}} WAl {{.*}}
58+
; LARGE: .data0 {{.*}} WA {{.*}}
5959
; LARGE: .ldata {{.*}} WAl {{.*}}
6060
; LARGE: .ldata.x {{.*}} WAl {{.*}}
61-
; LARGE: .ldata0 {{.*}} WAl {{.*}}
61+
; LARGE: .ldata0 {{.*}} WA {{.*}}
6262
; LARGE: force_small {{.*}} WA {{.*}}
6363
; LARGE: force_large {{.*}} WAl {{.*}}
64-
; LARGE: foo {{.*}} WAl {{.*}}
64+
; LARGE: foo {{.*}} WA {{.*}}
6565
; LARGE: .bss {{.*}} WA {{.*}}
6666
; LARGE: .lbss {{.*}} WAl {{.*}}
6767
; LARGE: .rodata {{.*}} A {{.*}}
@@ -72,14 +72,14 @@
7272

7373
; LARGE-DS: .data {{.*}} WA {{.*}}
7474
; LARGE-DS: .data.x {{.*}} WA {{.*}}
75-
; LARGE-DS: .data0 {{.*}} WAl {{.*}}
75+
; LARGE-DS: .data0 {{.*}} WA {{.*}}
7676
; LARGE-DS: .ldata {{.*}} WAl {{.*}}
7777
; LARGE-DS: .ldata.x {{.*}} WAl {{.*}}
78-
; LARGE-DS: .ldata0 {{.*}} WAl {{.*}}
78+
; LARGE-DS: .ldata0 {{.*}} WA {{.*}}
7979
; LARGE-DS: .ldata.data {{.*}} WAl {{.*}}
8080
; LARGE-DS: force_small {{.*}} WA {{.*}}
8181
; LARGE-DS: force_large {{.*}} WAl {{.*}}
82-
; LARGE-DS: foo {{.*}} WAl {{.*}}
82+
; LARGE-DS: foo {{.*}} WA {{.*}}
8383
; LARGE-DS: .bss {{.*}} WA {{.*}}
8484
; LARGE-DS: .lbss.bss {{.*}} WAl {{.*}}
8585
; LARGE-DS: .rodata {{.*}} A {{.*}}

0 commit comments

Comments
 (0)