diff options
| author | Rui Ueyama <ruiu@google.com> | 2014-01-27 03:53:23 +0000 | 
|---|---|---|
| committer | Rui Ueyama <ruiu@google.com> | 2014-01-27 03:53:23 +0000 | 
| commit | f1a2d55e2bcb147a10b430b5ed3a9776762d5aeb (patch) | |
| tree | e2f65ee0d38b580f8fb06ad80d39b35df8c1c2ab | |
| parent | 3d8de47f76529dba40fc34d497576d9cb51330bc (diff) | |
| download | bcm5719-llvm-f1a2d55e2bcb147a10b430b5ed3a9776762d5aeb.tar.gz bcm5719-llvm-f1a2d55e2bcb147a10b430b5ed3a9776762d5aeb.zip  | |
[PECOFF] Set a proper architecture type to references.
Relocations for x64 object files should have reference type of
KindArch::x86_64.
llvm-svn: 200183
| -rw-r--r-- | lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp | 28 | 
1 files changed, 27 insertions, 1 deletions
diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index c0dd9105883..81c733950de 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -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<MemoryBuffer> mb, error_code &ec)  }  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 coff_relocation *rel,    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.  | 

