diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2018-08-22 23:58:16 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2018-08-22 23:58:16 +0000 |
commit | bc3089f45f9eda5cbe5c728cdbb09e76e1e22176 (patch) | |
tree | 3a37839a68d7d656fcb24328e2ecb98590157995 /llvm/lib/MC/WinCOFFObjectWriter.cpp | |
parent | a2761e437f220ec2cc4a5503bc427b317cc8c59d (diff) | |
download | bcm5719-llvm-bc3089f45f9eda5cbe5c728cdbb09e76e1e22176.tar.gz bcm5719-llvm-bc3089f45f9eda5cbe5c728cdbb09e76e1e22176.zip |
MC: Teach the COFF object writer to write address-significance tables.
The format is the same as in ELF: a sequence of ULEB128-encoded
symbol indexes.
Differential Revision: https://reviews.llvm.org/D51047
llvm-svn: 340499
Diffstat (limited to 'llvm/lib/MC/WinCOFFObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/WinCOFFObjectWriter.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp index 4f6103c6d68..82c9fe76758 100644 --- a/llvm/lib/MC/WinCOFFObjectWriter.cpp +++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp @@ -36,6 +36,7 @@ #include "llvm/Support/Endian.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/JamCRC.h" +#include "llvm/Support/LEB128.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> @@ -145,6 +146,10 @@ public: bool UseBigObj; + bool EmitAddrsigSection = false; + MCSectionCOFF *AddrsigSection; + std::vector<const MCSymbol *> AddrsigSyms; + WinCOFFObjectWriter(std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW, raw_pwrite_stream &OS); @@ -204,6 +209,11 @@ public: void assignSectionNumbers(); void assignFileOffsets(MCAssembler &Asm, const MCAsmLayout &Layout); + void emitAddrsigSection() override { EmitAddrsigSection = true; } + void addAddrsigSymbol(const MCSymbol *Sym) override { + AddrsigSyms.push_back(Sym); + } + uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override; }; @@ -657,6 +667,13 @@ void WinCOFFObjectWriter::writeSection(MCAssembler &Asm, void WinCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout) { + if (EmitAddrsigSection) { + AddrsigSection = Asm.getContext().getCOFFSection( + ".llvm_addrsig", COFF::IMAGE_SCN_LNK_REMOVE, + SectionKind::getMetadata()); + Asm.registerSection(*AddrsigSection); + } + // "Define" each section & symbol. This creates section & symbol // entries in the staging area. for (const auto &Section : Asm) @@ -1024,6 +1041,24 @@ uint64_t WinCOFFObjectWriter::writeObject(MCAssembler &Asm, Section->Symbol->Aux[0].Aux.SectionDefinition.Number = AssocSec->Number; } + // Create the contents of the .llvm_addrsig section. + if (EmitAddrsigSection) { + auto Frag = new MCDataFragment(AddrsigSection); + raw_svector_ostream OS(Frag->getContents()); + for (const MCSymbol *S : AddrsigSyms) { + if (!S->isTemporary()) { + encodeULEB128(S->getIndex(), OS); + continue; + } + + MCSection *TargetSection = &S->getSection(); + assert(SectionMap.find(TargetSection) != SectionMap.end() && + "Section must already have been defined in " + "executePostLayoutBinding!"); + encodeULEB128(SectionMap[TargetSection]->Symbol->getIndex(), OS); + } + } + assignFileOffsets(Asm, Layout); // MS LINK expects to be able to use this timestamp to implement their |