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,
SmallVectorImpl<char> &Str) const {
// FIXME: Inefficient.
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();
+}
//
//===----------------------------------------------------------------------===//
-#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/TargetMachine.h"
-#include "llvm/Target/TargetData.h"
+#include "llvm/ADT/SmallVector.h"
using namespace llvm;
ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
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
/// section flags based on the name of the section specified for a global
/// variable, it can implement this.
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,
SmallVectorImpl<char> &Str) const {
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);
+}
+