diff options
author | Rui Ueyama <ruiu@google.com> | 2014-10-07 22:20:21 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2014-10-07 22:20:21 +0000 |
commit | 8951520c23bad817730f7ed8cc290bcd308b81a4 (patch) | |
tree | b45fc259ed5636f2173563262010d9b5e2c1470a | |
parent | 29551955a9227812848656b95451ec6dd824690b (diff) | |
download | bcm5719-llvm-8951520c23bad817730f7ed8cc290bcd308b81a4.tar.gz bcm5719-llvm-8951520c23bad817730f7ed8cc290bcd308b81a4.zip |
[PECOFF] Remove yet another use of _is64
No functionality change intended.
llvm-svn: 219246
-rw-r--r-- | lld/lib/ReaderWriter/PECOFF/EdataPass.cpp | 12 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/PECOFF/IdataPass.cpp | 28 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/PECOFF/IdataPass.h | 34 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp | 2 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/PECOFF/Pass.cpp | 34 | ||||
-rw-r--r-- | lld/lib/ReaderWriter/PECOFF/Pass.h | 9 |
6 files changed, 65 insertions, 54 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp b/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp index 14f291f237d..73449f0b984 100644 --- a/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp +++ b/lld/lib/ReaderWriter/PECOFF/EdataPass.cpp @@ -93,7 +93,7 @@ EdataPass::createAddressTable(const std::vector<TableEntry> &entries, for (const TableEntry &e : entries) { int index = e.ordinal - ordinalBase; size_t offset = index * sizeof(export_address_table_entry); - addDir32NBReloc(addressTable, e.atom, _is64, offset); + addDir32NBReloc(addressTable, e.atom, _ctx.getMachineType(), offset); } return addressTable; } @@ -110,7 +110,7 @@ EdataPass::createNamePointerTable(const PECOFFLinkingContext &ctx, auto *stringAtom = new (_alloc) COFFStringAtom( _file, _stringOrdinal++, ".edata", ctx.undecorateSymbol(e.exportName)); file->addAtom(*stringAtom); - addDir32NBReloc(table, stringAtom, _is64, offset); + addDir32NBReloc(table, stringAtom, _ctx.getMachineType(), offset); offset += sizeof(uint32_t); } return table; @@ -166,25 +166,25 @@ void EdataPass::perform(std::unique_ptr<MutableFile> &file) { new (_alloc) COFFStringAtom(_file, _stringOrdinal++, ".edata", llvm::sys::path::filename(_ctx.outputPath())); file->addAtom(*dllName); - addDir32NBReloc(table, dllName, _is64, + addDir32NBReloc(table, dllName, _ctx.getMachineType(), offsetof(export_directory_table_entry, NameRVA)); EdataAtom *addressTable = createAddressTable(entries, ordinalBase, maxOrdinal); file->addAtom(*addressTable); addDir32NBReloc( - table, addressTable, _is64, + table, addressTable, _ctx.getMachineType(), offsetof(export_directory_table_entry, ExportAddressTableRVA)); EdataAtom *namePointerTable = createNamePointerTable(_ctx, namedEntries, file.get()); file->addAtom(*namePointerTable); - addDir32NBReloc(table, namePointerTable, _is64, + addDir32NBReloc(table, namePointerTable, _ctx.getMachineType(), offsetof(export_directory_table_entry, NamePointerRVA)); EdataAtom *ordinalTable = createOrdinalTable(namedEntries, ordinalBase); file->addAtom(*ordinalTable); - addDir32NBReloc(table, ordinalTable, _is64, + addDir32NBReloc(table, ordinalTable, _ctx.getMachineType(), offsetof(export_directory_table_entry, OrdinalTableRVA)); } diff --git a/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp b/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp index 2145b803c93..92e2238ce40 100644 --- a/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp +++ b/lld/lib/ReaderWriter/PECOFF/IdataPass.cpp @@ -26,14 +26,13 @@ namespace lld { namespace pecoff { namespace idata { -IdataAtom::IdataAtom(Context &context, std::vector<uint8_t> data) +IdataAtom::IdataAtom(IdataContext &context, std::vector<uint8_t> data) : COFFLinkerInternalAtom(context.dummyFile, - context.dummyFile.getNextOrdinal(), data), - _is64(context.is64) { + context.dummyFile.getNextOrdinal(), data) { context.file.addAtom(*this); } -HintNameAtom::HintNameAtom(Context &context, uint16_t hint, +HintNameAtom::HintNameAtom(IdataContext &context, uint16_t hint, StringRef importName) : IdataAtom(context, assembleRawContent(hint, importName)), _importName(importName) {} @@ -68,7 +67,7 @@ ImportTableEntryAtom::assembleRawContent(uint64_t rva, bool is64) { // array of pointers to hint/name atoms. The array needs to be terminated with // the NULL entry. void ImportDirectoryAtom::addRelocations( - Context &context, StringRef loadName, + IdataContext &context, StringRef loadName, const std::vector<COFFSharedLibraryAtom *> &sharedAtoms) { // Create parallel arrays. The contents of the two are initially the // same. The PE/COFF loader overwrites the import address tables with the @@ -79,20 +78,21 @@ void ImportDirectoryAtom::addRelocations( std::vector<ImportTableEntryAtom *> importAddressTables = createImportTableAtoms(context, sharedAtoms, true, ".idata.a"); - addDir32NBReloc(this, importLookupTables[0], _is64, + addDir32NBReloc(this, importLookupTables[0], context.ctx.getMachineType(), offsetof(ImportDirectoryTableEntry, ImportLookupTableRVA)); - addDir32NBReloc(this, importAddressTables[0], _is64, + addDir32NBReloc(this, importAddressTables[0], context.ctx.getMachineType(), offsetof(ImportDirectoryTableEntry, ImportAddressTableRVA)); auto *atom = new (_alloc) COFFStringAtom(context.dummyFile, context.dummyFile.getNextOrdinal(), ".idata", loadName); context.file.addAtom(*atom); - addDir32NBReloc(this, atom, _is64, + addDir32NBReloc(this, atom, context.ctx.getMachineType(), offsetof(ImportDirectoryTableEntry, NameRVA)); } std::vector<ImportTableEntryAtom *> ImportDirectoryAtom::createImportTableAtoms( - Context &context, const std::vector<COFFSharedLibraryAtom *> &sharedAtoms, + IdataContext &context, + const std::vector<COFFSharedLibraryAtom *> &sharedAtoms, bool shouldAddReference, StringRef sectionName) const { std::vector<ImportTableEntryAtom *> ret; for (COFFSharedLibraryAtom *atom : sharedAtoms) { @@ -100,14 +100,14 @@ std::vector<ImportTableEntryAtom *> ImportDirectoryAtom::createImportTableAtoms( if (atom->importName().empty()) { // Import by ordinal uint64_t hint = atom->hint(); - hint |= _is64 ? (uint64_t(1) << 63) : (uint64_t(1) << 31); + hint |= context.ctx.is64Bit() ? (uint64_t(1) << 63) : (uint64_t(1) << 31); entry = new (_alloc) ImportTableEntryAtom(context, hint, sectionName); } else { // Import by name entry = new (_alloc) ImportTableEntryAtom(context, 0, sectionName); HintNameAtom *hintName = new (_alloc) HintNameAtom(context, atom->hint(), atom->importName()); - addDir32NBReloc(entry, hintName, _is64, 0); + addDir32NBReloc(entry, hintName, context.ctx.getMachineType(), 0); } ret.push_back(entry); if (shouldAddReference) @@ -124,8 +124,8 @@ void IdataPass::perform(std::unique_ptr<MutableFile> &file) { if (file->sharedLibrary().empty()) return; - idata::Context context(*file, _dummyFile, _is64); - std::map<StringRef, std::vector<COFFSharedLibraryAtom *> > sharedAtoms = + idata::IdataContext context(*file, _dummyFile, _ctx); + std::map<StringRef, std::vector<COFFSharedLibraryAtom *>> sharedAtoms = groupByLoadName(*file); for (auto i : sharedAtoms) { StringRef loadName = i.first; @@ -155,7 +155,7 @@ IdataPass::groupByLoadName(MutableFile &file) { } /// Transforms a reference to a COFFSharedLibraryAtom to a real reference. -void IdataPass::replaceSharedLibraryAtoms(idata::Context &context) { +void IdataPass::replaceSharedLibraryAtoms(idata::IdataContext &context) { for (const DefinedAtom *atom : context.file.defined()) { for (const Reference *ref : *atom) { const Atom *target = ref->target(); diff --git a/lld/lib/ReaderWriter/PECOFF/IdataPass.h b/lld/lib/ReaderWriter/PECOFF/IdataPass.h index 5fac74dc2cb..1558bfad490 100644 --- a/lld/lib/ReaderWriter/PECOFF/IdataPass.h +++ b/lld/lib/ReaderWriter/PECOFF/IdataPass.h @@ -41,12 +41,12 @@ class HintNameAtom; class ImportTableEntryAtom; // A state object of this pass. -struct Context { - Context(MutableFile &f, VirtualFile &g, bool peplus) - : file(f), dummyFile(g), is64(peplus) {} +struct IdataContext { + IdataContext(MutableFile &f, VirtualFile &g, const PECOFFLinkingContext &c) + : file(f), dummyFile(g), ctx(c) {} MutableFile &file; VirtualFile &dummyFile; - bool is64; + const PECOFFLinkingContext &ctx; }; /// The root class of all idata atoms. @@ -58,8 +58,7 @@ public: ContentPermissions permissions() const override { return permR__; } protected: - IdataAtom(Context &context, std::vector<uint8_t> data); - bool _is64; + IdataAtom(IdataContext &context, std::vector<uint8_t> data); }; /// A HintNameAtom represents a symbol that will be imported from a DLL at @@ -72,7 +71,7 @@ protected: /// loader can find the symbol quickly. class HintNameAtom : public IdataAtom { public: - HintNameAtom(Context &context, uint16_t hint, StringRef importName); + HintNameAtom(IdataContext &context, uint16_t hint, StringRef importName); StringRef getContentString() { return _importName; } @@ -83,8 +82,9 @@ private: class ImportTableEntryAtom : public IdataAtom { public: - ImportTableEntryAtom(Context &ctx, uint64_t contents, StringRef sectionName) - : IdataAtom(ctx, assembleRawContent(contents, ctx.is64)), + ImportTableEntryAtom(IdataContext &ctx, uint64_t contents, + StringRef sectionName) + : IdataAtom(ctx, assembleRawContent(contents, ctx.ctx.is64Bit())), _sectionName(sectionName) {} StringRef customSectionName() const override { @@ -102,7 +102,7 @@ private: /// items. The executable has one ImportDirectoryAtom per one imported DLL. class ImportDirectoryAtom : public IdataAtom { public: - ImportDirectoryAtom(Context &context, StringRef loadName, + ImportDirectoryAtom(IdataContext &context, StringRef loadName, const std::vector<COFFSharedLibraryAtom *> &sharedAtoms) : IdataAtom(context, std::vector<uint8_t>(20, 0)) { addRelocations(context, loadName, sharedAtoms); @@ -111,11 +111,12 @@ public: StringRef customSectionName() const override { return ".idata.d"; } private: - void addRelocations(Context &context, StringRef loadName, + void addRelocations(IdataContext &context, StringRef loadName, const std::vector<COFFSharedLibraryAtom *> &sharedAtoms); std::vector<ImportTableEntryAtom *> createImportTableAtoms( - Context &context, const std::vector<COFFSharedLibraryAtom *> &sharedAtoms, + IdataContext &context, + const std::vector<COFFSharedLibraryAtom *> &sharedAtoms, bool shouldAddReference, StringRef sectionName) const; mutable llvm::BumpPtrAllocator _alloc; @@ -124,7 +125,7 @@ private: /// The last NULL entry in the import directory. class NullImportDirectoryAtom : public IdataAtom { public: - explicit NullImportDirectoryAtom(Context &context) + explicit NullImportDirectoryAtom(IdataContext &context) : IdataAtom(context, std::vector<uint8_t>(20, 0)) {} StringRef customSectionName() const override { return ".idata.d"; } @@ -134,8 +135,7 @@ public: class IdataPass : public lld::Pass { public: - IdataPass(const PECOFFLinkingContext &ctx) - : _dummyFile(ctx), _is64(ctx.is64Bit()) {} + IdataPass(const PECOFFLinkingContext &ctx) : _dummyFile(ctx), _ctx(ctx) {} void perform(std::unique_ptr<MutableFile> &file) override; @@ -143,14 +143,14 @@ private: std::map<StringRef, std::vector<COFFSharedLibraryAtom *> > groupByLoadName(MutableFile &file); - void replaceSharedLibraryAtoms(idata::Context &context); + void replaceSharedLibraryAtoms(idata::IdataContext &context); // A dummy file with which all the atoms created in the pass will be // associated. Atoms need to be associated to an input file even if it's not // read from a file, so we use this object. VirtualFile _dummyFile; - bool _is64; + const PECOFFLinkingContext &_ctx; llvm::BumpPtrAllocator _alloc; }; diff --git a/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp b/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp index ab87fafa7df..9dbe13d538b 100644 --- a/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp +++ b/lld/lib/ReaderWriter/PECOFF/LoadConfigPass.cpp @@ -43,7 +43,7 @@ LoadConfigAtom::LoadConfigAtom(VirtualFile &file, const DefinedAtom *sxdata, file, file.getNextOrdinal(), std::vector<uint8_t>(sizeof(coff_load_configuration32))) { addDir32Reloc( - this, sxdata, false, + this, sxdata, llvm::COFF::IMAGE_FILE_MACHINE_I386, offsetof(llvm::object::coff_load_configuration32, SEHandlerTable)); auto *data = getContents<llvm::object::coff_load_configuration32>(); data->SEHandlerCount = count; diff --git a/lld/lib/ReaderWriter/PECOFF/Pass.cpp b/lld/lib/ReaderWriter/PECOFF/Pass.cpp index 2b2f90624fd..cb31e44f7df 100644 --- a/lld/lib/ReaderWriter/PECOFF/Pass.cpp +++ b/lld/lib/ReaderWriter/PECOFF/Pass.cpp @@ -23,25 +23,35 @@ static void addReloc(COFFBaseDefinedAtom *atom, const Atom *target, atom->addReference(std::unique_ptr<COFFReference>(ref)); } -void addDir32Reloc(COFFBaseDefinedAtom *atom, const Atom *target, bool is64, - size_t offsetInAtom) { - if (is64) { - addReloc(atom, target, offsetInAtom, Reference::KindArch::x86_64, - llvm::COFF::IMAGE_REL_AMD64_ADDR32); - } else { +void addDir32Reloc(COFFBaseDefinedAtom *atom, const Atom *target, + llvm::COFF::MachineTypes machine, size_t offsetInAtom) { + switch (machine) { + case llvm::COFF::IMAGE_FILE_MACHINE_I386: addReloc(atom, target, offsetInAtom, Reference::KindArch::x86, llvm::COFF::IMAGE_REL_I386_DIR32); + return; + case llvm::COFF::IMAGE_FILE_MACHINE_AMD64: + addReloc(atom, target, offsetInAtom, Reference::KindArch::x86_64, + llvm::COFF::IMAGE_REL_AMD64_ADDR32); + return; + default: + llvm_unreachable("unsupported machine type"); } } -void addDir32NBReloc(COFFBaseDefinedAtom *atom, const Atom *target, bool is64, - size_t offsetInAtom) { - if (is64) { - addReloc(atom, target, offsetInAtom, Reference::KindArch::x86_64, - llvm::COFF::IMAGE_REL_AMD64_ADDR32NB); - } else { +void addDir32NBReloc(COFFBaseDefinedAtom *atom, const Atom *target, + llvm::COFF::MachineTypes machine, size_t offsetInAtom) { + switch (machine) { + case llvm::COFF::IMAGE_FILE_MACHINE_I386: addReloc(atom, target, offsetInAtom, Reference::KindArch::x86, llvm::COFF::IMAGE_REL_I386_DIR32NB); + return; + case llvm::COFF::IMAGE_FILE_MACHINE_AMD64: + addReloc(atom, target, offsetInAtom, Reference::KindArch::x86_64, + llvm::COFF::IMAGE_REL_AMD64_ADDR32NB); + return; + default: + llvm_unreachable("unsupported machine type"); } } diff --git a/lld/lib/ReaderWriter/PECOFF/Pass.h b/lld/lib/ReaderWriter/PECOFF/Pass.h index a0a6057ecde..e0cdee3e8a3 100644 --- a/lld/lib/ReaderWriter/PECOFF/Pass.h +++ b/lld/lib/ReaderWriter/PECOFF/Pass.h @@ -11,15 +11,16 @@ #define LLD_READER_WRITER_PE_COFF_PASS_H #include "Atoms.h" +#include "llvm/Support/COFF.h" namespace lld { namespace pecoff { -void addDir32Reloc(COFFBaseDefinedAtom *atom, const Atom *target, bool is64, - size_t offsetInAtom); +void addDir32Reloc(COFFBaseDefinedAtom *atom, const Atom *target, + llvm::COFF::MachineTypes machine, size_t offsetInAtom); -void addDir32NBReloc(COFFBaseDefinedAtom *atom, const Atom *target, bool is64, - size_t offsetInAtom); +void addDir32NBReloc(COFFBaseDefinedAtom *atom, const Atom *target, + llvm::COFF::MachineTypes machine, size_t offsetInAtom); } // namespace pecoff } // namespace lld |