[PATCH] llvm-readobj: print COFF imported symbols

David Majnemer david.majnemer at gmail.com
Thu Oct 2 14:37:12 PDT 2014


================
Comment at: include/llvm/Object/COFF.h:165-196
@@ -162,18 +164,34 @@
 
 struct import_lookup_table_entry32 {
   support::ulittle32_t data;
 
   bool isOrdinal() const { return data & 0x80000000; }
 
   uint16_t getOrdinal() const {
     assert(isOrdinal() && "ILT entry is not an ordinal!");
     return data & 0xFFFF;
   }
 
   uint32_t getHintNameRVA() const {
     assert(!isOrdinal() && "ILT entry is not a Hint/Name RVA!");
     return data;
   }
 };
 
+struct import_lookup_table_entry64 {
+  support::ulittle64_t data;
+
+  bool isOrdinal() const { return data & (uint64_t(1) << 62); }
+
+  uint16_t getOrdinal() const {
+    assert(isOrdinal() && "ILT entry is not an ordinal!");
+    return data & 0xFFFF;
+  }
+
+  uint32_t getHintNameRVA() const {
+    assert(!isOrdinal() && "ILT entry is not a Hint/Name RVA!");
+    return data & 0xFFFFFFFF;
+  }
+};
+
 struct export_directory_table_entry {
----------------
As we discussed, the following might be a better approach:

```
template <typename IntTy>
struct import_lookup_table_entry {
  IntTy Data;

  bool isOrdinal() const { return Data < 0; }

  uint16_t getOrdinal() const {
    assert(isOrdinal() && "ILT entry is not an ordinal!");
    return static_cast<uint16_t>(Data);
  }

  uint32_t getHintNameRVA() const {
    assert(!isOrdinal() && "ILT entry is not a Hint/Name RVA!");
    return static_cast<uint32_t>(Data);
  }
}

typedef import_lookup_table_entry<support::slittle32_t> import_lookup_table_entry32;
typedef import_lookup_table_entry<support::slittle64_t> import_lookup_table_entry64;
```

================
Comment at: include/llvm/Object/COFF.h:182
@@ +181,3 @@
+struct import_lookup_table_entry64 {
+  support::ulittle64_t data;
+
----------------
`Data`

================
Comment at: include/llvm/Object/COFF.h:184
@@ +183,3 @@
+
+  bool isOrdinal() const { return data & (uint64_t(1) << 62); }
+
----------------
This should probably be 63, not 62.  It's probably better to just make `data` signed.

================
Comment at: lib/Object/COFFObjectFile.cpp:1062
@@ +1061,3 @@
+  if (OwningObject->getBytesInAddress() == 4) {
+    uint32_t *Entry = reinterpret_cast<uint32_t *>(IntPtr);
+    while (*Entry++)
----------------
This should be a little endian cast.

================
Comment at: lib/Object/COFFObjectFile.cpp:1066
@@ +1065,3 @@
+  } else {
+    uint64_t *Entry = reinterpret_cast<uint64_t *>(IntPtr);
+    while (*Entry++)
----------------
Here too.

================
Comment at: tools/llvm-readobj/COFFDumper.cpp:898-899
@@ -897,1 +897,4 @@
     W.printHex("ImportAddressTableRVA", Addr);
+    for (auto J = I->imported_symbol_begin(), F = I->imported_symbol_end();
+         J != F; ++J) {
+      StringRef Sym;
----------------
Range iterator would be nice here too.

http://reviews.llvm.org/D5586






More information about the llvm-commits mailing list