summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Lytton <robert@xmos.com>2014-02-11 10:36:26 +0000
committerRobert Lytton <robert@xmos.com>2014-02-11 10:36:26 +0000
commitd3abd0b648dd795dc481cc06169714738eb9bbdc (patch)
tree2f9810bcff0e274928ebc36fb8acfabdb7e2cc76 /lib
parent04a573a41f037eae148f70bf2038602f7e32dd71 (diff)
downloadllvm-d3abd0b648dd795dc481cc06169714738eb9bbdc.tar.gz
llvm-d3abd0b648dd795dc481cc06169714738eb9bbdc.tar.bz2
llvm-d3abd0b648dd795dc481cc06169714738eb9bbdc.tar.xz
XCore target: fix const section handling
Xcore target ABI requires const data that is externally visible to be handled differently if it has C-language linkage rather than C++ language linkage. Clang now emits ".cp.rodata" section information. All other externally visible constant data will be placed in the DP section. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201144 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Target/XCore/XCoreISelLowering.cpp5
-rw-r--r--lib/Target/XCore/XCoreTargetObjectFile.cpp62
-rw-r--r--lib/Target/XCore/XCoreTargetObjectFile.h1
3 files changed, 40 insertions, 28 deletions
diff --git a/lib/Target/XCore/XCoreISelLowering.cpp b/lib/Target/XCore/XCoreISelLowering.cpp
index 82ad0d069a..842531c455 100644
--- a/lib/Target/XCore/XCoreISelLowering.cpp
+++ b/lib/Target/XCore/XCoreISelLowering.cpp
@@ -275,7 +275,10 @@ getGlobalAddressWrapper(SDValue GA, const GlobalValue *GV,
if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
UnderlyingGV = GA->resolveAliasedGlobal();
if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(UnderlyingGV)) {
- if (GVar->isConstant())
+ if ( ( GVar->isConstant() &&
+ UnderlyingGV->isLocalLinkage(GV->getLinkage()) )
+ || ( GVar->hasSection() &&
+ StringRef(GVar->getSection()).startswith(".cp.") ) )
return DAG.getNode(XCoreISD::CPRelativeWrapper, dl, MVT::i32, GA);
return DAG.getNode(XCoreISD::DPRelativeWrapper, dl, MVT::i32, GA);
}
diff --git a/lib/Target/XCore/XCoreTargetObjectFile.cpp b/lib/Target/XCore/XCoreTargetObjectFile.cpp
index cf565e7a1e..33b719b34d 100644
--- a/lib/Target/XCore/XCoreTargetObjectFile.cpp
+++ b/lib/Target/XCore/XCoreTargetObjectFile.cpp
@@ -41,10 +41,16 @@ void XCoreTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
ELF::SHF_ALLOC | ELF::SHF_WRITE |
ELF::XCORE_SHF_DP_SECTION,
SectionKind::getDataRel());
- // This is the wrong place to decide if const data should be placed
- // in the .cp or .dp section.
- // Ideally we should set up DataRelROSection to use the '.dp.'' and use this
- // for const data, unless the front end explicitly states a '.cp.'' section.
+ DataRelROSection =
+ Ctx.getELFSection(".dp.rodata", ELF::SHT_PROGBITS,
+ ELF::SHF_ALLOC | ELF::SHF_WRITE |
+ ELF::XCORE_SHF_DP_SECTION,
+ SectionKind::getReadOnlyWithRel());
+ DataRelROSectionLarge =
+ Ctx.getELFSection(".dp.rodata.large", ELF::SHT_PROGBITS,
+ ELF::SHF_ALLOC | ELF::SHF_WRITE |
+ ELF::XCORE_SHF_DP_SECTION,
+ SectionKind::getReadOnlyWithRel());
ReadOnlySection =
Ctx.getELFSection(".cp.rodata", ELF::SHT_PROGBITS,
ELF::SHF_ALLOC |
@@ -80,19 +86,13 @@ void XCoreTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
// StaticDtorSection - see MObjectFileInfo.cpp
}
-static SectionKind getXCoreKindForNamedSection(StringRef Name, SectionKind K) {
- if (Name.startswith(".cp."))
- return SectionKind::getReadOnly();
- return K;
-}
-
static unsigned getXCoreSectionType(SectionKind K) {
if (K.isBSS())
return ELF::SHT_NOBITS;
return ELF::SHT_PROGBITS;
}
-static unsigned getXCoreSectionFlags(SectionKind K) {
+static unsigned getXCoreSectionFlags(SectionKind K, bool IsCPRel) {
unsigned Flags = 0;
if (!K.isMetadata())
@@ -100,7 +100,7 @@ static unsigned getXCoreSectionFlags(SectionKind K) {
if (K.isText())
Flags |= ELF::SHF_EXECINSTR;
- else if (K.isReadOnly())
+ else if (IsCPRel)
Flags |= ELF::XCORE_SHF_CP_SECTION;
else
Flags |= ELF::XCORE_SHF_DP_SECTION;
@@ -123,33 +123,41 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler &Mang, const TargetMachine &TM) const {
StringRef SectionName = GV->getSection();
// Infer section flags from the section name if we can.
- Kind = getXCoreKindForNamedSection(SectionName, Kind);
+ bool IsCPRel = SectionName.startswith(".cp.");
+ if (IsCPRel && !Kind.isReadOnly())
+ report_fatal_error("Using .cp. section for writeable object.");
return getContext().getELFSection(SectionName, getXCoreSectionType(Kind),
- getXCoreSectionFlags(Kind), Kind);
+ getXCoreSectionFlags(Kind, IsCPRel), Kind);
}
const MCSection *XCoreTargetObjectFile::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
const TargetMachine &TM) const{
- if (Kind.isText()) return TextSection;
- if (Kind.isMergeable1ByteCString()) return CStringSection;
- if (Kind.isMergeableConst4()) return MergeableConst4Section;
- if (Kind.isMergeableConst8()) return MergeableConst8Section;
- if (Kind.isMergeableConst16()) return MergeableConst16Section;
+ bool UseCPRel = GV->isLocalLinkage(GV->getLinkage());
+
+ if (Kind.isText()) return TextSection;
+ if (UseCPRel) {
+ if (Kind.isMergeable1ByteCString()) return CStringSection;
+ if (Kind.isMergeableConst4()) return MergeableConst4Section;
+ if (Kind.isMergeableConst8()) return MergeableConst8Section;
+ if (Kind.isMergeableConst16()) return MergeableConst16Section;
+ }
Type *ObjType = GV->getType()->getPointerElementType();
if (TM.getCodeModel() == CodeModel::Small ||
!ObjType->isSized() ||
TM.getDataLayout()->getTypeAllocSize(ObjType) < CodeModelLargeSize) {
- if (Kind.isReadOnly()) return ReadOnlySection;
- if (Kind.isBSS()) return BSSSection;
- if (Kind.isDataRel()) return DataSection;
- if (Kind.isReadOnlyWithRel()) return ReadOnlySection;
+ if (Kind.isReadOnly()) return UseCPRel? ReadOnlySection
+ : DataRelROSection;
+ if (Kind.isBSS()) return BSSSection;
+ if (Kind.isDataRel()) return DataSection;
+ if (Kind.isReadOnlyWithRel()) return DataRelROSection;
} else {
- if (Kind.isReadOnly()) return ReadOnlySectionLarge;
- if (Kind.isBSS()) return BSSSectionLarge;
- if (Kind.isDataRel()) return DataSectionLarge;
- if (Kind.isReadOnlyWithRel()) return ReadOnlySectionLarge;
+ if (Kind.isReadOnly()) return UseCPRel? ReadOnlySectionLarge
+ : DataRelROSectionLarge;
+ if (Kind.isBSS()) return BSSSectionLarge;
+ if (Kind.isDataRel()) return DataSectionLarge;
+ if (Kind.isReadOnlyWithRel()) return DataRelROSectionLarge;
}
assert((Kind.isThreadLocal() || Kind.isCommon()) && "Unknown section kind");
diff --git a/lib/Target/XCore/XCoreTargetObjectFile.h b/lib/Target/XCore/XCoreTargetObjectFile.h
index 47d7fad8ee..aa345043c0 100644
--- a/lib/Target/XCore/XCoreTargetObjectFile.h
+++ b/lib/Target/XCore/XCoreTargetObjectFile.h
@@ -20,6 +20,7 @@ static const unsigned CodeModelLargeSize = 256;
const MCSection *BSSSectionLarge;
const MCSection *DataSectionLarge;
const MCSection *ReadOnlySectionLarge;
+ const MCSection *DataRelROSectionLarge;
public:
void Initialize(MCContext &Ctx, const TargetMachine &TM);