aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
authorjasonliu <jasonliu.development@gmail.com>2020-10-01 23:35:31 +0000
committerjasonliu <jasonliu.development@gmail.com>2020-10-02 00:16:24 +0000
commit78a9e62aa6f8f39fe8141e5486fca6db29947ecf (patch)
tree93dc966616afde1c719990a82cee9eccf0c19d96 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
parent61687f3a48c254436cbdd55e10bfb23b727f3eb5 (diff)
downloadllvm-78a9e62aa6f8f39fe8141e5486fca6db29947ecf.zip
llvm-78a9e62aa6f8f39fe8141e5486fca6db29947ecf.tar.gz
llvm-78a9e62aa6f8f39fe8141e5486fca6db29947ecf.tar.bz2
[XCOFF] Enable -fdata-sections on AIX
Summary: Some design decision worth noting about: I've noticed a recent mailing discussing about why string literal is not affected by -fdata-sections for ELF target: http://lists.llvm.org/pipermail/llvm-dev/2020-September/145121.html But on AIX, our linker could not split the mergeable string like other target. So I think it would make more sense for us to emit separate csect for every mergeable string in -fdata-sections mode, as there might not be other ways for linker to do garbage collection on unused mergeable string. Reviewed By: daltenty, hubert.reinterpretcast Differential Revision: https://reviews.llvm.org/D88339
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp50
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.");
}