[llvm] [X86] Don't respect large data threshold for globals with an explicit section (PR #78348)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 17 14:35:14 PST 2024
================
@@ -58,31 +58,31 @@ bool TargetMachine::isLargeGlobalValue(const GlobalValue *GVal) const {
if (GV->isThreadLocal())
return false;
- // We should properly mark well-known section name prefixes as small/large,
- // because otherwise the output section may have the wrong section flags and
- // the linker will lay it out in an unexpected way.
- StringRef Name = GV->getSection();
- if (!Name.empty()) {
- auto IsPrefix = [&](StringRef Prefix) {
- StringRef S = Name;
- return S.consume_front(Prefix) && (S.empty() || S[0] == '.');
- };
- if (IsPrefix(".bss") || IsPrefix(".data") || IsPrefix(".rodata"))
- return false;
- if (IsPrefix(".lbss") || IsPrefix(".ldata") || IsPrefix(".lrodata"))
- return true;
- }
-
// For x86-64, we treat an explicit GlobalVariable small code model to mean
// that the global should be placed in a small section, and ditto for large.
- // Well-known section names above take precedence for correctness.
if (auto CM = GV->getCodeModel()) {
if (*CM == CodeModel::Small)
return false;
if (*CM == CodeModel::Large)
return true;
}
+ // Treat all globals in explicit sections as small, except for the standard
+ // large sections of .lbss, .ldata, .lrodata. This reduces the risk of linking
+ // together small and large sections, resulting in small references to large
+ // data sections. The code model attribute overrides this above.
+ if (GV->hasSection()) {
+ StringRef Name = GV->getSection();
+ auto IsPrefix = [&](StringRef Prefix) {
+ StringRef S = Name;
+ return S.consume_front(Prefix) && (S.empty() || S[0] == '.');
+ };
+ if (IsPrefix(".lbss") || IsPrefix(".ldata") || IsPrefix(".lrodata"))
----------------
MaskRay wrote:
`return IsPrefix(".lbss") || IsPrefix(".ldata") || IsPrefix(".lrodata")`
https://github.com/llvm/llvm-project/pull/78348
More information about the llvm-commits
mailing list