diff --git a/include/llvm/Target/TargetAsmInfo.h b/include/llvm/Target/TargetAsmInfo.h index 7656ad67e91..a36ce476028 100644 --- a/include/llvm/Target/TargetAsmInfo.h +++ b/include/llvm/Target/TargetAsmInfo.h @@ -474,7 +474,7 @@ namespace llvm { /// SectionForGlobal - This hooks returns proper section name for given /// global with all necessary flags and marks. - virtual const char* SectionForGlobal(const GlobalValue *GV) const; + virtual std::string SectionForGlobal(const GlobalValue *GV) const; // Accessors. // diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index 433330c146e..923cac6640c 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -255,7 +255,7 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV, return flags; } -const char* +std::string TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { SectionKind::Kind kind = SectionKindForGlobal(GV); diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp index 887c13dcc76..750e6b36bc2 100644 --- a/lib/Target/X86/X86TargetAsmInfo.cpp +++ b/lib/Target/X86/X86TargetAsmInfo.cpp @@ -346,8 +346,8 @@ unsigned X86TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, else { // 64 bit targets encode pointers in 4 bytes iff: // - code model is small OR - // - code model is medium and we're emitting externally visible symbols or - // any code symbols + // - code model is medium and we're emitting externally visible symbols + // or any code symbols if (CM == CodeModel::Small || (CM == CodeModel::Medium && (Global || Reason != DwarfEncoding::Data))) @@ -375,3 +375,96 @@ unsigned X86TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, } } +std::string X86TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { + const X86Subtarget *Subtarget = &X86TM->getSubtarget(); + SectionKind::Kind kind = SectionKindForGlobal(GV); + unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str()); + std::string Name; + + // FIXME: Should we use some hashing based on section name and just check + // flags? + + // Select section name + if (const Function *F = dyn_cast(GV)) { + // Implement here + } else if (const GlobalVariable *GVar = dyn_cast(GV)) { + if (GVar->hasSection()) { + // Honour section already set, if any + Name = GVar->getSection(); + } else { + // Use default section depending on the 'type' of global + // FIXME: Handle linkonce stuff + switch (kind) { + case SectionKind::Data: + Name = DataSection; + break; + case SectionKind::BSS: + Name = (BSSSection ? BSSSection : DataSection); + break; + case SectionKind::ROData: + case SectionKind::RODataMergeStr: + case SectionKind::RODataMergeConst: + // FIXME: Temporary + Name = DataSection; + break; + case SectionKind::ThreadData: + Name = (TLSDataSection ? TLSDataSection : DataSection); + break; + case SectionKind::ThreadBSS: + Name = (TLSBSSSection ? TLSBSSSection : DataSection); + default: + assert(0 && "Unsuported section kind for global"); + } + } + } else + assert(0 && "Unsupported global"); + + // Add all special flags, etc + switch (Subtarget->TargetType) { + case X86Subtarget::isELF: + Name += ",\""; + + if (!(flags & SectionFlags::Debug)) + Name += 'a'; + if (flags & SectionFlags::Code) + Name += 'x'; + if (flags & SectionFlags::Writeable) + Name += 'w'; + if (flags & SectionFlags::Mergeable) + Name += 'M'; + if (flags & SectionFlags::Strings) + Name += 'S'; + if (flags & SectionFlags::TLS) + Name += 'T'; + + Name += "\""; + + // FIXME: There can be exceptions here + if (flags & SectionFlags::BSS) + Name += ",@nobits"; + else + Name += ",@progbits"; + + // FIXME: entity size for mergeable sections + break; + case X86Subtarget::isCygwin: + case X86Subtarget::isMingw: + Name += ",\""; + + if (flags & SectionFlags::Code) + Name += 'x'; + if (flags & SectionFlags::Writeable) + Name += 'w'; + + Name += "\""; + + break; + case X86Subtarget::isDarwin: + // Darwin does not use any special flags + default: + break; + } + + return Name; +} + diff --git a/lib/Target/X86/X86TargetAsmInfo.h b/lib/Target/X86/X86TargetAsmInfo.h index d9dd2753571..7d92c799bda 100644 --- a/lib/Target/X86/X86TargetAsmInfo.h +++ b/lib/Target/X86/X86TargetAsmInfo.h @@ -23,10 +23,11 @@ namespace llvm { struct X86TargetAsmInfo : public TargetAsmInfo { explicit X86TargetAsmInfo(const X86TargetMachine &TM); - + virtual bool ExpandInlineAsm(CallInst *CI) const; virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason, bool Global) const; + virtual std::string SectionForGlobal(const GlobalValue *GV) const; private: const X86TargetMachine* X86TM;