[PATCH] Move machine type auto-detection to SymbolTable.

Rui Ueyama ruiu at google.com
Fri May 29 12:17:28 PDT 2015


LGTM with following change.

I first thought that it's invalid if all files are archive, but then realized that that's valid.
An object file defining an entry point function can be in an archive.


================
Comment at: COFF/SymbolTable.cpp:174-184
@@ -173,2 +173,13 @@
 
+llvm::COFF::MachineTypes SymbolTable::getInferredMachineType() {
+  for (std::unique_ptr<ObjectFile> &File : ObjectFiles) {
+    // Try to infer machine type from the magic byte of the object file.
+    auto MT =
+        static_cast<llvm::COFF::MachineTypes>(File->getCOFFObj()->getMachine());
+    if (MT != llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN)
+      return MT;
+  }
+  return llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
+}
+
 } // namespace coff
----------------
I'd make this a non-member function in Writer.cpp which takes vector<unique_ptr<ObjectFile>>& as a parameter, as this function is not that related to symbol resolution. It feels that it belongs Writer. Maybe you need to expose ObjectFiles, but that's fine.

And in the Writer, you can return Config->MachineType as a default value instead of UNKNOWN.

http://reviews.llvm.org/D10136

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list