2009-07-28 11:13:23 +08: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-08-01 02:48:30 +08:00
|
|
|
#include "XCoreSubtarget.h"
|
2013-12-02 18:18:31 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2010-04-09 05:26:26 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCSectionELF.h"
|
2011-01-23 12:28:49 +08:00
|
|
|
#include "llvm/Support/ELF.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2013-12-02 18:18:31 +08:00
|
|
|
|
2009-07-28 11:13:23 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
|
2009-08-01 02:48:30 +08:00
|
|
|
void XCoreTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM){
|
|
|
|
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
|
|
|
|
|
2013-12-02 18:18:31 +08: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 14:09:35 +08:00
|
|
|
DataSection =
|
2013-12-02 18:18:31 +08:00
|
|
|
Ctx.getELFSection(".dp.data", ELF::SHT_PROGBITS,
|
2011-01-23 12:43:11 +08:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_WRITE |
|
|
|
|
ELF::XCORE_SHF_DP_SECTION,
|
2010-11-11 11:40:25 +08:00
|
|
|
SectionKind::getDataRel());
|
2013-12-02 18:18:31 +08:00
|
|
|
DataSectionLarge =
|
|
|
|
Ctx.getELFSection(".dp.data.large", ELF::SHT_PROGBITS,
|
2011-01-23 12:43:11 +08:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_WRITE |
|
|
|
|
ELF::XCORE_SHF_DP_SECTION,
|
2013-12-02 18:18:31 +08:00
|
|
|
SectionKind::getDataRel());
|
2014-02-11 18:36:26 +08: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 18:18:31 +08: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-19 05:14:31 +08:00
|
|
|
MergeableConst4Section =
|
2011-01-23 12:28:49 +08:00
|
|
|
Ctx.getELFSection(".cp.rodata.cst4", ELF::SHT_PROGBITS,
|
2011-01-23 12:43:11 +08:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_MERGE |
|
|
|
|
ELF::XCORE_SHF_CP_SECTION,
|
2010-11-11 11:40:25 +08:00
|
|
|
SectionKind::getMergeableConst4());
|
2009-08-19 05:14:31 +08:00
|
|
|
MergeableConst8Section =
|
2011-01-23 12:28:49 +08:00
|
|
|
Ctx.getELFSection(".cp.rodata.cst8", ELF::SHT_PROGBITS,
|
2011-01-23 12:43:11 +08:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_MERGE |
|
|
|
|
ELF::XCORE_SHF_CP_SECTION,
|
2010-11-11 11:40:25 +08:00
|
|
|
SectionKind::getMergeableConst8());
|
2009-08-19 05:14:31 +08:00
|
|
|
MergeableConst16Section =
|
2011-01-23 12:28:49 +08:00
|
|
|
Ctx.getELFSection(".cp.rodata.cst16", ELF::SHT_PROGBITS,
|
2011-01-23 12:43:11 +08:00
|
|
|
ELF::SHF_ALLOC | ELF::SHF_MERGE |
|
|
|
|
ELF::XCORE_SHF_CP_SECTION,
|
2010-11-11 11:40:25 +08:00
|
|
|
SectionKind::getMergeableConst16());
|
2013-12-02 18:18:31 +08:00
|
|
|
CStringSection =
|
|
|
|
Ctx.getELFSection(".cp.rodata.string", ELF::SHT_PROGBITS,
|
|
|
|
ELF::SHF_ALLOC | ELF::SHF_MERGE | ELF::SHF_STRINGS |
|
2011-01-23 12:43:11 +08:00
|
|
|
ELF::XCORE_SHF_CP_SECTION,
|
2010-11-11 11:40:25 +08:00
|
|
|
SectionKind::getReadOnlyWithRel());
|
2013-12-02 18:18:31 +08: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 18:36:26 +08:00
|
|
|
static unsigned getXCoreSectionFlags(SectionKind K, bool IsCPRel) {
|
2013-12-02 18:18:31 +08:00
|
|
|
unsigned Flags = 0;
|
|
|
|
|
|
|
|
if (!K.isMetadata())
|
|
|
|
Flags |= ELF::SHF_ALLOC;
|
|
|
|
|
|
|
|
if (K.isText())
|
|
|
|
Flags |= ELF::SHF_EXECINSTR;
|
2014-02-11 18:36:26 +08:00
|
|
|
else if (IsCPRel)
|
2013-12-02 18:18:31 +08: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-20 01:23:20 +08:00
|
|
|
const MCSection *
|
|
|
|
XCoreTargetObjectFile::getExplicitSectionGlobal(const GlobalValue *GV,
|
|
|
|
SectionKind Kind, Mangler &Mang,
|
|
|
|
const TargetMachine &TM) const {
|
2013-12-02 18:18:31 +08:00
|
|
|
StringRef SectionName = GV->getSection();
|
|
|
|
// Infer section flags from the section name if we can.
|
2014-02-11 18:36:26 +08:00
|
|
|
bool IsCPRel = SectionName.startswith(".cp.");
|
|
|
|
if (IsCPRel && !Kind.isReadOnly())
|
|
|
|
report_fatal_error("Using .cp. section for writeable object.");
|
2013-12-02 18:18:31 +08:00
|
|
|
return getContext().getELFSection(SectionName, getXCoreSectionType(Kind),
|
2014-02-11 18:36:26 +08:00
|
|
|
getXCoreSectionFlags(Kind, IsCPRel), Kind);
|
2013-12-02 18:18:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const MCSection *XCoreTargetObjectFile::
|
2014-02-08 22:53:28 +08:00
|
|
|
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
|
2014-01-28 08:49:26 +08:00
|
|
|
const TargetMachine &TM) const{
|
2013-12-02 18:18:31 +08:00
|
|
|
|
2014-02-11 18:36:26 +08: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 18:18:31 +08:00
|
|
|
Type *ObjType = GV->getType()->getPointerElementType();
|
2014-08-05 05:25:23 +08:00
|
|
|
if (TM.getCodeModel() == CodeModel::Small || !ObjType->isSized() ||
|
|
|
|
TM.getSubtargetImpl()->getDataLayout()->getTypeAllocSize(ObjType) <
|
|
|
|
CodeModelLargeSize) {
|
2014-02-11 18:36:26 +08:00
|
|
|
if (Kind.isReadOnly()) return UseCPRel? ReadOnlySection
|
|
|
|
: DataRelROSection;
|
2014-02-18 19:21:59 +08:00
|
|
|
if (Kind.isBSS() || Kind.isCommon())return BSSSection;
|
2014-02-11 18:36:26 +08:00
|
|
|
if (Kind.isDataRel()) return DataSection;
|
|
|
|
if (Kind.isReadOnlyWithRel()) return DataRelROSection;
|
2013-12-02 18:18:31 +08:00
|
|
|
} else {
|
2014-02-11 18:36:26 +08:00
|
|
|
if (Kind.isReadOnly()) return UseCPRel? ReadOnlySectionLarge
|
|
|
|
: DataRelROSectionLarge;
|
2014-02-18 19:21:59 +08:00
|
|
|
if (Kind.isBSS() || Kind.isCommon())return BSSSectionLarge;
|
2014-02-11 18:36:26 +08:00
|
|
|
if (Kind.isDataRel()) return DataSectionLarge;
|
|
|
|
if (Kind.isReadOnlyWithRel()) return DataRelROSectionLarge;
|
2013-12-02 18:18:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
assert((Kind.isThreadLocal() || Kind.isCommon()) && "Unknown section kind");
|
|
|
|
report_fatal_error("Target does not support TLS or Common sections");
|
|
|
|
}
|
|
|
|
|
2014-07-15 06:57:27 +08:00
|
|
|
const MCSection *
|
|
|
|
XCoreTargetObjectFile::getSectionForConstant(SectionKind Kind,
|
|
|
|
const Constant *C) const {
|
2013-12-02 18:18:31 +08:00
|
|
|
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-02 03:09:44 +08:00
|
|
|
}
|