2009-07-28 03:13:23 +00:00
|
|
|
//===-- XCoreTargetObjectFile.cpp - XCore object files --------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "XCoreTargetObjectFile.h"
|
2009-07-31 18:48:30 +00:00
|
|
|
#include "XCoreSubtarget.h"
|
2013-12-02 10:18:31 +00:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2010-04-08 21:26:26 +00:00
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
2011-01-23 04:28:49 +00:00
|
|
|
#include "llvm/Support/ELF.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2013-12-02 10:18:31 +00:00
|
|
|
|
2009-07-28 03:13:23 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
|
2009-07-31 18:48:30 +00:00
|
|
|
void XCoreTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
|
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
|
2013-12-02 10:18:31 +00:00
|
|
|
BSSSection =
|
|
|
|
Ctx.getELFSection(".dp.bss", ELF::SHT_NOBITS,
|
|
|
|
ELF::SHF_ALLOC | ELF::SHF_WRITE |
|
|
|
|
ELF::XCORE_SHF_DP_SECTION,
|
|
|
|
SectionKind::getBSS());
|
|
|
|
BSSSectionLarge =
|
|
|
|
Ctx.getELFSection(".dp.bss.large", ELF::SHT_NOBITS,
|
|
|
|
ELF::SHF_ALLOC | ELF::SHF_WRITE |
|
|
|
|
ELF::XCORE_SHF_DP_SECTION,
|
|
|
|
SectionKind::getBSS());
|
2009-08-15 06:09:35 +00:00
|
|
|
DataSection =
|
2013-12-02 10:18:31 +00:00
|
|
|
Ctx.getELFSection(".dp.data", ELF::SHT_PROGBITS,
|
2011-01-23 04:43:11 +00:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_WRITE |
|
|
|
|
ELF::XCORE_SHF_DP_SECTION,
|
2010-11-11 03:40:25 +00:00
|
|
|
SectionKind::getDataRel());
|
2013-12-02 10:18:31 +00:00
|
|
|
DataSectionLarge =
|
|
|
|
Ctx.getELFSection(".dp.data.large", ELF::SHT_PROGBITS,
|
2011-01-23 04:43:11 +00:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_WRITE |
|
|
|
|
ELF::XCORE_SHF_DP_SECTION,
|
2013-12-02 10:18:31 +00:00
|
|
|
SectionKind::getDataRel());
|
2014-02-11 10:36:26 +00:00
|
|
|
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());
|
2013-12-02 10:18:31 +00:00
|
|
|
ReadOnlySection =
|
|
|
|
Ctx.getELFSection(".cp.rodata", ELF::SHT_PROGBITS,
|
|
|
|
ELF::SHF_ALLOC |
|
|
|
|
ELF::XCORE_SHF_CP_SECTION,
|
|
|
|
SectionKind::getReadOnlyWithRel());
|
|
|
|
ReadOnlySectionLarge =
|
|
|
|
Ctx.getELFSection(".cp.rodata.large", ELF::SHT_PROGBITS,
|
|
|
|
ELF::SHF_ALLOC |
|
|
|
|
ELF::XCORE_SHF_CP_SECTION,
|
|
|
|
SectionKind::getReadOnlyWithRel());
|
2009-08-18 21:14:31 +00:00
|
|
|
MergeableConst4Section =
|
2011-01-23 04:28:49 +00:00
|
|
|
Ctx.getELFSection(".cp.rodata.cst4", ELF::SHT_PROGBITS,
|
2011-01-23 04:43:11 +00:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_MERGE |
|
|
|
|
ELF::XCORE_SHF_CP_SECTION,
|
2010-11-11 03:40:25 +00:00
|
|
|
SectionKind::getMergeableConst4());
|
2009-08-18 21:14:31 +00:00
|
|
|
MergeableConst8Section =
|
2011-01-23 04:28:49 +00:00
|
|
|
Ctx.getELFSection(".cp.rodata.cst8", ELF::SHT_PROGBITS,
|
2011-01-23 04:43:11 +00:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_MERGE |
|
|
|
|
ELF::XCORE_SHF_CP_SECTION,
|
2010-11-11 03:40:25 +00:00
|
|
|
SectionKind::getMergeableConst8());
|
2009-08-18 21:14:31 +00:00
|
|
|
MergeableConst16Section =
|
2011-01-23 04:28:49 +00:00
|
|
|
Ctx.getELFSection(".cp.rodata.cst16", ELF::SHT_PROGBITS,
|
2011-01-23 04:43:11 +00:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_MERGE |
|
|
|
|
ELF::XCORE_SHF_CP_SECTION,
|
2010-11-11 03:40:25 +00:00
|
|
|
SectionKind::getMergeableConst16());
|
2013-12-02 10:18:31 +00:00
|
|
|
CStringSection =
|
|
|
|
Ctx.getELFSection(".cp.rodata.string", ELF::SHT_PROGBITS,
|
|
|
|
ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS |
|
2011-01-23 04:43:11 +00:00
|
|
|
ELF::XCORE_SHF_CP_SECTION,
|
2010-11-11 03:40:25 +00:00
|
|
|
SectionKind::getReadOnlyWithRel());
|
2013-12-02 10:18:31 +00:00
|
|
|
// TextSection - see MObjectFileInfo.cpp
|
|
|
|
// StaticCtorSection - see MObjectFileInfo.cpp
|
|
|
|
// StaticDtorSection - see MObjectFileInfo.cpp
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getXCoreSectionType(SectionKind K) {
|
|
|
|
if (K.isBSS())
|
|
|
|
return ELF::SHT_NOBITS;
|
|
|
|
return ELF::SHT_PROGBITS;
|
|
|
|
}
|
|
|
|
|
2014-02-11 10:36:26 +00:00
|
|
|
static unsigned getXCoreSectionFlags(SectionKind K, bool IsCPRel) {
|
2013-12-02 10:18:31 +00:00
|
|
|
unsigned Flags = 0;
|
|
|
|
|
|
|
|
if (!K.isMetadata())
|
|
|
|
Flags |= ELF::SHF_ALLOC;
|
|
|
|
|
|
|
|
if (K.isText())
|
|
|
|
Flags |= ELF::SHF_EXECINSTR;
|
2014-02-11 10:36:26 +00:00
|
|
|
else if (IsCPRel)
|
2013-12-02 10:18:31 +00:00
|
|
|
Flags |= ELF::XCORE_SHF_CP_SECTION;
|
|
|
|
else
|
|
|
|
Flags |= ELF::XCORE_SHF_DP_SECTION;
|
|
|
|
|
|
|
|
if (K.isWriteable())
|
|
|
|
Flags |= ELF::SHF_WRITE;
|
|
|
|
|
|
|
|
if (K.isMergeableCString() || K.isMergeableConst4() ||
|
|
|
|
K.isMergeableConst8() || K.isMergeableConst16())
|
|
|
|
Flags |= ELF::SHF_MERGE;
|
|
|
|
|
|
|
|
if (K.isMergeableCString())
|
|
|
|
Flags |= ELF::SHF_STRINGS;
|
|
|
|
|
|
|
|
return Flags;
|
|
|
|
}
|
|
|
|
|
2014-02-19 17:23:20 +00:00
|
|
|
const MCSection *
|
|
|
|
XCoreTargetObjectFile::getExplicitSectionGlobal(const GlobalValue *GV,
|
|
|
|
SectionKind Kind, Mangler &Mang,
|
|
|
|
const TargetMachine &TM) const {
|
2013-12-02 10:18:31 +00:00
|
|
|
StringRef SectionName = GV->getSection();
|
|
|
|
// Infer section flags from the section name if we can.
|
2014-02-11 10:36:26 +00:00
|
|
|
bool IsCPRel = SectionName.startswith(".cp.");
|
|
|
|
if (IsCPRel && !Kind.isReadOnly())
|
|
|
|
report_fatal_error("Using .cp. section for writeable object.");
|
2013-12-02 10:18:31 +00:00
|
|
|
return getContext().getELFSection(SectionName, getXCoreSectionType(Kind),
|
2014-02-11 10:36:26 +00:00
|
|
|
getXCoreSectionFlags(Kind, IsCPRel), Kind);
|
2013-12-02 10:18:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const MCSection *XCoreTargetObjectFile::
|
2014-02-08 14:53:28 +00:00
|
|
|
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
|
2014-01-28 00:49:26 +00:00
|
|
|
const TargetMachine &TM) const{
|
2013-12-02 10:18:31 +00:00
|
|
|
|
2014-02-11 10:36:26 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-12-02 10:18:31 +00:00
|
|
|
Type *ObjType = GV->getType()->getPointerElementType();
|
|
|
|
if (TM.getCodeModel() == CodeModel::Small ||
|
|
|
|
!ObjType->isSized() ||
|
|
|
|
TM.getDataLayout()->getTypeAllocSize(ObjType) < CodeModelLargeSize) {
|
2014-02-11 10:36:26 +00:00
|
|
|
if (Kind.isReadOnly()) return UseCPRel? ReadOnlySection
|
|
|
|
: DataRelROSection;
|
2014-02-18 11:21:59 +00:00
|
|
|
if (Kind.isBSS() || Kind.isCommon())return BSSSection;
|
2014-02-11 10:36:26 +00:00
|
|
|
if (Kind.isDataRel()) return DataSection;
|
|
|
|
if (Kind.isReadOnlyWithRel()) return DataRelROSection;
|
2013-12-02 10:18:31 +00:00
|
|
|
} else {
|
2014-02-11 10:36:26 +00:00
|
|
|
if (Kind.isReadOnly()) return UseCPRel? ReadOnlySectionLarge
|
|
|
|
: DataRelROSectionLarge;
|
2014-02-18 11:21:59 +00:00
|
|
|
if (Kind.isBSS() || Kind.isCommon())return BSSSectionLarge;
|
2014-02-11 10:36:26 +00:00
|
|
|
if (Kind.isDataRel()) return DataSectionLarge;
|
|
|
|
if (Kind.isReadOnlyWithRel()) return DataRelROSectionLarge;
|
2013-12-02 10:18:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert((Kind.isThreadLocal() || Kind.isCommon()) && "Unknown section kind");
|
|
|
|
report_fatal_error("Target does not support TLS or Common sections");
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCSection *XCoreTargetObjectFile::
|
|
|
|
getSectionForConstant(SectionKind Kind) const {
|
|
|
|
if (Kind.isMergeableConst4()) return MergeableConst4Section;
|
|
|
|
if (Kind.isMergeableConst8()) return MergeableConst8Section;
|
|
|
|
if (Kind.isMergeableConst16()) return MergeableConst16Section;
|
|
|
|
assert((Kind.isReadOnly() || Kind.isReadOnlyWithRel()) &&
|
|
|
|
"Unknown section kind");
|
|
|
|
// We assume the size of the object is never greater than CodeModelLargeSize.
|
|
|
|
// To handle CodeModelLargeSize changes to AsmPrinter would be required.
|
|
|
|
return ReadOnlySection;
|
2009-08-01 19:09:44 +00:00
|
|
|
}
|