Index: llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h =================================================================== --- llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h +++ llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h @@ -53,10 +53,10 @@ const Constant *C, unsigned &Align) const override; - MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; MCSection *getSectionForJumpTable(const Function &F, @@ -103,10 +103,10 @@ ArrayRef ModuleFlags, const TargetMachine &TM) const override; - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; - MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, @@ -144,10 +144,10 @@ ~TargetLoweringObjectFileCOFF() override {} void Initialize(MCContext &Ctx, const TargetMachine &TM) override; - MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; void getNameWithPrefix(SmallVectorImpl &OutName, const GlobalValue *GV, Index: llvm/include/llvm/IR/GlobalValue.h =================================================================== --- llvm/include/llvm/IR/GlobalValue.h +++ llvm/include/llvm/IR/GlobalValue.h @@ -26,6 +26,7 @@ namespace llvm { class Comdat; +class GlobalObject; class PointerType; class Module; @@ -492,6 +493,11 @@ // increased. bool canIncreaseAlignment() const; + const GlobalObject *getBaseObject() const { + return const_cast(this)->getBaseObject(); + } + GlobalObject *getBaseObject(); + /// This method unlinks 'this' from the containing module, but does not delete /// it. virtual void removeFromParent() = 0; Index: llvm/include/llvm/Target/TargetLoweringObjectFile.h =================================================================== --- llvm/include/llvm/Target/TargetLoweringObjectFile.h +++ llvm/include/llvm/Target/TargetLoweringObjectFile.h @@ -86,21 +86,21 @@ /// Classify the specified global variable into a set of target independent /// categories embodied in SectionKind. - static SectionKind getKindForGlobal(const GlobalValue *GV, + static SectionKind getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM); /// This method computes the appropriate section to emit the specified global /// variable or function definition. This should not be passed external (or /// available externally) globals. - MCSection *SectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const; /// This method computes the appropriate section to emit the specified global /// variable or function definition. This should not be passed external (or /// available externally) globals. - MCSection *SectionForGlobal(const GlobalValue *GV, + MCSection *SectionForGlobal(const GlobalObject *GO, const TargetMachine &TM) const { - return SectionForGlobal(GV, getKindForGlobal(GV, TM), TM); + return SectionForGlobal(GO, getKindForGlobal(GO, TM), TM); } virtual void getNameWithPrefix(SmallVectorImpl &OutName, @@ -115,9 +115,9 @@ /// Targets should implement this method to assign a section to globals with /// an explicit section specfied. The implementation of this method can - /// assume that GV->hasSection() is true. + /// assume that GO->hasSection() is true. virtual MCSection * - getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, + getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const = 0; /// Return an MCExpr to use for a reference to the specified global variable @@ -187,7 +187,7 @@ const GlobalValue *GV) const {} protected: - virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV, + virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const = 0; }; Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -209,15 +209,15 @@ } MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { - StringRef SectionName = GV->getSection(); + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { + StringRef SectionName = GO->getSection(); // Infer section flags from the section name if we can. Kind = getELFKindForNamedSection(SectionName, Kind); StringRef Group = ""; unsigned Flags = getELFSectionFlags(Kind); - if (const Comdat *C = getELFComdat(GV)) { + if (const Comdat *C = getELFComdat(GO)) { Group = C->getName(); Flags |= ELF::SHF_GROUP; } @@ -246,7 +246,7 @@ } static MCSectionELF * -selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV, +selectELFSectionForGlobal(MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang, const TargetMachine &TM, bool EmitUniqueSection, unsigned Flags, unsigned *NextUniqueID) { @@ -274,7 +274,7 @@ } StringRef Group = ""; - if (const Comdat *C = getELFComdat(GV)) { + if (const Comdat *C = getELFComdat(GO)) { Flags |= ELF::SHF_GROUP; Group = C->getName(); } @@ -285,8 +285,8 @@ // We also need alignment here. // FIXME: this is getting the alignment of the character, not the // alignment of the global! - unsigned Align = GV->getParent()->getDataLayout().getPreferredAlignment( - cast(GV)); + unsigned Align = GO->getParent()->getDataLayout().getPreferredAlignment( + cast(GO)); std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + "."; Name = SizeSpec + utostr(Align); @@ -297,7 +297,7 @@ Name = getSectionPrefixForGlobal(Kind); } - if (const Function *F = dyn_cast(GV)) { + if (const auto *F = dyn_cast(GO)) { const auto &OptionalPrefix = F->getSectionPrefix(); if (OptionalPrefix) Name += *OptionalPrefix; @@ -305,7 +305,7 @@ if (EmitUniqueSection && UniqueSectionNames) { Name.push_back('.'); - TM.getNameWithPrefix(Name, GV, Mang, true); + TM.getNameWithPrefix(Name, GO, Mang, true); } unsigned UniqueID = MCContext::GenericSectionID; if (EmitUniqueSection && !UniqueSectionNames) { @@ -317,7 +317,7 @@ } MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { unsigned Flags = getELFSectionFlags(Kind); // If we have -ffunction-section or -fdata-section then we should emit the @@ -329,9 +329,9 @@ else EmitUniqueSection = TM.getDataSections(); } - EmitUniqueSection |= GV->hasComdat(); + EmitUniqueSection |= GO->hasComdat(); - return selectELFSectionForGlobal(getContext(), GV, Kind, getMangler(), TM, + return selectELFSectionForGlobal(getContext(), GO, Kind, getMangler(), TM, EmitUniqueSection, Flags, &NextUniqueID); } @@ -572,22 +572,22 @@ } MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { // Parse the section specifier and create it if valid. StringRef Segment, Section; unsigned TAA = 0, StubSize = 0; bool TAAParsed; - checkMachOComdat(GV); + checkMachOComdat(GO); std::string ErrorCode = - MCSectionMachO::ParseSectionSpecifier(GV->getSection(), Segment, Section, + MCSectionMachO::ParseSectionSpecifier(GO->getSection(), Segment, Section, TAA, TAAParsed, StubSize); if (!ErrorCode.empty()) { // If invalid, report the error with report_fatal_error. - report_fatal_error("Global variable '" + GV->getName() + + report_fatal_error("Global variable '" + GO->getName() + "' has an invalid section specifier '" + - GV->getSection() + "': " + ErrorCode + "."); + GO->getSection() + "': " + ErrorCode + "."); } // Get the section. @@ -604,7 +604,7 @@ // to reject it here. if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) { // If invalid, report the error with report_fatal_error. - report_fatal_error("Global variable '" + GV->getName() + + report_fatal_error("Global variable '" + GO->getName() + "' section type or attributes does not match previous" " section specifier"); } @@ -613,19 +613,19 @@ } MCSection *TargetLoweringObjectFileMachO::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { - checkMachOComdat(GV); + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { + checkMachOComdat(GO); // Handle thread local data. if (Kind.isThreadBSS()) return TLSBSSSection; if (Kind.isThreadData()) return TLSDataSection; if (Kind.isText()) - return GV->isWeakForLinker() ? TextCoalSection : TextSection; + return GO->isWeakForLinker() ? TextCoalSection : TextSection; // If this is weak/linkonce, put this in a coalescable section, either in text // or data depending on if it is writable. - if (GV->isWeakForLinker()) { + if (GO->isWeakForLinker()) { if (Kind.isReadOnly()) return ConstTextCoalSection; return DataCoalSection; @@ -633,21 +633,21 @@ // FIXME: Alignment check should be handled by section classifier. if (Kind.isMergeable1ByteCString() && - GV->getParent()->getDataLayout().getPreferredAlignment( - cast(GV)) < 32) + GO->getParent()->getDataLayout().getPreferredAlignment( + cast(GO)) < 32) return CStringSection; // Do not put 16-bit arrays in the UString section if they have an // externally visible label, this runs into issues with certain linker // versions. - if (Kind.isMergeable2ByteCString() && !GV->hasExternalLinkage() && - GV->getParent()->getDataLayout().getPreferredAlignment( - cast(GV)) < 32) + if (Kind.isMergeable2ByteCString() && !GO->hasExternalLinkage() && + GO->getParent()->getDataLayout().getPreferredAlignment( + cast(GO)) < 32) return UStringSection; // With MachO only variables whose corresponding symbol starts with 'l' or // 'L' can be merged, so we only try merging GVs with private linkage. - if (GV->hasPrivateLinkage() && Kind.isMergeableConst()) { + if (GO->hasPrivateLinkage() && Kind.isMergeableConst()) { if (Kind.isMergeableConst4()) return FourByteConstantSection; if (Kind.isMergeableConst8()) @@ -821,10 +821,13 @@ void TargetLoweringObjectFileMachO::getNameWithPrefix( SmallVectorImpl &OutName, const GlobalValue *GV, const TargetMachine &TM) const { - SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM); - const MCSection *TheSection = SectionForGlobal(GV, GVKind, TM); - bool CannotUsePrivateLabel = - !canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection); + bool CannotUsePrivateLabel = true; + if (auto *GO = GV->getBaseObject()) { + SectionKind GOKind = TargetLoweringObjectFile::getKindForGlobal(GO, TM); + const MCSection *TheSection = SectionForGlobal(GO, GOKind, TM); + CannotUsePrivateLabel = + !canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection); + } getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel); } @@ -912,18 +915,18 @@ } MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { int Selection = 0; unsigned Characteristics = getCOFFSectionFlags(Kind, TM); - StringRef Name = GV->getSection(); + StringRef Name = GO->getSection(); StringRef COMDATSymName = ""; - if (GV->hasComdat()) { - Selection = getSelectionForCOFF(GV); + if (GO->hasComdat()) { + Selection = getSelectionForCOFF(GO); const GlobalValue *ComdatGV; if (Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) - ComdatGV = getComdatGVForCOFF(GV); + ComdatGV = getComdatGVForCOFF(GO); else - ComdatGV = GV; + ComdatGV = GO; if (!ComdatGV->hasPrivateLinkage()) { MCSymbol *Sym = TM.getSymbol(ComdatGV, getMangler()); @@ -951,7 +954,7 @@ } MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { // If we have -ffunction-sections then we should emit the global value to a // uniqued section specifically for it. bool EmitUniquedSection; @@ -960,19 +963,19 @@ else EmitUniquedSection = TM.getDataSections(); - if ((EmitUniquedSection && !Kind.isCommon()) || GV->hasComdat()) { + if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) { const char *Name = getCOFFSectionNameForUniqueGlobal(Kind); unsigned Characteristics = getCOFFSectionFlags(Kind, TM); Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; - int Selection = getSelectionForCOFF(GV); + int Selection = getSelectionForCOFF(GO); if (!Selection) Selection = COFF::IMAGE_COMDAT_SELECT_NODUPLICATES; const GlobalValue *ComdatGV; - if (GV->hasComdat()) - ComdatGV = getComdatGVForCOFF(GV); + if (GO->hasComdat()) + ComdatGV = getComdatGVForCOFF(GO); else - ComdatGV = GV; + ComdatGV = GO; unsigned UniqueID = MCContext::GenericSectionID; if (EmitUniquedSection) @@ -985,7 +988,7 @@ COMDATSymName, Selection, UniqueID); } else { SmallString<256> TmpData; - getMangler().getNameWithPrefix(TmpData, GV, /*CannotUsePrivateLabel=*/true); + getMangler().getNameWithPrefix(TmpData, GO, /*CannotUsePrivateLabel=*/true); return getContext().getCOFFSection(Name, Characteristics, Kind, TmpData, Selection, UniqueID); } Index: llvm/lib/IR/Globals.cpp =================================================================== --- llvm/lib/IR/Globals.cpp +++ llvm/lib/IR/Globals.cpp @@ -213,6 +213,14 @@ return true; } +GlobalObject *GlobalValue::getBaseObject() { + if (auto *GO = dyn_cast(this)) + return GO; + if (auto *GA = dyn_cast(this)) + return GA->getBaseObject(); + return nullptr; +} + //===----------------------------------------------------------------------===// // GlobalVariable Implementation //===----------------------------------------------------------------------===// Index: llvm/lib/Target/AMDGPU/AMDGPUTargetObjectFile.h =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetObjectFile.h +++ llvm/lib/Target/AMDGPU/AMDGPUTargetObjectFile.h @@ -23,7 +23,7 @@ class AMDGPUTargetObjectFile : public TargetLoweringObjectFileELF { public: - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; }; Index: llvm/lib/Target/AMDGPU/AMDGPUTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetObjectFile.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUTargetObjectFile.cpp @@ -21,10 +21,10 @@ //===----------------------------------------------------------------------===// MCSection *AMDGPUTargetObjectFile::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { - if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GV) && + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { + if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GO) && AMDGPU::shouldEmitConstantsToTextSection(TM.getTargetTriple())) return TextSection; - return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM); + return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM); } Index: llvm/lib/Target/AVR/AVRTargetObjectFile.h =================================================================== --- llvm/lib/Target/AVR/AVRTargetObjectFile.h +++ llvm/lib/Target/AVR/AVRTargetObjectFile.h @@ -21,7 +21,7 @@ public: void Initialize(MCContext &ctx, const TargetMachine &TM) override; - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; private: Index: llvm/lib/Target/AVR/AVRTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/AVR/AVRTargetObjectFile.cpp +++ llvm/lib/Target/AVR/AVRTargetObjectFile.cpp @@ -26,16 +26,16 @@ } MCSection * -AVRTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV, +AVRTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { // Global values in flash memory are placed in the progmem.data section // unless they already have a user assigned section. - if (AVR::isProgramMemoryAddress(GV) && !GV->hasSection()) + if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection()) return ProgmemDataSection; // Otherwise, we work the same way as ELF. - return Base::SelectSectionForGlobal(GV, Kind, TM); + return Base::SelectSectionForGlobal(GO, Kind, TM); } } // end of namespace llvm Index: llvm/lib/Target/Hexagon/HexagonISelLowering.cpp =================================================================== --- llvm/lib/Target/Hexagon/HexagonISelLowering.cpp +++ llvm/lib/Target/Hexagon/HexagonISelLowering.cpp @@ -1507,7 +1507,8 @@ if (RM == Reloc::Static) { SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset); - if (HLOF.isGlobalInSmallSection(GV, HTM)) + const GlobalObject *GO = GV->getBaseObject(); + if (GO && HLOF.isGlobalInSmallSection(GO, HTM)) return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, GA); return DAG.getNode(HexagonISD::CONST32, dl, PtrVT, GA); } Index: llvm/lib/Target/Hexagon/HexagonTargetObjectFile.h =================================================================== --- llvm/lib/Target/Hexagon/HexagonTargetObjectFile.h +++ llvm/lib/Target/Hexagon/HexagonTargetObjectFile.h @@ -19,14 +19,15 @@ public: void Initialize(MCContext &Ctx, const TargetMachine &TM) override; - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; - MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *getExplicitSectionGlobal(const GlobalObject *GO, + SectionKind Kind, const TargetMachine &TM) const override; - bool isGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM) - const; + bool isGlobalInSmallSection(const GlobalObject *GO, + const TargetMachine &TM) const; bool isSmallDataEnabled() const; @@ -39,7 +40,7 @@ unsigned getSmallestAddressableSize(const Type *Ty, const GlobalValue *GV, const TargetMachine &TM) const; - MCSection *selectSmallSectionForGlobal(const GlobalValue *GV, + MCSection *selectSmallSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const; }; Index: llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp +++ llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp @@ -101,22 +101,22 @@ } MCSection *HexagonTargetObjectFile::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { - TRACE("[SelectSectionForGlobal] GV(" << GV->getName() << ") "); - TRACE("input section(" << GV->getSection() << ") "); - - TRACE((GV->hasPrivateLinkage() ? "private_linkage " : "") - << (GV->hasLocalLinkage() ? "local_linkage " : "") - << (GV->hasInternalLinkage() ? "internal " : "") - << (GV->hasExternalLinkage() ? "external " : "") - << (GV->hasCommonLinkage() ? "common_linkage " : "") - << (GV->hasCommonLinkage() ? "common " : "" ) + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { + TRACE("[SelectSectionForGlobal] GO(" << GO->getName() << ") "); + TRACE("input section(" << GO->getSection() << ") "); + + TRACE((GO->hasPrivateLinkage() ? "private_linkage " : "") + << (GO->hasLocalLinkage() ? "local_linkage " : "") + << (GO->hasInternalLinkage() ? "internal " : "") + << (GO->hasExternalLinkage() ? "external " : "") + << (GO->hasCommonLinkage() ? "common_linkage " : "") + << (GO->hasCommonLinkage() ? "common " : "" ) << (Kind.isCommon() ? "kind_common " : "" ) << (Kind.isBSS() ? "kind_bss " : "" ) << (Kind.isBSSLocal() ? "kind_bss_local " : "" )); - if (isGlobalInSmallSection(GV, TM)) - return selectSmallSectionForGlobal(GV, Kind, TM); + if (isGlobalInSmallSection(GO, TM)) + return selectSmallSectionForGlobal(GO, Kind, TM); if (Kind.isCommon()) { // This is purely for LTO+Linker Script because commons don't really have a @@ -128,50 +128,50 @@ TRACE("default_ELF_section\n"); // Otherwise, we work the same as ELF. - return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM); + return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM); } MCSection *HexagonTargetObjectFile::getExplicitSectionGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { - TRACE("[getExplicitSectionGlobal] GV(" << GV->getName() << ") from(" - << GV->getSection() << ") "); - TRACE((GV->hasPrivateLinkage() ? "private_linkage " : "") - << (GV->hasLocalLinkage() ? "local_linkage " : "") - << (GV->hasInternalLinkage() ? "internal " : "") - << (GV->hasExternalLinkage() ? "external " : "") - << (GV->hasCommonLinkage() ? "common_linkage " : "") - << (GV->hasCommonLinkage() ? "common " : "" ) + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { + TRACE("[getExplicitSectionGlobal] GO(" << GO->getName() << ") from(" + << GO->getSection() << ") "); + TRACE((GO->hasPrivateLinkage() ? "private_linkage " : "") + << (GO->hasLocalLinkage() ? "local_linkage " : "") + << (GO->hasInternalLinkage() ? "internal " : "") + << (GO->hasExternalLinkage() ? "external " : "") + << (GO->hasCommonLinkage() ? "common_linkage " : "") + << (GO->hasCommonLinkage() ? "common " : "" ) << (Kind.isCommon() ? "kind_common " : "" ) << (Kind.isBSS() ? "kind_bss " : "" ) << (Kind.isBSSLocal() ? "kind_bss_local " : "" )); - if (GV->hasSection()) { - StringRef Section = GV->getSection(); + if (GO->hasSection()) { + StringRef Section = GO->getSection(); if (Section.find(".access.text.group") != StringRef::npos) - return getContext().getELFSection(GV->getSection(), ELF::SHT_PROGBITS, + return getContext().getELFSection(GO->getSection(), ELF::SHT_PROGBITS, ELF::SHF_ALLOC | ELF::SHF_EXECINSTR); if (Section.find(".access.data.group") != StringRef::npos) - return getContext().getELFSection(GV->getSection(), ELF::SHT_PROGBITS, + return getContext().getELFSection(GO->getSection(), ELF::SHT_PROGBITS, ELF::SHF_WRITE | ELF::SHF_ALLOC); } - if (isGlobalInSmallSection(GV, TM)) - return selectSmallSectionForGlobal(GV, Kind, TM); + if (isGlobalInSmallSection(GO, TM)) + return selectSmallSectionForGlobal(GO, Kind, TM); // Otherwise, we work the same as ELF. TRACE("default_ELF_section\n"); - return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GV, Kind, TM); + return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, Kind, TM); } /// Return true if this global value should be placed into small data/bss /// section. -bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalValue *GV, +bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM) const { // Only global variables, not functions. DEBUG(dbgs() << "Checking if value is in small-data, -G" - << SmallDataThreshold << ": \"" << GV->getName() << "\": "); - const GlobalVariable *GVar = dyn_cast(GV); + << SmallDataThreshold << ": \"" << GO->getName() << "\": "); + const GlobalVariable *GVar = dyn_cast(GO); if (!GVar) { DEBUG(dbgs() << "no, not a global variable\n"); return false; @@ -297,9 +297,9 @@ } MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { - const Type *GTy = GV->getType()->getElementType(); - unsigned Size = getSmallestAddressableSize(GTy, GV, TM); + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { + const Type *GTy = GO->getType()->getElementType(); + unsigned Size = getSmallestAddressableSize(GTy, GO, TM); // If we have -ffunction-section or -fdata-section then we should emit the // global value to a unique section specifically for it... even for sdata. @@ -325,7 +325,7 @@ if (EmitUniquedSection) { Name.append("."); - Name.append(GV->getName()); + Name.append(GO->getName()); } TRACE(" unique sbss(" << Name << ")\n"); return getContext().getELFSection(Name.str(), ELF::SHT_NOBITS, @@ -352,7 +352,7 @@ // case the Kind could be wrong for it. if (Kind.isMergeableConst()) { TRACE(" const_object_as_data "); - const GlobalVariable *GVar = dyn_cast(GV); + const GlobalVariable *GVar = dyn_cast(GO); if (GVar->hasSection() && isSmallDataSection(GVar->getSection())) Kind = SectionKind::getData(); } @@ -369,7 +369,7 @@ if (EmitUniquedSection) { Name.append("."); - Name.append(GV->getName()); + Name.append(GO->getName()); } TRACE(" unique sdata(" << Name << ")\n"); return getContext().getELFSection(Name.str(), ELF::SHT_PROGBITS, @@ -378,5 +378,5 @@ TRACE("default ELF section\n"); // Otherwise, we work the same as ELF. - return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM); + return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM); } Index: llvm/lib/Target/Lanai/LanaiISelLowering.cpp =================================================================== --- llvm/lib/Target/Lanai/LanaiISelLowering.cpp +++ llvm/lib/Target/Lanai/LanaiISelLowering.cpp @@ -1167,8 +1167,9 @@ // If the code model is small or global variable will be placed in the small // section, then assume address will fit in 21-bits. + const GlobalObject *GO = GV->getBaseObject(); if (getTargetMachine().getCodeModel() == CodeModel::Small || - TLOF->isGlobalInSmallSection(GV, getTargetMachine())) { + (GO && TLOF->isGlobalInSmallSection(GO, getTargetMachine()))) { SDValue Small = DAG.getTargetGlobalAddress( GV, DL, getPointerTy(DAG.getDataLayout()), Offset, LanaiII::MO_NO_FLAG); return DAG.getNode(ISD::OR, DL, MVT::i32, Index: llvm/lib/Target/Lanai/LanaiTargetObjectFile.h =================================================================== --- llvm/lib/Target/Lanai/LanaiTargetObjectFile.h +++ llvm/lib/Target/Lanai/LanaiTargetObjectFile.h @@ -18,19 +18,20 @@ MCSection *SmallDataSection; MCSection *SmallBSSSection; + bool isGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM, + SectionKind Kind) const; + bool isGlobalInSmallSectionImpl(const GlobalObject *GO, + const TargetMachine &TM) const; + public: void Initialize(MCContext &Ctx, const TargetMachine &TM) override; /// Return true if this global address should be placed into small data/bss /// section. - bool isGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM, - SectionKind Kind) const; - bool isGlobalInSmallSection(const GlobalValue *GV, + bool isGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM) const; - bool isGlobalInSmallSectionImpl(const GlobalValue *GV, - const TargetMachine &TM) const; - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; /// Return true if this constant should be placed into small data section. Index: llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp +++ llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp @@ -49,22 +49,22 @@ // Return true if this global address should be placed into small data/bss // section. bool LanaiTargetObjectFile::isGlobalInSmallSection( - const GlobalValue *GV, const TargetMachine &TM) const { + const GlobalObject *GO, const TargetMachine &TM) const { // We first check the case where global is a declaration, because finding // section kind using getKindForGlobal() is only allowed for global // definitions. - if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage()) - return isGlobalInSmallSectionImpl(GV, TM); + if (GO->isDeclaration() || GO->hasAvailableExternallyLinkage()) + return isGlobalInSmallSectionImpl(GO, TM); - return isGlobalInSmallSection(GV, TM, getKindForGlobal(GV, TM)); + return isGlobalInSmallSection(GO, TM, getKindForGlobal(GO, TM)); } // Return true if this global address should be placed into small data/bss // section. -bool LanaiTargetObjectFile::isGlobalInSmallSection(const GlobalValue *GV, +bool LanaiTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM, SectionKind Kind) const { - return (isGlobalInSmallSectionImpl(GV, TM) && + return (isGlobalInSmallSectionImpl(GO, TM) && (Kind.isData() || Kind.isBSS() || Kind.isCommon())); } @@ -72,34 +72,34 @@ // section. This method does all the work, except for checking the section // kind. bool LanaiTargetObjectFile::isGlobalInSmallSectionImpl( - const GlobalValue *GV, const TargetMachine & /*TM*/) const { + const GlobalObject *GO, const TargetMachine & /*TM*/) const { // Only global variables, not functions. - const GlobalVariable *GVA = dyn_cast(GV); + const auto *GVA = dyn_cast(GO); if (!GVA) return false; - if (GV->hasLocalLinkage()) + if (GVA->hasLocalLinkage()) return false; - if (((GV->hasExternalLinkage() && GV->isDeclaration()) || - GV->hasCommonLinkage())) + if (((GVA->hasExternalLinkage() && GVA->isDeclaration()) || + GVA->hasCommonLinkage())) return false; - Type *Ty = GV->getType()->getElementType(); + Type *Ty = GVA->getValueType(); return isInSmallSection( - GV->getParent()->getDataLayout().getTypeAllocSize(Ty)); + GVA->getParent()->getDataLayout().getTypeAllocSize(Ty)); } MCSection *LanaiTargetObjectFile::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { // Handle Small Section classification here. - if (Kind.isBSS() && isGlobalInSmallSection(GV, TM, Kind)) + if (Kind.isBSS() && isGlobalInSmallSection(GO, TM, Kind)) return SmallBSSSection; - if (Kind.isData() && isGlobalInSmallSection(GV, TM, Kind)) + if (Kind.isData() && isGlobalInSmallSection(GO, TM, Kind)) return SmallDataSection; // Otherwise, we work the same as ELF. - return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM); + return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM); } /// Return true if this constant should be placed into small data section. Index: llvm/lib/Target/Mips/MipsISelLowering.cpp =================================================================== --- llvm/lib/Target/Mips/MipsISelLowering.cpp +++ llvm/lib/Target/Mips/MipsISelLowering.cpp @@ -1772,7 +1772,8 @@ const MipsTargetObjectFile *TLOF = static_cast( getTargetMachine().getObjFileLowering()); - if (TLOF->IsGlobalInSmallSection(GV, getTargetMachine())) + const GlobalObject *GO = GV->getBaseObject(); + if (GO && TLOF->IsGlobalInSmallSection(GO, getTargetMachine())) // %gp_rel relocation return getAddrGPRel(N, SDLoc(N), Ty, DAG); Index: llvm/lib/Target/Mips/MipsTargetObjectFile.h =================================================================== --- llvm/lib/Target/Mips/MipsTargetObjectFile.h +++ llvm/lib/Target/Mips/MipsTargetObjectFile.h @@ -18,20 +18,21 @@ MCSection *SmallDataSection; MCSection *SmallBSSSection; const MipsTargetMachine *TM; + + bool IsGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM, + SectionKind Kind) const; + bool IsGlobalInSmallSectionImpl(const GlobalObject *GO, + const TargetMachine &TM) const; public: void Initialize(MCContext &Ctx, const TargetMachine &TM) override; /// Return true if this global address should be placed into small data/bss /// section. - bool IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM, - SectionKind Kind) const; - bool IsGlobalInSmallSection(const GlobalValue *GV, + bool IsGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM) const; - bool IsGlobalInSmallSectionImpl(const GlobalValue *GV, - const TargetMachine &TM) const; - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; /// Return true if this constant should be placed into small data section. Index: llvm/lib/Target/Mips/MipsTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/Mips/MipsTargetObjectFile.cpp +++ llvm/lib/Target/Mips/MipsTargetObjectFile.cpp @@ -61,23 +61,23 @@ /// Return true if this global address should be placed into small data/bss /// section. -bool MipsTargetObjectFile:: -IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM) const { +bool MipsTargetObjectFile::IsGlobalInSmallSection( + const GlobalObject *GO, const TargetMachine &TM) const { // We first check the case where global is a declaration, because finding // section kind using getKindForGlobal() is only allowed for global // definitions. - if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage()) - return IsGlobalInSmallSectionImpl(GV, TM); + if (GO->isDeclaration() || GO->hasAvailableExternallyLinkage()) + return IsGlobalInSmallSectionImpl(GO, TM); - return IsGlobalInSmallSection(GV, TM, getKindForGlobal(GV, TM)); + return IsGlobalInSmallSection(GO, TM, getKindForGlobal(GO, TM)); } /// Return true if this global address should be placed into small data/bss /// section. bool MipsTargetObjectFile:: -IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM, +IsGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM, SectionKind Kind) const { - return (IsGlobalInSmallSectionImpl(GV, TM) && + return (IsGlobalInSmallSectionImpl(GO, TM) && (Kind.isData() || Kind.isBSS() || Kind.isCommon())); } @@ -85,7 +85,7 @@ /// section. This method does all the work, except for checking the section /// kind. bool MipsTargetObjectFile:: -IsGlobalInSmallSectionImpl(const GlobalValue *GV, +IsGlobalInSmallSectionImpl(const GlobalObject *GO, const TargetMachine &TM) const { const MipsSubtarget &Subtarget = *static_cast(TM).getSubtargetImpl(); @@ -95,37 +95,37 @@ return false; // Only global variables, not functions. - const GlobalVariable *GVA = dyn_cast(GV); + const GlobalVariable *GVA = dyn_cast(GO); if (!GVA) return false; // Enforce -mlocal-sdata. - if (!LocalSData && GV->hasLocalLinkage()) + if (!LocalSData && GVA->hasLocalLinkage()) return false; // Enforce -mextern-sdata. - if (!ExternSData && ((GV->hasExternalLinkage() && GV->isDeclaration()) || - GV->hasCommonLinkage())) + if (!ExternSData && ((GVA->hasExternalLinkage() && GVA->isDeclaration()) || + GVA->hasCommonLinkage())) return false; - Type *Ty = GV->getValueType(); + Type *Ty = GVA->getValueType(); return IsInSmallSection( - GV->getParent()->getDataLayout().getTypeAllocSize(Ty)); + GVA->getParent()->getDataLayout().getTypeAllocSize(Ty)); } MCSection *MipsTargetObjectFile::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { // TODO: Could also support "weak" symbols as well with ".gnu.linkonce.s.*" // sections? // Handle Small Section classification here. - if (Kind.isBSS() && IsGlobalInSmallSection(GV, TM, Kind)) + if (Kind.isBSS() && IsGlobalInSmallSection(GO, TM, Kind)) return SmallBSSSection; - if (Kind.isData() && IsGlobalInSmallSection(GV, TM, Kind)) + if (Kind.isData() && IsGlobalInSmallSection(GO, TM, Kind)) return SmallDataSection; // Otherwise, we work the same as ELF. - return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM); + return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM); } /// Return true if this constant should be placed into small data section. Index: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp =================================================================== --- llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -4598,6 +4598,6 @@ } MCSection *NVPTXTargetObjectFile::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { return getDataSection(); } Index: llvm/lib/Target/NVPTX/NVPTXTargetObjectFile.h =================================================================== --- llvm/lib/Target/NVPTX/NVPTXTargetObjectFile.h +++ llvm/lib/Target/NVPTX/NVPTXTargetObjectFile.h @@ -91,12 +91,12 @@ return ReadOnlySection; } - MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override { return DataSection; } - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; }; Index: llvm/lib/Target/PowerPC/PPCTargetObjectFile.h =================================================================== --- llvm/lib/Target/PowerPC/PPCTargetObjectFile.h +++ llvm/lib/Target/PowerPC/PPCTargetObjectFile.h @@ -22,7 +22,7 @@ void Initialize(MCContext &Ctx, const TargetMachine &TM) override; - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; /// \brief Describe a TLS variable address within debug info. Index: llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp +++ llvm/lib/Target/PowerPC/PPCTargetObjectFile.cpp @@ -23,7 +23,7 @@ } MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { // Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI // when we have a constant that contains global relocations. This is // necessary because of this ABI's handling of pointers to functions in @@ -39,13 +39,13 @@ // For more information, see the description of ELIMINATE_COPY_RELOCS in // GNU ld. if (Kind.isReadOnly()) { - const GlobalVariable *GVar = dyn_cast(GV); + const auto *GVar = dyn_cast(GO); if (GVar && GVar->isConstant() && GVar->getInitializer()->needsRelocation()) Kind = SectionKind::getReadOnlyWithRel(); } - return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM); + return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM); } const MCExpr *PPC64LinuxTargetObjectFile:: Index: llvm/lib/Target/TargetLoweringObjectFile.cpp =================================================================== --- llvm/lib/Target/TargetLoweringObjectFile.cpp +++ llvm/lib/Target/TargetLoweringObjectFile.cpp @@ -132,15 +132,15 @@ /// classifies the global in a variety of ways that make various target /// implementations simpler. The target implementation is free to ignore this /// extra info of course. -SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV, +SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO, const TargetMachine &TM){ - assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() && + assert(!GO->isDeclaration() && !GO->hasAvailableExternallyLinkage() && "Can only be used for global definitions"); Reloc::Model ReloModel = TM.getRelocationModel(); // Early exit - functions should be always in text sections. - const GlobalVariable *GVar = dyn_cast(GV); + const auto *GVar = dyn_cast(GO); if (!GVar) return SectionKind::getText(); @@ -201,7 +201,8 @@ // Otherwise, just drop it into a mergable constant section. If we have // a section for this size, use it, otherwise use the arbitrary sized // mergable section. - switch (GV->getParent()->getDataLayout().getTypeAllocSize(C->getType())) { + switch ( + GVar->getParent()->getDataLayout().getTypeAllocSize(C->getType())) { case 4: return SectionKind::getMergeableConst4(); case 8: return SectionKind::getMergeableConst8(); case 16: return SectionKind::getMergeableConst16(); @@ -234,13 +235,13 @@ /// variable or function definition. This should not be passed external (or /// available externally) globals. MCSection *TargetLoweringObjectFile::SectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { // Select section name. - if (GV->hasSection()) - return getExplicitSectionGlobal(GV, Kind, TM); + if (GO->hasSection()) + return getExplicitSectionGlobal(GO, Kind, TM); // Use default section depending on the 'type' of global - return SelectSectionForGlobal(GV, Kind, TM); + return SelectSectionForGlobal(GO, Kind, TM); } MCSection *TargetLoweringObjectFile::getSectionForJumpTable( Index: llvm/lib/Target/XCore/XCoreTargetObjectFile.h =================================================================== --- llvm/lib/Target/XCore/XCoreTargetObjectFile.h +++ llvm/lib/Target/XCore/XCoreTargetObjectFile.h @@ -25,10 +25,10 @@ public: void Initialize(MCContext &Ctx, const TargetMachine &TM) override; - MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; - MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, + MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, Index: llvm/lib/Target/XCore/XCoreTargetObjectFile.cpp =================================================================== --- llvm/lib/Target/XCore/XCoreTargetObjectFile.cpp +++ llvm/lib/Target/XCore/XCoreTargetObjectFile.cpp @@ -96,8 +96,8 @@ } MCSection *XCoreTargetObjectFile::getExplicitSectionGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { - StringRef SectionName = GV->getSection(); + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { + StringRef SectionName = GO->getSection(); // Infer section flags from the section name if we can. bool IsCPRel = SectionName.startswith(".cp."); if (IsCPRel && !Kind.isReadOnly()) @@ -107,9 +107,9 @@ } MCSection *XCoreTargetObjectFile::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const { + const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { - bool UseCPRel = GV->isLocalLinkage(GV->getLinkage()); + bool UseCPRel = GO->hasLocalLinkage(); if (Kind.isText()) return TextSection; if (UseCPRel) { @@ -118,8 +118,8 @@ if (Kind.isMergeableConst8()) return MergeableConst8Section; if (Kind.isMergeableConst16()) return MergeableConst16Section; } - Type *ObjType = GV->getValueType(); - auto &DL = GV->getParent()->getDataLayout(); + Type *ObjType = GO->getValueType(); + auto &DL = GO->getParent()->getDataLayout(); if (TM.getCodeModel() == CodeModel::Small || !ObjType->isSized() || DL.getTypeAllocSize(ObjType) < CodeModelLargeSize) { if (Kind.isReadOnly()) return UseCPRel? ReadOnlySection