[PATCH] D31362: [llvm-readobj] Prefer ILT to IAT for reading COFF imports

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 18:15:34 PDT 2017


smeenai created this revision.

We're seeing binutils ld produce binaries where the import address
table's NameRVA entry is actually a VA instead (i.e. it's already base
relocated), which llvm-readobj then chokes on. Both dumpbin and the
Windows loader are able to handle these binaries correctly, however, and
we can make llvm-readobj handle them correctly too by iterating the
import lookup table (which doesn't have a relocated NameRVA) rather than
the import address table.

The import lookup table and the import address table are supposed to be
identical on disk, and prior to r277298 the import lookup table would be
used by `llvm-readobj -coff-imports` anyway, so this shouldn't have any
functional change (except in the case of our malformed binaries). The
import lookup table can apparently be missing when using old Borland
linkers, so fall back to the import address table in that case.

Resolves PR31766.


https://reviews.llvm.org/D31362

Files:
  tools/llvm-readobj/COFFDumper.cpp


Index: tools/llvm-readobj/COFFDumper.cpp
===================================================================
--- tools/llvm-readobj/COFFDumper.cpp
+++ tools/llvm-readobj/COFFDumper.cpp
@@ -1439,12 +1439,18 @@
     StringRef Name;
     error(I.getName(Name));
     W.printString("Name", Name);
-    uint32_t Addr;
-    error(I.getImportLookupTableRVA(Addr));
-    W.printHex("ImportLookupTableRVA", Addr);
-    error(I.getImportAddressTableRVA(Addr));
-    W.printHex("ImportAddressTableRVA", Addr);
-    printImportedSymbols(I.imported_symbols());
+    uint32_t ImportLookupTableAddr;
+    error(I.getImportLookupTableRVA(ImportLookupTableAddr));
+    W.printHex("ImportLookupTableRVA", ImportLookupTableAddr);
+    uint32_t ImportAddressTableAddr;
+    error(I.getImportAddressTableRVA(ImportAddressTableAddr));
+    W.printHex("ImportAddressTableRVA", ImportAddressTableAddr);
+    // The import lookup table can be missing with certain older linkers, so
+    // fall back to the import address table in that case.
+    if (ImportLookupTableAddr)
+      printImportedSymbols(I.lookup_table_symbols());
+    else
+      printImportedSymbols(I.imported_symbols());
   }
 
   // Delay imports


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31362.93028.patch
Type: text/x-patch
Size: 1192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170325/917cc4c8/attachment.bin>


More information about the llvm-commits mailing list