diff options
author | Rui Ueyama <ruiu@google.com> | 2015-07-09 22:54:13 +0300 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2015-07-09 22:54:13 +0300 |
commit | ea533cde30df7b9941b27606168e0664344f580d (patch) | |
tree | 56dbcffc7c2a0f5edafb7ecb9474223d3c9571c6 /lld/COFF/InputFiles.cpp | |
parent | 594e676cbe475dc879980e919731c3614aa083eb (diff) |
COFF: Infer machine type earlier than before.
Previously, we infer machine type at the very end of linking after
all symbols are resolved. That's actually too late because machine
type affects how we mangle symbols (whether or not we need to
add "_").
For example, /entry:foo adds "_foo" to the symbol table if x86 but
"foo" if x64.
This patch moves the code to infer machine type, so that machine
type is inferred based on input files given via the command line
(but not based on .directives files).
llvm-svn: 241843
Diffstat (limited to 'lld/COFF/InputFiles.cpp')
-rw-r--r-- | lld/COFF/InputFiles.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index a0211623f62d..cbc239388863 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -24,8 +24,9 @@ using namespace llvm::COFF; using namespace llvm::object; using namespace llvm::support::endian; using llvm::RoundUpToAlignment; -using llvm::sys::fs::identify_magic; +using llvm::Triple; using llvm::sys::fs::file_magic; +using llvm::sys::fs::identify_magic; namespace lld { namespace coff { @@ -242,6 +243,12 @@ Defined *ObjectFile::createDefined(COFFSymbolRef Sym, const void *AuxP, return B; } +MachineTypes ObjectFile::getMachineType() { + if (COFFObj) + return static_cast<MachineTypes>(COFFObj->getMachine()); + return IMAGE_FILE_MACHINE_UNKNOWN; +} + std::error_code ImportFile::parse() { const char *Buf = MB.getBufferStart(); const char *End = MB.getBufferEnd(); @@ -319,5 +326,20 @@ std::error_code BitcodeFile::parse() { return std::error_code(); } +MachineTypes BitcodeFile::getMachineType() { + if (!M) + return IMAGE_FILE_MACHINE_UNKNOWN; + switch (Triple(M->getTargetTriple()).getArch()) { + case Triple::x86_64: + return IMAGE_FILE_MACHINE_AMD64; + case Triple::x86: + return IMAGE_FILE_MACHINE_I386; + case Triple::arm: + return IMAGE_FILE_MACHINE_ARMNT; + default: + return IMAGE_FILE_MACHINE_UNKNOWN; + } +} + } // namespace coff } // namespace lld |