[lld] r195610 - [PECOFF] Set ordinals to linker internal atoms.
Rui Ueyama
ruiu at google.com
Sun Nov 24 21:38:20 PST 2013
Author: ruiu
Date: Sun Nov 24 23:38:20 2013
New Revision: 195610
URL: http://llvm.org/viewvc/llvm-project?rev=195610&view=rev
Log:
[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.)
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp
lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h?rev=195610&r1=195609&r2=195610&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/Atoms.h Sun Nov 24 23:38:20 2013
@@ -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__; }
Modified: lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h?rev=195610&r1=195609&r2=195610&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h Sun Nov 24 23:38:20 2013
@@ -45,6 +45,7 @@ using std::vector;
namespace lld {
namespace pecoff {
+class IdataPassFile;
namespace {
class DLLNameAtom;
@@ -59,10 +60,10 @@ void addDir32NBReloc(COFFBaseDefinedAtom
// 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
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp?rev=195610&r1=195609&r2=195610&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderImportHeader.cpp Sun Nov 24 23:38:20 2013
@@ -160,7 +160,7 @@ class FuncAtom : public COFFLinkerIntern
public:
FuncAtom(const File &file, StringRef symbolName)
: COFFLinkerInternalAtom(
- file,
+ file, /*oridnal*/ 0,
std::vector<uint8_t>(FuncAtomContent,
FuncAtomContent + sizeof(FuncAtomContent)),
symbolName) {}
Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=195610&r1=195609&r2=195610&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Sun Nov 24 23:38:20 2013
@@ -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(uint
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<
// 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(con
*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
More information about the llvm-commits
mailing list