diff options
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 676a465..92ffbec 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -2055,11 +2055,10 @@ MCSection *TargetLoweringObjectFileWasm::getStaticDtorSection( MCSymbol * TargetLoweringObjectFileXCOFF::getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const { - if (TM.getDataSections()) - report_fatal_error("XCOFF unique data sections not yet implemented"); - // We always use a qualname symbol for a GV that represents // a declaration, a function descriptor, or a common symbol. + // If a GV represents a GlobalVariable and -fdata-sections is enabled, we + // also return a qualname so that a label symbol could be avoided. // It is inherently ambiguous when the GO represents the address of a // function, as the GO could either represent a function descriptor or a // function entry point. We choose to always return a function descriptor @@ -2074,15 +2073,12 @@ TargetLoweringObjectFileXCOFF::getTargetSymbol(const GlobalValue *GV, return cast<MCSectionXCOFF>( getSectionForFunctionDescriptor(cast<Function>(GO), TM)) ->getQualNameSymbol(); - if (GOKind.isCommon() || GOKind.isBSSLocal()) + if (TM.getDataSections() || GOKind.isCommon() || GOKind.isBSSLocal()) return cast<MCSectionXCOFF>(SectionForGlobal(GO, GOKind, TM)) ->getQualNameSymbol(); } // For all other cases, fall back to getSymbol to return the unqualified name. - // This could change for a GV that is a GlobalVariable when we decide to - // support -fdata-sections since we could avoid having label symbols if the - // linkage name is applied to the csect symbol. return nullptr; } @@ -2107,9 +2103,6 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForExternalReference( MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal( const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { - assert(!TM.getDataSections() && - "XCOFF unique data sections not yet implemented."); - // Common symbols go into a csect with matching name which will get mapped // into the .bss section. if (Kind.isBSSLocal() || Kind.isCommon()) { @@ -2129,6 +2122,9 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal( SmallString<128> Name; Name = SizeSpec + utostr(Alignment.value()); + if (TM.getDataSections()) + getNameWithPrefix(Name, GO, TM); + return getContext().getXCOFFSection(Name, XCOFF::XMC_RO, XCOFF::XTY_SD, Kind, /*BeginSymbolName*/ nullptr); } @@ -2141,20 +2137,32 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal( return TextSection; } - if (Kind.isData() || Kind.isReadOnlyWithRel()) - // TODO: We may put this under option control, because user may want to - // have read-only data with relocations placed into a read-only section by - // the compiler. - return DataSection; - - // Zero initialized data must be emitted to the .data section because external - // linkage control sections that get mapped to the .bss section will be linked - // as tentative defintions, which is only appropriate for SectionKind::Common. - if (Kind.isBSS()) + // TODO: We may put Kind.isReadOnlyWithRel() under option control, because + // user may want to have read-only data with relocations placed into a + // read-only section by the compiler. + // For BSS kind, zero initialized data must be emitted to the .data section + // because external linkage control sections that get mapped to the .bss + // section will be linked as tentative defintions, which is only appropriate + // for SectionKind::Common. + if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS()) { + if (TM.getDataSections()) { + SmallString<128> Name; + getNameWithPrefix(Name, GO, TM); + return getContext().getXCOFFSection(Name, XCOFF::XMC_RW, XCOFF::XTY_SD, + SectionKind::getData()); + } return DataSection; + } - if (Kind.isReadOnly()) + if (Kind.isReadOnly()) { + if (TM.getDataSections()) { + SmallString<128> Name; + getNameWithPrefix(Name, GO, TM); + return getContext().getXCOFFSection(Name, XCOFF::XMC_RO, XCOFF::XTY_SD, + SectionKind::getReadOnly()); + } return ReadOnlySection; + } report_fatal_error("XCOFF other section types not yet implemented."); } |