diff options
| author | Rui Ueyama <ruiu@google.com> | 2013-11-25 05:38:20 +0000 |
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2013-11-25 05:38:20 +0000 |
| commit | 6194109c29791f000e5ba3327d838b4be4e6c651 (patch) | |
| tree | 60721cea686bd78efab7b48490c83e2d6236c216 | |
| parent | e3c48709ed1a6e4271643795cdd02538895ae61e (diff) | |
| download | bcm5719-llvm-6194109c29791f000e5ba3327d838b4be4e6c651.tar.gz bcm5719-llvm-6194109c29791f000e5ba3327d838b4be4e6c651.zip | |
[PECOFF] Set ordinals to linker internal atoms.
This patch won't change the output because the layout of linker internal
atoms is forced by layout-{before,after} references. Ordinals of the linker
internal atoms are not currently used. (That's why it's working even if there
are atoms having the same ordinals.)
llvm-svn: 195610
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/Atoms.h | 14 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/IdataPass.h | 26 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp | 2 | ||||
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp | 15 |
4 files changed, 36 insertions, 21 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/Atoms.h b/lld/lib/ReaderWriter/PECOFF/Atoms.h index 8c15dbf13c9..ab059691f09 100644 --- a/lld/lib/ReaderWriter/PECOFF/Atoms.h +++ b/lld/lib/ReaderWriter/PECOFF/Atoms.h @@ -229,19 +229,20 @@ private: class COFFLinkerInternalAtom : public COFFBaseDefinedAtom { public: virtual SectionChoice sectionChoice() const { return sectionBasedOnContent; } - virtual uint64_t ordinal() const { return 0; } + virtual uint64_t ordinal() const { return _ordinal; } virtual Scope scope() const { return scopeGlobal; } virtual Alignment alignment() const { return Alignment(0); } virtual uint64_t size() const { return _data.size(); } virtual ArrayRef<uint8_t> rawContent() const { return _data; } protected: - COFFLinkerInternalAtom(const File &file, std::vector<uint8_t> data, - StringRef symbolName = "") + COFFLinkerInternalAtom(const File &file, uint64_t ordinal, + std::vector<uint8_t> data, StringRef symbolName = "") : COFFBaseDefinedAtom(file, symbolName, Kind::Internal), - _data(std::move(data)) {} + _ordinal(ordinal), _data(std::move(data)) {} private: + uint64_t _ordinal; std::vector<uint8_t> _data; }; @@ -249,8 +250,9 @@ private: // COFF header. class COFFDataDirectoryAtom : public COFFLinkerInternalAtom { public: - COFFDataDirectoryAtom(const File &file, std::vector<uint8_t> contents) - : COFFLinkerInternalAtom(file, contents) {} + COFFDataDirectoryAtom(const File &file, uint64_t ordinal, + std::vector<uint8_t> contents) + : COFFLinkerInternalAtom(file, ordinal, contents) {} virtual ContentType contentType() const { return typeDataDirectoryEntry; } virtual ContentPermissions permissions() const { return permR__; } diff --git a/lld/lib/ReaderWriter/PECOFF/IdataPass.h b/lld/lib/ReaderWriter/PECOFF/IdataPass.h index 19797dfff9a..d85604f1a29 100644 --- a/lld/lib/ReaderWriter/PECOFF/IdataPass.h +++ b/lld/lib/ReaderWriter/PECOFF/IdataPass.h @@ -45,6 +45,7 @@ using std::vector; namespace lld { namespace pecoff { +class IdataPassFile; namespace { class DLLNameAtom; @@ -59,10 +60,10 @@ void addDir32NBReloc(COFFBaseDefinedAtom *atom, const Atom *target, // A state object of this pass. struct Context { - Context(MutableFile &f, File &g) : file(f), dummyFile(g) {} + Context(MutableFile &f, IdataPassFile &g) : file(f), dummyFile(g) {} MutableFile &file; - File &dummyFile; + IdataPassFile &dummyFile; // The object to accumulate idata atoms. Idata atoms need to be grouped by // type and be continuous in the output file. To force such layout, we @@ -84,10 +85,7 @@ public: virtual ContentPermissions permissions() const { return permR__; } protected: - IdataAtom(Context &context, vector<uint8_t> data) - : COFFLinkerInternalAtom(context.dummyFile, data) { - context.file.addAtom(*this); - } + IdataAtom(Context &context, vector<uint8_t> data); }; /// A DLLNameAtom contains a name of a DLL and is referenced by the Name RVA @@ -243,9 +241,14 @@ public: class IdataPassFile : public SimpleFile { public: IdataPassFile(const LinkingContext &ctx) - : SimpleFile(ctx, "<idata-pass-file>") { + : SimpleFile(ctx, "<idata-pass-file>"), _nextOrdinal(0) { setOrdinal(ctx.getNextOrdinalAndIncrement()); } + + uint64_t getNextOrdinal() { return _nextOrdinal++; } + +private: + uint64_t _nextOrdinal; }; class IdataPass : public lld::Pass { @@ -336,7 +339,8 @@ private: * context.importAddressTables[0]->size(); auto *dir = new (_alloc) coff::COFFDataDirectoryAtom( - context.dummyFile, std::move(contents)); + context.dummyFile, context.dummyFile.getNextOrdinal(), + std::move(contents)); addDir32NBReloc(dir, context.importDirectories[0], importTableOffset); addDir32NBReloc(dir, context.importAddressTables[0], iatOffset); @@ -366,6 +370,12 @@ private: llvm::BumpPtrAllocator _alloc; }; +IdataAtom::IdataAtom(Context &context, vector<uint8_t> data) + : COFFLinkerInternalAtom(context.dummyFile, + context.dummyFile.getNextOrdinal(), data) { + context.file.addAtom(*this); +} + } // namespace pecoff } // namespace lld diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp index ae8382c782a..28c6751d2ea 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp @@ -160,7 +160,7 @@ class FuncAtom : public COFFLinkerInternalAtom { public: FuncAtom(const File &file, StringRef symbolName) : COFFLinkerInternalAtom( - file, + file, /*oridnal*/ 0, std::vector<uint8_t>(FuncAtomContent, FuncAtomContent + sizeof(FuncAtomContent)), symbolName) {} diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp index 04d29cb1853..5153e39b504 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp @@ -414,8 +414,8 @@ private: /// A BaseRelocAtom represents a base relocation block in ".reloc" section. class BaseRelocAtom : public coff::COFFLinkerInternalAtom { public: - BaseRelocAtom(const File &file, std::vector<uint8_t> data) - : COFFLinkerInternalAtom(file, std::move(data)) {} + BaseRelocAtom(const File &file, uint64_t ordinal, std::vector<uint8_t> data) + : COFFLinkerInternalAtom(file, ordinal, std::move(data)) {} virtual ContentType contentType() const { return typeData; } virtual Alignment alignment() const { return Alignment(2); } @@ -459,7 +459,8 @@ private: PageOffsetT groupByPage(std::vector<uint64_t> relocSites); // Create the content of a relocation block. - DefinedAtom *createBaseRelocBlock(const File &file, uint64_t pageAddr, + DefinedAtom *createBaseRelocBlock(const File &file, uint64_t ordinal, + uint64_t pageAddr, const std::vector<uint16_t> &offsets); mutable llvm::BumpPtrAllocator _alloc; @@ -782,10 +783,11 @@ void SectionHeaderTableChunk::write(uint8_t *fileBuffer) { void BaseRelocChunk::setContents(ChunkVectorT &chunks) { std::vector<uint64_t> relocSites = listRelocSites(chunks); PageOffsetT blocks = groupByPage(relocSites); + uint64_t ordinal = 0; for (auto &i : blocks) { uint64_t pageAddr = i.first; const std::vector<uint16_t> &offsetsInPage = i.second; - appendAtom(createBaseRelocBlock(_file, pageAddr, offsetsInPage)); + appendAtom(createBaseRelocBlock(_file, ordinal++, pageAddr, offsetsInPage)); } } @@ -811,7 +813,8 @@ BaseRelocChunk::groupByPage(std::vector<uint64_t> relocSites) { // Create the content of a relocation block. DefinedAtom * -BaseRelocChunk::createBaseRelocBlock(const File &file, uint64_t pageAddr, +BaseRelocChunk::createBaseRelocBlock(const File &file, uint64_t ordinal, + uint64_t pageAddr, const std::vector<uint16_t> &offsets) { // Relocation blocks should be padded with IMAGE_REL_I386_ABSOLUTE to be // aligned to a DWORD size boundary. @@ -837,7 +840,7 @@ BaseRelocChunk::createBaseRelocBlock(const File &file, uint64_t pageAddr, *reinterpret_cast<ulittle16_t *>(ptr) = val; ptr += sizeof(ulittle16_t); } - return new (_alloc) BaseRelocAtom(file, std::move(contents)); + return new (_alloc) BaseRelocAtom(file, ordinal, std::move(contents)); } } // end anonymous namespace |

