[lld] r200183 - [PECOFF] Set a proper architecture type to references.
Rui Ueyama
ruiu at google.com
Sun Jan 26 19:53:23 PST 2014
Author: ruiu
Date: Sun Jan 26 21:53:23 2014
New Revision: 200183
URL: http://llvm.org/viewvc/llvm-project?rev=200183&view=rev
Log:
[PECOFF] Set a proper architecture type to references.
Relocations for x64 object files should have reference type of
KindArch::x86_64.
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=200183&r1=200182&r2=200183&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Sun Jan 26 21:53:23 2014
@@ -119,6 +119,7 @@ private:
const coff_section *section,
const vector<COFFDefinedFileAtom *> &atoms);
+ error_code getReferenceArch(Reference::KindArch &result);
error_code addRelocationReferenceToAtoms();
error_code findSection(StringRef name, const coff_section *&result);
StringRef ArrayRefToString(ArrayRef<uint8_t> array);
@@ -129,6 +130,9 @@ private:
atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
+ // The target type of the object.
+ Reference::KindArch _referenceArch;
+
// The contents of .drectve section.
StringRef _directives;
@@ -278,6 +282,9 @@ FileCOFF::FileCOFF(std::unique_ptr<Memor
}
error_code FileCOFF::parse(StringMap &altNames) {
+ if (error_code ec = getReferenceArch(_referenceArch))
+ return ec;
+
// Read the symbol table and atomize them if possible. Defined atoms
// cannot be atomized in one pass, so they will be not be atomized but
// added to symbolToAtom.
@@ -712,10 +719,29 @@ FileCOFF::addRelocationReference(const c
if (error_code ec = findAtomAt(section, itemAddress, atom, offsetInAtom))
return ec;
atom->addReference(std::unique_ptr<COFFReference>(
- new COFFReference(targetAtom, offsetInAtom, rel->Type)));
+ new COFFReference(targetAtom, offsetInAtom, rel->Type,
+ Reference::KindNamespace::COFF,
+ _referenceArch)));
return error_code::success();
}
+/// Returns the target machine type of the current object file.
+error_code FileCOFF::getReferenceArch(Reference::KindArch &result) {
+ const llvm::object::coff_file_header *header = nullptr;
+ if (error_code ec = _obj->getHeader(header))
+ return ec;
+ switch (header->Machine) {
+ case llvm::COFF::IMAGE_FILE_MACHINE_I386:
+ result = Reference::KindArch::x86;
+ return error_code::success();
+ case llvm::COFF::IMAGE_FILE_MACHINE_AMD64:
+ result = Reference::KindArch::x86_64;
+ return error_code::success();
+ }
+ llvm::errs() << "Unsupported machine type: " << header->Machine << "\n";
+ return llvm::object::object_error::parse_failed;
+}
+
/// Add relocation information to atoms.
error_code FileCOFF::addRelocationReferenceToAtoms() {
// Relocation entries are defined for each section.
More information about the llvm-commits
mailing list