forked from OSchip/llvm-project
Sink getSectionPrefixForUniqueGlobal down into the TAI
implementations that need it, rearrange ELFTAI. llvm-svn: 77236
This commit is contained in:
parent
067c407c48
commit
e7cb8f7987
|
@ -17,12 +17,12 @@ namespace llvm {
|
||||||
protected:
|
protected:
|
||||||
explicit COFFTargetAsmInfo(const TargetMachine &TM);
|
explicit COFFTargetAsmInfo(const TargetMachine &TM);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual const char *
|
|
||||||
getSectionPrefixForUniqueGlobal(SectionKind kind) const;
|
|
||||||
|
|
||||||
virtual void getSectionFlagsAsString(SectionKind Kind,
|
virtual void getSectionFlagsAsString(SectionKind Kind,
|
||||||
SmallVectorImpl<char> &Str) const;
|
SmallVectorImpl<char> &Str) const;
|
||||||
|
|
||||||
|
virtual const Section *
|
||||||
|
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,6 @@ namespace llvm {
|
||||||
void getSectionFlagsAsString(SectionKind Kind,
|
void getSectionFlagsAsString(SectionKind Kind,
|
||||||
SmallVectorImpl<char> &Str) const;
|
SmallVectorImpl<char> &Str) const;
|
||||||
|
|
||||||
const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) const;
|
|
||||||
|
|
||||||
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
|
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
|
||||||
SectionKind Kind) const;
|
SectionKind Kind) const;
|
||||||
|
|
||||||
|
|
|
@ -144,6 +144,9 @@ namespace llvm {
|
||||||
bool ExplicitSection : 1;
|
bool ExplicitSection : 1;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
// FIXME: REMOVE.
|
||||||
|
Kind getKind() const { return K; }
|
||||||
|
|
||||||
bool isWeak() const { return Weak; }
|
bool isWeak() const { return Weak; }
|
||||||
bool hasExplicitSection() const { return ExplicitSection; }
|
bool hasExplicitSection() const { return ExplicitSection; }
|
||||||
|
|
||||||
|
@ -669,15 +672,6 @@ namespace llvm {
|
||||||
virtual const Section *getSectionForMergeableConstant(SectionKind Kind)const;
|
virtual const Section *getSectionForMergeableConstant(SectionKind Kind)const;
|
||||||
|
|
||||||
|
|
||||||
/// getSectionPrefixForUniqueGlobal - Return a string that we should prepend
|
|
||||||
/// onto a global's name in order to get the unique section name for the
|
|
||||||
/// global. This is important for globals that need to be merged across
|
|
||||||
/// translation units.
|
|
||||||
virtual const char *
|
|
||||||
getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getKindForNamedSection - If this target wants to be able to override
|
/// getKindForNamedSection - If this target wants to be able to override
|
||||||
/// section flags based on the name of the section specified for a global
|
/// section flags based on the name of the section specified for a global
|
||||||
/// variable, it can implement this. This is used on ELF systems so that
|
/// variable, it can implement this. This is used on ELF systems so that
|
||||||
|
|
|
@ -53,15 +53,6 @@ COFFTargetAsmInfo::COFFTargetAsmInfo(const TargetMachine &TM)
|
||||||
DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
|
DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *COFFTargetAsmInfo::
|
|
||||||
getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
|
|
||||||
if (Kind.isText())
|
|
||||||
return ".text$linkonce";
|
|
||||||
if (Kind.isWriteable())
|
|
||||||
return ".data$linkonce";
|
|
||||||
return ".rdata$linkonce";
|
|
||||||
}
|
|
||||||
|
|
||||||
void COFFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
|
void COFFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
|
||||||
SmallVectorImpl<char> &Str) const {
|
SmallVectorImpl<char> &Str) const {
|
||||||
// FIXME: Inefficient.
|
// FIXME: Inefficient.
|
||||||
|
@ -74,3 +65,45 @@ void COFFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
|
||||||
|
|
||||||
Str.append(Res.begin(), Res.end());
|
Str.append(Res.begin(), Res.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Move to AsmPrinter (mangler access).
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/GlobalVariable.h"
|
||||||
|
|
||||||
|
static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) {
|
||||||
|
if (Kind.isText())
|
||||||
|
return ".text$linkonce";
|
||||||
|
if (Kind.isWriteable())
|
||||||
|
return ".data$linkonce";
|
||||||
|
return ".rdata$linkonce";
|
||||||
|
}
|
||||||
|
|
||||||
|
const Section *
|
||||||
|
COFFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
|
||||||
|
SectionKind Kind) const {
|
||||||
|
assert(!Kind.isThreadLocal() && "Doesn't support TLS");
|
||||||
|
|
||||||
|
// If this global is linkonce/weak and the target handles this by emitting it
|
||||||
|
// into a 'uniqued' section name, create and return the section now.
|
||||||
|
if (Kind.isWeak()) {
|
||||||
|
const char *Prefix = getSectionPrefixForUniqueGlobal(Kind);
|
||||||
|
// FIXME: Use mangler interface (PR4584).
|
||||||
|
std::string Name = Prefix+GV->getNameStr();
|
||||||
|
return getOrCreateSection(Name.c_str(), false, Kind.getKind());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Kind.isText())
|
||||||
|
return getTextSection();
|
||||||
|
|
||||||
|
if (Kind.isBSS())
|
||||||
|
if (const Section *S = getBSSSection_())
|
||||||
|
return S;
|
||||||
|
|
||||||
|
if (Kind.isReadOnly())
|
||||||
|
if (const Section *S = getReadOnlySection())
|
||||||
|
return S;
|
||||||
|
|
||||||
|
return getDataSection();
|
||||||
|
}
|
||||||
|
|
|
@ -12,16 +12,8 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Constants.h"
|
|
||||||
#include "llvm/DerivedTypes.h"
|
|
||||||
#include "llvm/Function.h"
|
|
||||||
#include "llvm/GlobalVariable.h"
|
|
||||||
#include "llvm/ADT/StringExtras.h"
|
|
||||||
#include "llvm/CodeGen/MachineConstantPool.h"
|
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
|
||||||
#include "llvm/Target/ELFTargetAsmInfo.h"
|
#include "llvm/Target/ELFTargetAsmInfo.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
|
ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
|
||||||
|
@ -53,72 +45,6 @@ ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
|
||||||
SectionKind::MergeableConst16);
|
SectionKind::MergeableConst16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Section*
|
|
||||||
ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
|
|
||||||
SectionKind Kind) const {
|
|
||||||
if (Kind.isText()) return TextSection;
|
|
||||||
if (Kind.isMergeableCString()) {
|
|
||||||
const TargetData *TD = TM.getTargetData();
|
|
||||||
Constant *C = cast<GlobalVariable>(GV)->getInitializer();
|
|
||||||
const Type *Ty = cast<ArrayType>(C->getType())->getElementType();
|
|
||||||
|
|
||||||
unsigned Size = TD->getTypeAllocSize(Ty);
|
|
||||||
if (Size <= 16) {
|
|
||||||
assert(getCStringSection() && "Should have string section prefix");
|
|
||||||
|
|
||||||
// We also need alignment here.
|
|
||||||
// FIXME: this is getting the alignment of the character, not the
|
|
||||||
// alignment of the string!!
|
|
||||||
unsigned Align = TD->getPrefTypeAlignment(Ty);
|
|
||||||
if (Align < Size)
|
|
||||||
Align = Size;
|
|
||||||
|
|
||||||
std::string Name = getCStringSection() + utostr(Size) + '.' +
|
|
||||||
utostr(Align);
|
|
||||||
return getOrCreateSection(Name.c_str(), false,
|
|
||||||
SectionKind::MergeableCString);
|
|
||||||
}
|
|
||||||
|
|
||||||
return getReadOnlySection();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Kind.isMergeableConst()) {
|
|
||||||
if (Kind.isMergeableConst4())
|
|
||||||
return MergeableConst4Section;
|
|
||||||
if (Kind.isMergeableConst8())
|
|
||||||
return MergeableConst8Section;
|
|
||||||
if (Kind.isMergeableConst16())
|
|
||||||
return MergeableConst16Section;
|
|
||||||
return ReadOnlySection; // .const
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Kind.isReadOnly()) return getReadOnlySection();
|
|
||||||
|
|
||||||
|
|
||||||
if (Kind.isThreadData()) return TLSDataSection;
|
|
||||||
if (Kind.isThreadBSS()) return TLSBSSSection;
|
|
||||||
|
|
||||||
if (Kind.isBSS()) return getBSSSection_();
|
|
||||||
|
|
||||||
|
|
||||||
if (Kind.isDataNoRel()) return DataSection;
|
|
||||||
if (Kind.isDataRelLocal()) return DataRelLocalSection;
|
|
||||||
if (Kind.isDataRel()) return DataRelSection;
|
|
||||||
if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection;
|
|
||||||
|
|
||||||
assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
|
|
||||||
return DataRelROSection;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getSectionForMergeableConstant - Given a Mergeable constant with the
|
|
||||||
/// specified size and relocation information, return a section that it
|
|
||||||
/// should be placed in.
|
|
||||||
const Section *
|
|
||||||
ELFTargetAsmInfo::getSectionForMergeableConstant(SectionKind Kind) const {
|
|
||||||
return SelectSectionForGlobal(0, Kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// getFlagsForNamedSection - If this target wants to be able to infer
|
/// getFlagsForNamedSection - If this target wants to be able to infer
|
||||||
/// section flags based on the name of the section specified for a global
|
/// section flags based on the name of the section specified for a global
|
||||||
/// variable, it can implement this.
|
/// variable, it can implement this.
|
||||||
|
@ -148,24 +74,6 @@ SectionKind::Kind ELFTargetAsmInfo::getKindForNamedSection(const char *Name,
|
||||||
return K;
|
return K;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
|
||||||
ELFTargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind Kind) const{
|
|
||||||
if (Kind.isText()) return ".gnu.linkonce.t.";
|
|
||||||
if (Kind.isReadOnly()) return ".gnu.linkonce.r.";
|
|
||||||
|
|
||||||
if (Kind.isThreadData()) return ".gnu.linkonce.td.";
|
|
||||||
if (Kind.isThreadBSS()) return ".gnu.linkonce.tb.";
|
|
||||||
|
|
||||||
if (Kind.isBSS()) return ".gnu.linkonce.b.";
|
|
||||||
if (Kind.isDataNoRel()) return ".gnu.linkonce.d.";
|
|
||||||
if (Kind.isDataRelLocal()) return ".gnu.linkonce.d.rel.local.";
|
|
||||||
if (Kind.isDataRel()) return ".gnu.linkonce.d.rel.";
|
|
||||||
if (Kind.isReadOnlyWithRelLocal()) return ".gnu.linkonce.d.rel.ro.local.";
|
|
||||||
|
|
||||||
assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
|
|
||||||
return ".gnu.linkonce.d.rel.ro.";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void ELFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
|
void ELFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
|
||||||
SmallVectorImpl<char> &Str) const {
|
SmallVectorImpl<char> &Str) const {
|
||||||
|
@ -219,3 +127,108 @@ void ELFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
|
||||||
Str.push_back('6');
|
Str.push_back('6');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// Move to AsmPrinter (mangler access).
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "llvm/DerivedTypes.h"
|
||||||
|
#include "llvm/GlobalVariable.h"
|
||||||
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#include "llvm/Target/TargetMachine.h"
|
||||||
|
#include "llvm/ADT/StringExtras.h"
|
||||||
|
|
||||||
|
static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) {
|
||||||
|
if (Kind.isText()) return ".gnu.linkonce.t.";
|
||||||
|
if (Kind.isReadOnly()) return ".gnu.linkonce.r.";
|
||||||
|
|
||||||
|
if (Kind.isThreadData()) return ".gnu.linkonce.td.";
|
||||||
|
if (Kind.isThreadBSS()) return ".gnu.linkonce.tb.";
|
||||||
|
|
||||||
|
if (Kind.isBSS()) return ".gnu.linkonce.b.";
|
||||||
|
if (Kind.isDataNoRel()) return ".gnu.linkonce.d.";
|
||||||
|
if (Kind.isDataRelLocal()) return ".gnu.linkonce.d.rel.local.";
|
||||||
|
if (Kind.isDataRel()) return ".gnu.linkonce.d.rel.";
|
||||||
|
if (Kind.isReadOnlyWithRelLocal()) return ".gnu.linkonce.d.rel.ro.local.";
|
||||||
|
|
||||||
|
assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
|
||||||
|
return ".gnu.linkonce.d.rel.ro.";
|
||||||
|
}
|
||||||
|
|
||||||
|
const Section*
|
||||||
|
ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
|
||||||
|
SectionKind Kind) const {
|
||||||
|
|
||||||
|
// If this global is linkonce/weak and the target handles this by emitting it
|
||||||
|
// into a 'uniqued' section name, create and return the section now.
|
||||||
|
if (Kind.isWeak()) {
|
||||||
|
const char *Prefix = getSectionPrefixForUniqueGlobal(Kind);
|
||||||
|
// FIXME: Use mangler interface (PR4584).
|
||||||
|
std::string Name = Prefix+GV->getNameStr();
|
||||||
|
return getOrCreateSection(Name.c_str(), false, Kind.getKind());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Kind.isText()) return TextSection;
|
||||||
|
if (Kind.isMergeableCString()) {
|
||||||
|
const TargetData *TD = TM.getTargetData();
|
||||||
|
Constant *C = cast<GlobalVariable>(GV)->getInitializer();
|
||||||
|
const Type *Ty = cast<ArrayType>(C->getType())->getElementType();
|
||||||
|
|
||||||
|
unsigned Size = TD->getTypeAllocSize(Ty);
|
||||||
|
if (Size <= 16) {
|
||||||
|
assert(getCStringSection() && "Should have string section prefix");
|
||||||
|
|
||||||
|
// We also need alignment here.
|
||||||
|
// FIXME: this is getting the alignment of the character, not the
|
||||||
|
// alignment of the string!!
|
||||||
|
unsigned Align = TD->getPrefTypeAlignment(Ty);
|
||||||
|
if (Align < Size)
|
||||||
|
Align = Size;
|
||||||
|
|
||||||
|
std::string Name = getCStringSection() + utostr(Size) + '.' +
|
||||||
|
utostr(Align);
|
||||||
|
return getOrCreateSection(Name.c_str(), false,
|
||||||
|
SectionKind::MergeableCString);
|
||||||
|
}
|
||||||
|
|
||||||
|
return getReadOnlySection();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Kind.isMergeableConst()) {
|
||||||
|
if (Kind.isMergeableConst4())
|
||||||
|
return MergeableConst4Section;
|
||||||
|
if (Kind.isMergeableConst8())
|
||||||
|
return MergeableConst8Section;
|
||||||
|
if (Kind.isMergeableConst16())
|
||||||
|
return MergeableConst16Section;
|
||||||
|
return ReadOnlySection; // .const
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Kind.isReadOnly()) return getReadOnlySection();
|
||||||
|
|
||||||
|
|
||||||
|
if (Kind.isThreadData()) return TLSDataSection;
|
||||||
|
if (Kind.isThreadBSS()) return TLSBSSSection;
|
||||||
|
|
||||||
|
if (Kind.isBSS()) return getBSSSection_();
|
||||||
|
|
||||||
|
|
||||||
|
if (Kind.isDataNoRel()) return DataSection;
|
||||||
|
if (Kind.isDataRelLocal()) return DataRelLocalSection;
|
||||||
|
if (Kind.isDataRel()) return DataRelSection;
|
||||||
|
if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection;
|
||||||
|
|
||||||
|
assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
|
||||||
|
return DataRelROSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// getSectionForMergeableConstant - Given a Mergeable constant with the
|
||||||
|
/// specified size and relocation information, return a section that it
|
||||||
|
/// should be placed in.
|
||||||
|
const Section *
|
||||||
|
ELFTargetAsmInfo::getSectionForMergeableConstant(SectionKind Kind) const {
|
||||||
|
return SelectSectionForGlobal(0, Kind);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -319,15 +319,6 @@ const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
|
||||||
return getOrCreateSection(GV->getSection().c_str(), false, GVKind);
|
return getOrCreateSection(GV->getSection().c_str(), false, GVKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this global is linkonce/weak and the target handles this by emitting it
|
|
||||||
// into a 'uniqued' section name, create and return the section now.
|
|
||||||
if (Kind.isWeak()) {
|
|
||||||
if (const char *Prefix = getSectionPrefixForUniqueGlobal(Kind)) {
|
|
||||||
// FIXME: Use mangler interface (PR4584).
|
|
||||||
std::string Name = Prefix+GV->getNameStr();
|
|
||||||
return getOrCreateSection(Name.c_str(), false, GVKind);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use default section depending on the 'type' of global
|
// Use default section depending on the 'type' of global
|
||||||
return SelectSectionForGlobal(GV, Kind);
|
return SelectSectionForGlobal(GV, Kind);
|
||||||
|
|
Loading…
Reference in New Issue