-std::string
-X86ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
- SectionKind::Kind kind = SectionKindForGlobal(GV);
-
- if (const Function *F = dyn_cast<Function>(GV)) {
- switch (F->getLinkage()) {
- default: assert(0 && "Unknown linkage type!");
- case Function::InternalLinkage:
- case Function::DLLExportLinkage:
- case Function::ExternalLinkage:
- return getTextSection();
- case Function::WeakLinkage:
- case Function::LinkOnceLinkage:
- return UniqueSectionForGlobal(F, kind);
- }
- } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
- if (GVar->hasCommonLinkage() ||
- GVar->hasLinkOnceLinkage() ||
- GVar->hasWeakLinkage())
- return UniqueSectionForGlobal(GVar, kind);
- else {
- switch (kind) {
- case SectionKind::Data:
- return getDataSection();
- case SectionKind::BSS:
- // ELF targets usually have BSS sections
- return getBSSSection();
- case SectionKind::ROData:
- return getReadOnlySection();
- case SectionKind::RODataMergeStr:
- return MergeableStringSection(GVar);
- case SectionKind::RODataMergeConst:
- return MergeableConstSection(GVar);
- case SectionKind::ThreadData:
- // ELF targets usually support TLS stuff
- return getTLSDataSection();
- case SectionKind::ThreadBSS:
- return getTLSBSSSection();
- default:
- assert(0 && "Unsuported section kind for global");
- }
- }
- } else
- assert(0 && "Unsupported global");
-}
-
-std::string
-X86ELFTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const {
- unsigned Flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
- unsigned Size = SectionFlags::getEntitySize(Flags);
-
- // FIXME: string here is temporary, until stuff will fully land in.
- if (Size)
- return ".rodata.cst" + utostr(Size);
- else
- return getReadOnlySection();
-}
-
-std::string
-X86ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
- unsigned Flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
- unsigned Size = SectionFlags::getEntitySize(Flags);
-
- if (Size) {
- // We also need alignment here
- const TargetData *TD = X86TM->getTargetData();
- unsigned Align = TD->getPreferredAlignment(GV);
- if (Align < Size)
- Align = Size;
-
- // FIXME: string here is temporary, until stuff will fully land in.
- return ".rodata.str" + utostr(Size) + ',' + utostr(Align);
- } else
- return getReadOnlySection();
-}
-
-unsigned
-X86ELFTargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
- const char* name) const {
- unsigned Flags =
- TargetAsmInfo::SectionFlagsForGlobal(GV,
- GV->getSection().c_str());
-
- // If there was decision to put stuff into mergeable section - calculate
- // entity size
- if (Flags & SectionFlags::Mergeable) {
- const TargetData *TD = X86TM->getTargetData();
- Constant *C = cast<GlobalVariable>(GV)->getInitializer();
- const Type *Type;
-
- if (Flags & SectionFlags::Strings) {
- const ConstantArray *CVA = cast<ConstantArray>(C);
- Type = CVA->getType()->getElementType();
- } else
- Type = C->getType();
-
- unsigned Size = TD->getABITypeSize(Type);
- if (Size > 32)
- Size = 0;
- Flags = SectionFlags::setEntitySize(Flags, Size);
- }
-
- return Flags;
-}
-
-
-std::string X86ELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
- std::string Flags = ",\"";
-
- if (!(flags & SectionFlags::Debug))
- Flags += 'a';
- if (flags & SectionFlags::Code)
- Flags += 'x';
- if (flags & SectionFlags::Writeable)
- Flags += 'w';
- if (flags & SectionFlags::Mergeable)
- Flags += 'M';
- if (flags & SectionFlags::Strings)
- Flags += 'S';
- if (flags & SectionFlags::TLS)
- Flags += 'T';
-
- Flags += "\"";
-
- // FIXME: There can be exceptions here
- if (flags & SectionFlags::BSS)
- Flags += ",@nobits";
- else
- Flags += ",@progbits";
-
- if (unsigned entitySize = SectionFlags::getEntitySize(flags))
- Flags += "," + utostr(entitySize);
-
- return Flags;
-}
-