[llvm] [X86] Set SHF_X86_64_LARGE for globals with explicit well-known large section name (PR #74381)
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 4 14:59:52 PST 2023
================
@@ -55,17 +52,22 @@ bool TargetMachine::isLargeGlobalObject(const GlobalObject *GO) const {
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
- // output section large and cause the linker to move it, which is almost
- // always undesired.
+ // useful, even if GCC does not allow them. However, 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();
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;
+
+ if (getCodeModel() != CodeModel::Medium && getCodeModel() != CodeModel::Large)
+ return false;
const DataLayout &DL = GV->getParent()->getDataLayout();
----------------
rnk wrote:
I think this will read better if you nest the LargeDataThreshold check in the medium / large conditional, like:
```
if (getCodeModel() == CodeModel::Medium || getCodeModel() == CodeModel::Large) {
...
return Size == 0 || Size > LargeDataThreshold;
}
return false;
```
https://github.com/llvm/llvm-project/pull/74381
More information about the llvm-commits
mailing list