[PATCH] llvm-readobj: print COFF imported symbols

Rui Ueyama ruiu at google.com
Thu Oct 2 14:51:51 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 {
----------------
majnemer wrote:
> 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;
> ```
Done.

================
Comment at: include/llvm/Object/COFF.h:182
@@ +181,3 @@
+struct import_lookup_table_entry64 {
+  support::ulittle64_t data;
+
----------------
majnemer wrote:
> `Data`
There's existing code that refers to this field in import_lookup_table_entry32, so I'll rename it in a different patch.

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

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

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

http://reviews.llvm.org/D5586






More information about the llvm-commits mailing list