diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2011-01-23 17:55:27 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2011-01-23 17:55:27 +0000 |
commit | 96aa78c8c5ef1a5f268539c9edc86569b436d573 (patch) | |
tree | e664056c0f0a8ce32c72d19cf0f0ae1e8eefd038 /lib/MC | |
parent | 584520e8e2c1f8cc04bc8dd4dc4ea6c390627317 (diff) |
Add support for the --noexecstack option.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124077 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC')
-rw-r--r-- | lib/MC/ELFObjectWriter.cpp | 30 | ||||
-rw-r--r-- | lib/MC/MCAssembler.cpp | 2 | ||||
-rw-r--r-- | lib/MC/MCELFStreamer.cpp | 6 |
3 files changed, 26 insertions, 12 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 05dd0c7629..4dbb5387f3 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -329,8 +329,11 @@ namespace { virtual void CreateMetadataSections(MCAssembler &Asm, MCAsmLayout &Layout, const SectionIndexMapTy &SectionIndexMap); - virtual void CreateGroupSections(MCAssembler &Asm, MCAsmLayout &Layout, - GroupMapTy &GroupMap, RevGroupMapTy &RevGroupMap); + // Create the sections that show up in the symbol table. Currently + // those are the .note.GNU-stack section and the group sections. + virtual void CreateIndexedSections(MCAssembler &Asm, MCAsmLayout &Layout, + GroupMapTy &GroupMap, + RevGroupMapTy &RevGroupMap); virtual void ExecutePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout); @@ -1174,10 +1177,19 @@ ELFObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, return &SecA == &SecB; } -void ELFObjectWriter::CreateGroupSections(MCAssembler &Asm, - MCAsmLayout &Layout, - GroupMapTy &GroupMap, - RevGroupMapTy &RevGroupMap) { +void ELFObjectWriter::CreateIndexedSections(MCAssembler &Asm, + MCAsmLayout &Layout, + GroupMapTy &GroupMap, + RevGroupMapTy &RevGroupMap) { + // Create the .note.GNU-stack section if needed. + MCContext &Ctx = Asm.getContext(); + if (Asm.getNoExecStack()) { + const MCSectionELF *GnuStackSection = + Ctx.getELFSection(".note.GNU-stack", ELF::SHT_PROGBITS, 0, + SectionKind::getReadOnly()); + Asm.getOrCreateSectionData(*GnuStackSection); + } + // Build the groups for (MCAssembler::const_iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it) { @@ -1190,7 +1202,7 @@ void ELFObjectWriter::CreateGroupSections(MCAssembler &Asm, Asm.getOrCreateSymbolData(*SignatureSymbol); const MCSectionELF *&Group = RevGroupMap[SignatureSymbol]; if (!Group) { - Group = Asm.getContext().CreateELFGroupSection(); + Group = Ctx.CreateELFGroupSection(); MCSectionData &Data = Asm.getOrCreateSectionData(*Group); Data.setAlignment(4); MCDataFragment *F = new MCDataFragment(&Data); @@ -1334,8 +1346,8 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout) { GroupMapTy GroupMap; RevGroupMapTy RevGroupMap; - CreateGroupSections(Asm, const_cast<MCAsmLayout&>(Layout), GroupMap, - RevGroupMap); + CreateIndexedSections(Asm, const_cast<MCAsmLayout&>(Layout), GroupMap, + RevGroupMap); SectionIndexMapTy SectionIndexMap; diff --git a/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp index 5b291490f7..587068aee5 100644 --- a/lib/MC/MCAssembler.cpp +++ b/lib/MC/MCAssembler.cpp @@ -172,7 +172,7 @@ MCAssembler::MCAssembler(MCContext &Context_, TargetAsmBackend &Backend_, MCCodeEmitter &Emitter_, MCObjectWriter &Writer_, raw_ostream &OS_) : Context(Context_), Backend(Backend_), Emitter(Emitter_), Writer(Writer_), - OS(OS_), RelaxAll(false), SubsectionsViaSymbols(false) + OS(OS_), RelaxAll(false), NoExecStack(false), SubsectionsViaSymbols(false) { } diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index 6a6c9338ab..ac31057065 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -515,10 +515,12 @@ void MCELFStreamer::Finish() { } MCStreamer *llvm::createELFStreamer(MCContext &Context, TargetAsmBackend &TAB, - raw_ostream &OS, MCCodeEmitter *CE, - bool RelaxAll) { + raw_ostream &OS, MCCodeEmitter *CE, + bool RelaxAll, bool NoExecStack) { MCELFStreamer *S = new MCELFStreamer(Context, TAB, OS, CE); if (RelaxAll) S->getAssembler().setRelaxAll(true); + if (NoExecStack) + S->getAssembler().setNoExecStack(true); return S; } |