[PECOFF] Align .edata fields on natural boundaries.
The only data in .edata whose length varies is the string. This patch moves all the strings to the end of the section, so that 16-bit or 32-bit integers are aligned on correct boundaries. llvm-svn: 197213
This commit is contained in:
parent
c91c24e33d
commit
3a136547d7
|
@ -68,8 +68,8 @@ EdataPass::createNamePointerTable(const std::vector<const DefinedAtom *> &atoms,
|
|||
|
||||
size_t offset = 0;
|
||||
for (const DefinedAtom *atom : atoms) {
|
||||
COFFStringAtom *stringAtom = new (_alloc) COFFStringAtom(
|
||||
_file, _file.getNextOrdinal(), ".edata", atom->name());
|
||||
COFFStringAtom *stringAtom = new (_alloc)
|
||||
COFFStringAtom(_file, _stringOrdinal++, ".edata", atom->name());
|
||||
file->addAtom(*stringAtom);
|
||||
addDir32NBReloc(table, stringAtom, offset);
|
||||
offset += sizeof(uint32_t);
|
||||
|
@ -114,9 +114,9 @@ void EdataPass::perform(std::unique_ptr<MutableFile> &file) {
|
|||
EdataAtom *table = createExportDirectoryTable(atoms.size());
|
||||
file->addAtom(*table);
|
||||
|
||||
COFFStringAtom *dllName = new (_alloc) COFFStringAtom(
|
||||
_file, _file.getNextOrdinal(),
|
||||
".edata", llvm::sys::path::filename(_ctx.outputPath()));
|
||||
COFFStringAtom *dllName =
|
||||
new (_alloc) COFFStringAtom(_file, _stringOrdinal++, ".edata",
|
||||
llvm::sys::path::filename(_ctx.outputPath()));
|
||||
file->addAtom(*dllName);
|
||||
addDir32NBReloc(table, dllName, offsetof(export_directory_table_entry, NameRVA));
|
||||
|
||||
|
|
|
@ -56,7 +56,8 @@ public:
|
|||
|
||||
class EdataPass : public lld::Pass {
|
||||
public:
|
||||
EdataPass(const PECOFFLinkingContext &ctx) : _ctx(ctx), _file(ctx) {}
|
||||
EdataPass(const PECOFFLinkingContext &ctx)
|
||||
: _ctx(ctx), _file(ctx), _stringOrdinal(1024) {}
|
||||
|
||||
virtual void perform(std::unique_ptr<MutableFile> &file);
|
||||
|
||||
|
@ -64,14 +65,16 @@ private:
|
|||
edata::EdataAtom *createExportDirectoryTable(size_t numEntries);
|
||||
edata::EdataAtom *createAddressTable(
|
||||
const std::vector<const DefinedAtom *> &atoms);
|
||||
edata::EdataAtom *createNamePointerTable(
|
||||
const std::vector<const DefinedAtom *> &atoms, MutableFile *file);
|
||||
edata::EdataAtom *
|
||||
createNamePointerTable(const std::vector<const DefinedAtom *> &atoms,
|
||||
MutableFile *file);
|
||||
edata::EdataAtom *createOrdinalTable(
|
||||
const std::vector<const DefinedAtom *> &atoms,
|
||||
const std::vector<const DefinedAtom *> &sortedAtoms);
|
||||
|
||||
const PECOFFLinkingContext &_ctx;
|
||||
VirtualFile _file;
|
||||
int _stringOrdinal;
|
||||
mutable llvm::BumpPtrAllocator _alloc;
|
||||
};
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
# RUN: llvm-objdump -s %t.dll | FileCheck %s
|
||||
|
||||
CHECK: Contents of section .edata:
|
||||
CHECK-NEXT: 1000 00000000 {{........}} 00000000 28100000
|
||||
CHECK-NEXT: 1010 01000000 01000000 01000000 3c100000
|
||||
CHECK-NEXT: 1020 40100000 4e100000 6578706f 72742e74
|
||||
CHECK-NEXT: 1030 6573742e 746d702e 646c6c00 08200000
|
||||
CHECK-NEXT: 1040 44100000 5f657870 6f727466 6e000000
|
||||
CHECK-NEXT: 1000 00000000 {{........}} 00000000 32100000
|
||||
CHECK-NEXT: 1010 01000000 01000000 01000000 28100000
|
||||
CHECK-NEXT: 1020 2c100000 30100000 08200000 46100000
|
||||
CHECK-NEXT: 1030 00006578 706f7274 2e746573 742e746d
|
||||
CHECK-NEXT: 1040 702e646c 6c005f65 78706f72 74666e00
|
||||
|
|
Loading…
Reference in New Issue