aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
authorArthur Eubanks <aeubanks@google.com>2023-10-18 16:24:23 -0700
committerGitHub <noreply@github.com>2023-10-18 16:24:23 -0700
commitf3ea73133f91c1c23596d45680c8f2269c1dd289 (patch)
tree6d56b3c61db8bc818fe4d2714249664170c72a0c /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
parent7aa24915cb66c51bab7c15854877136930d3ed17 (diff)
downloadllvm-f3ea73133f91c1c23596d45680c8f2269c1dd289.zip
llvm-f3ea73133f91c1c23596d45680c8f2269c1dd289.tar.gz
llvm-f3ea73133f91c1c23596d45680c8f2269c1dd289.tar.bz2
[ELF] Set large section flag for globals with an explicit section (#69396)
An oversight in https://reviews.llvm.org/D148836 since this is a different code path.
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp43
1 files changed, 23 insertions, 20 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 6210e7f..f3ba38081 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -763,6 +763,25 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, StringRef SectionName,
return NextUniqueID++;
}
+static std::tuple<StringRef, bool, unsigned>
+getGlobalObjectInfo(const GlobalObject *GO, const TargetMachine &TM) {
+ StringRef Group = "";
+ bool IsComdat = false;
+ unsigned Flags = 0;
+ if (const Comdat *C = getELFComdat(GO)) {
+ Flags |= ELF::SHF_GROUP;
+ Group = C->getName();
+ IsComdat = C->getSelectionKind() == Comdat::Any;
+ }
+ 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};
+}
+
static MCSection *selectExplicitSectionGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM,
MCContext &Ctx, Mangler &Mang, unsigned &NextUniqueID,
@@ -793,14 +812,9 @@ static MCSection *selectExplicitSectionGlobal(
// Infer section flags from the section name if we can.
Kind = getELFKindForNamedSection(SectionName, Kind);
- StringRef Group = "";
- bool IsComdat = false;
unsigned Flags = getELFSectionFlags(Kind);
- if (const Comdat *C = getELFComdat(GO)) {
- Group = C->getName();
- IsComdat = C->getSelectionKind() == Comdat::Any;
- Flags |= ELF::SHF_GROUP;
- }
+ auto [Group, IsComdat, ExtraFlags] = getGlobalObjectInfo(GO, TM);
+ Flags |= ExtraFlags;
unsigned EntrySize = getEntrySizeForKind(Kind);
const unsigned UniqueID = calcUniqueIDUpdateFlagsAndSize(
@@ -848,19 +862,8 @@ static MCSectionELF *selectELFSectionForGlobal(
const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags,
unsigned *NextUniqueID, const MCSymbolELF *AssociatedSymbol) {
- StringRef Group = "";
- bool IsComdat = false;
- if (const Comdat *C = getELFComdat(GO)) {
- Flags |= ELF::SHF_GROUP;
- Group = C->getName();
- IsComdat = C->getSelectionKind() == Comdat::Any;
- }
- if (auto *GV = dyn_cast<GlobalVariable>(GO)) {
- if (TM.isLargeData(GV)) {
- assert(TM.getTargetTriple().getArch() == Triple::x86_64);
- Flags |= ELF::SHF_X86_64_LARGE;
- }
- }
+ auto [Group, IsComdat, ExtraFlags] = getGlobalObjectInfo(GO, TM);
+ Flags |= ExtraFlags;
// Get the section entry size based on the kind.
unsigned EntrySize = getEntrySizeForKind(Kind);