Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 1 | //===-- COFFDump.cpp - COFF-specific dumper ---------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
| 11 | /// \brief This file implements the COFF-specific dumper for llvm-objdump. |
| 12 | /// It outputs the Win64 EH data structures as plain text. |
Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 13 | /// The encoding of the unwind codes is described in MSDN: |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 14 | /// http://msdn.microsoft.com/en-us/library/ck9asaa9.aspx |
| 15 | /// |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | #include "llvm-objdump.h" |
| 19 | #include "llvm/Object/COFF.h" |
| 20 | #include "llvm/Object/ObjectFile.h" |
| 21 | #include "llvm/Support/Format.h" |
| 22 | #include "llvm/Support/SourceMgr.h" |
Chandler Carruth | b034cb7 | 2013-01-02 10:26:28 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Win64EH.h" |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 25 | #include <algorithm> |
| 26 | #include <cstring> |
Rafael Espindola | a6e9c3e | 2014-06-12 17:38:55 +0000 | [diff] [blame] | 27 | #include <system_error> |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 28 | |
| 29 | using namespace llvm; |
| 30 | using namespace object; |
| 31 | using namespace llvm::Win64EH; |
| 32 | |
| 33 | // Returns the name of the unwind code. |
| 34 | static StringRef getUnwindCodeTypeName(uint8_t Code) { |
| 35 | switch(Code) { |
| 36 | default: llvm_unreachable("Invalid unwind code"); |
| 37 | case UOP_PushNonVol: return "UOP_PushNonVol"; |
| 38 | case UOP_AllocLarge: return "UOP_AllocLarge"; |
| 39 | case UOP_AllocSmall: return "UOP_AllocSmall"; |
| 40 | case UOP_SetFPReg: return "UOP_SetFPReg"; |
| 41 | case UOP_SaveNonVol: return "UOP_SaveNonVol"; |
| 42 | case UOP_SaveNonVolBig: return "UOP_SaveNonVolBig"; |
| 43 | case UOP_SaveXMM128: return "UOP_SaveXMM128"; |
| 44 | case UOP_SaveXMM128Big: return "UOP_SaveXMM128Big"; |
| 45 | case UOP_PushMachFrame: return "UOP_PushMachFrame"; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // Returns the name of a referenced register. |
| 50 | static StringRef getUnwindRegisterName(uint8_t Reg) { |
| 51 | switch(Reg) { |
| 52 | default: llvm_unreachable("Invalid register"); |
| 53 | case 0: return "RAX"; |
| 54 | case 1: return "RCX"; |
| 55 | case 2: return "RDX"; |
| 56 | case 3: return "RBX"; |
| 57 | case 4: return "RSP"; |
| 58 | case 5: return "RBP"; |
| 59 | case 6: return "RSI"; |
| 60 | case 7: return "RDI"; |
| 61 | case 8: return "R8"; |
| 62 | case 9: return "R9"; |
| 63 | case 10: return "R10"; |
| 64 | case 11: return "R11"; |
| 65 | case 12: return "R12"; |
| 66 | case 13: return "R13"; |
| 67 | case 14: return "R14"; |
| 68 | case 15: return "R15"; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Calculates the number of array slots required for the unwind code. |
| 73 | static unsigned getNumUsedSlots(const UnwindCode &UnwindCode) { |
| 74 | switch (UnwindCode.getUnwindOp()) { |
| 75 | default: llvm_unreachable("Invalid unwind code"); |
| 76 | case UOP_PushNonVol: |
| 77 | case UOP_AllocSmall: |
| 78 | case UOP_SetFPReg: |
| 79 | case UOP_PushMachFrame: |
| 80 | return 1; |
| 81 | case UOP_SaveNonVol: |
| 82 | case UOP_SaveXMM128: |
| 83 | return 2; |
| 84 | case UOP_SaveNonVolBig: |
| 85 | case UOP_SaveXMM128Big: |
| 86 | return 3; |
| 87 | case UOP_AllocLarge: |
| 88 | return (UnwindCode.getOpInfo() == 0) ? 2 : 3; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // Prints one unwind code. Because an unwind code can occupy up to 3 slots in |
| 93 | // the unwind codes array, this function requires that the correct number of |
| 94 | // slots is provided. |
| 95 | static void printUnwindCode(ArrayRef<UnwindCode> UCs) { |
| 96 | assert(UCs.size() >= getNumUsedSlots(UCs[0])); |
Rui Ueyama | 595932f | 2014-03-04 19:23:56 +0000 | [diff] [blame] | 97 | outs() << format(" 0x%02x: ", unsigned(UCs[0].u.CodeOffset)) |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 98 | << getUnwindCodeTypeName(UCs[0].getUnwindOp()); |
| 99 | switch (UCs[0].getUnwindOp()) { |
| 100 | case UOP_PushNonVol: |
| 101 | outs() << " " << getUnwindRegisterName(UCs[0].getOpInfo()); |
| 102 | break; |
| 103 | case UOP_AllocLarge: |
| 104 | if (UCs[0].getOpInfo() == 0) { |
| 105 | outs() << " " << UCs[1].FrameOffset; |
| 106 | } else { |
| 107 | outs() << " " << UCs[1].FrameOffset |
| 108 | + (static_cast<uint32_t>(UCs[2].FrameOffset) << 16); |
| 109 | } |
| 110 | break; |
| 111 | case UOP_AllocSmall: |
| 112 | outs() << " " << ((UCs[0].getOpInfo() + 1) * 8); |
| 113 | break; |
| 114 | case UOP_SetFPReg: |
| 115 | outs() << " "; |
| 116 | break; |
| 117 | case UOP_SaveNonVol: |
| 118 | outs() << " " << getUnwindRegisterName(UCs[0].getOpInfo()) |
| 119 | << format(" [0x%04x]", 8 * UCs[1].FrameOffset); |
| 120 | break; |
| 121 | case UOP_SaveNonVolBig: |
| 122 | outs() << " " << getUnwindRegisterName(UCs[0].getOpInfo()) |
| 123 | << format(" [0x%08x]", UCs[1].FrameOffset |
| 124 | + (static_cast<uint32_t>(UCs[2].FrameOffset) << 16)); |
| 125 | break; |
| 126 | case UOP_SaveXMM128: |
| 127 | outs() << " XMM" << static_cast<uint32_t>(UCs[0].getOpInfo()) |
| 128 | << format(" [0x%04x]", 16 * UCs[1].FrameOffset); |
| 129 | break; |
| 130 | case UOP_SaveXMM128Big: |
| 131 | outs() << " XMM" << UCs[0].getOpInfo() |
| 132 | << format(" [0x%08x]", UCs[1].FrameOffset |
| 133 | + (static_cast<uint32_t>(UCs[2].FrameOffset) << 16)); |
| 134 | break; |
| 135 | case UOP_PushMachFrame: |
| 136 | outs() << " " << (UCs[0].getOpInfo() ? "w/o" : "w") |
| 137 | << " error code"; |
| 138 | break; |
| 139 | } |
| 140 | outs() << "\n"; |
| 141 | } |
| 142 | |
| 143 | static void printAllUnwindCodes(ArrayRef<UnwindCode> UCs) { |
| 144 | for (const UnwindCode *I = UCs.begin(), *E = UCs.end(); I < E; ) { |
| 145 | unsigned UsedSlots = getNumUsedSlots(*I); |
| 146 | if (UsedSlots > UCs.size()) { |
| 147 | outs() << "Unwind data corrupted: Encountered unwind op " |
| 148 | << getUnwindCodeTypeName((*I).getUnwindOp()) |
| 149 | << " which requires " << UsedSlots |
| 150 | << " slots, but only " << UCs.size() |
| 151 | << " remaining in buffer"; |
| 152 | return ; |
| 153 | } |
Craig Topper | 0013be1 | 2015-09-21 05:32:41 +0000 | [diff] [blame] | 154 | printUnwindCode(makeArrayRef(I, E)); |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 155 | I += UsedSlots; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // Given a symbol sym this functions returns the address and section of it. |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 160 | static std::error_code |
| 161 | resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym, |
| 162 | const coff_section *&ResolvedSection, |
| 163 | uint64_t &ResolvedAddr) { |
Rafael Espindola | ed067c4 | 2015-07-03 18:19:00 +0000 | [diff] [blame] | 164 | ErrorOr<uint64_t> ResolvedAddrOrErr = Sym.getAddress(); |
| 165 | if (std::error_code EC = ResolvedAddrOrErr.getError()) |
Rui Ueyama | ef8dede | 2014-01-16 20:57:55 +0000 | [diff] [blame] | 166 | return EC; |
Rafael Espindola | ed067c4 | 2015-07-03 18:19:00 +0000 | [diff] [blame] | 167 | ResolvedAddr = *ResolvedAddrOrErr; |
Rafael Espindola | 8bab889 | 2015-08-07 23:27:14 +0000 | [diff] [blame] | 168 | ErrorOr<section_iterator> Iter = Sym.getSection(); |
| 169 | if (std::error_code EC = Iter.getError()) |
Rui Ueyama | ef8dede | 2014-01-16 20:57:55 +0000 | [diff] [blame] | 170 | return EC; |
Rafael Espindola | 8bab889 | 2015-08-07 23:27:14 +0000 | [diff] [blame] | 171 | ResolvedSection = Obj->getCOFFSection(**Iter); |
Rui Ueyama | 7d09919 | 2015-06-09 15:20:42 +0000 | [diff] [blame] | 172 | return std::error_code(); |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // Given a vector of relocations for a section and an offset into this section |
| 176 | // the function returns the symbol used for the relocation at the offset. |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 177 | static std::error_code resolveSymbol(const std::vector<RelocationRef> &Rels, |
| 178 | uint64_t Offset, SymbolRef &Sym) { |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 179 | for (std::vector<RelocationRef>::const_iterator I = Rels.begin(), |
| 180 | E = Rels.end(); |
| 181 | I != E; ++I) { |
Rafael Espindola | 96d071c | 2015-06-29 23:29:12 +0000 | [diff] [blame] | 182 | uint64_t Ofs = I->getOffset(); |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 183 | if (Ofs == Offset) { |
Rafael Espindola | 806f006 | 2013-06-05 01:33:53 +0000 | [diff] [blame] | 184 | Sym = *I->getSymbol(); |
Rui Ueyama | 7d09919 | 2015-06-09 15:20:42 +0000 | [diff] [blame] | 185 | return std::error_code(); |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
Rui Ueyama | cf39784 | 2014-02-28 05:21:29 +0000 | [diff] [blame] | 188 | return object_error::parse_failed; |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Given a vector of relocations for a section and an offset into this section |
| 192 | // the function resolves the symbol used for the relocation at the offset and |
| 193 | // returns the section content and the address inside the content pointed to |
| 194 | // by the symbol. |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 195 | static std::error_code |
| 196 | getSectionContents(const COFFObjectFile *Obj, |
| 197 | const std::vector<RelocationRef> &Rels, uint64_t Offset, |
| 198 | ArrayRef<uint8_t> &Contents, uint64_t &Addr) { |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 199 | SymbolRef Sym; |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 200 | if (std::error_code EC = resolveSymbol(Rels, Offset, Sym)) |
Rui Ueyama | 1618fe2 | 2014-02-28 05:21:26 +0000 | [diff] [blame] | 201 | return EC; |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 202 | const coff_section *Section; |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 203 | if (std::error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr)) |
Rui Ueyama | ef8dede | 2014-01-16 20:57:55 +0000 | [diff] [blame] | 204 | return EC; |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 205 | if (std::error_code EC = Obj->getSectionContents(Section, Contents)) |
Rui Ueyama | ef8dede | 2014-01-16 20:57:55 +0000 | [diff] [blame] | 206 | return EC; |
Rui Ueyama | 7d09919 | 2015-06-09 15:20:42 +0000 | [diff] [blame] | 207 | return std::error_code(); |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | // Given a vector of relocations for a section and an offset into this section |
| 211 | // the function returns the name of the symbol used for the relocation at the |
| 212 | // offset. |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 213 | static std::error_code resolveSymbolName(const std::vector<RelocationRef> &Rels, |
| 214 | uint64_t Offset, StringRef &Name) { |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 215 | SymbolRef Sym; |
Rafael Espindola | 4453e4294 | 2014-06-13 03:07:50 +0000 | [diff] [blame] | 216 | if (std::error_code EC = resolveSymbol(Rels, Offset, Sym)) |
Rui Ueyama | ef8dede | 2014-01-16 20:57:55 +0000 | [diff] [blame] | 217 | return EC; |
Kevin Enderby | 81e8b7d | 2016-04-20 21:24:34 +0000 | [diff] [blame^] | 218 | Expected<StringRef> NameOrErr = Sym.getName(); |
| 219 | if (!NameOrErr) |
| 220 | return errorToErrorCode(NameOrErr.takeError()); |
Rafael Espindola | 5d0c2ff | 2015-07-02 20:55:21 +0000 | [diff] [blame] | 221 | Name = *NameOrErr; |
Rui Ueyama | 7d09919 | 2015-06-09 15:20:42 +0000 | [diff] [blame] | 222 | return std::error_code(); |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static void printCOFFSymbolAddress(llvm::raw_ostream &Out, |
| 226 | const std::vector<RelocationRef> &Rels, |
| 227 | uint64_t Offset, uint32_t Disp) { |
| 228 | StringRef Sym; |
Rui Ueyama | cf39784 | 2014-02-28 05:21:29 +0000 | [diff] [blame] | 229 | if (!resolveSymbolName(Rels, Offset, Sym)) { |
| 230 | Out << Sym; |
| 231 | if (Disp > 0) |
| 232 | Out << format(" + 0x%04x", Disp); |
| 233 | } else { |
| 234 | Out << format("0x%04x", Disp); |
| 235 | } |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Rui Ueyama | 215a586 | 2014-02-20 06:51:07 +0000 | [diff] [blame] | 238 | static void |
| 239 | printSEHTable(const COFFObjectFile *Obj, uint32_t TableVA, int Count) { |
| 240 | if (Count == 0) |
| 241 | return; |
| 242 | |
| 243 | const pe32_header *PE32Header; |
Davide Italiano | ccd53fe | 2015-08-05 07:18:31 +0000 | [diff] [blame] | 244 | error(Obj->getPE32Header(PE32Header)); |
Rui Ueyama | 215a586 | 2014-02-20 06:51:07 +0000 | [diff] [blame] | 245 | uint32_t ImageBase = PE32Header->ImageBase; |
| 246 | uintptr_t IntPtr = 0; |
Davide Italiano | ccd53fe | 2015-08-05 07:18:31 +0000 | [diff] [blame] | 247 | error(Obj->getVaPtr(TableVA, IntPtr)); |
Rui Ueyama | 215a586 | 2014-02-20 06:51:07 +0000 | [diff] [blame] | 248 | const support::ulittle32_t *P = (const support::ulittle32_t *)IntPtr; |
| 249 | outs() << "SEH Table:"; |
| 250 | for (int I = 0; I < Count; ++I) |
| 251 | outs() << format(" 0x%x", P[I] + ImageBase); |
| 252 | outs() << "\n\n"; |
| 253 | } |
| 254 | |
David Majnemer | 0ab61bf | 2016-03-15 06:14:01 +0000 | [diff] [blame] | 255 | template <typename T> |
| 256 | static void printTLSDirectoryT(const coff_tls_directory<T> *TLSDir) { |
| 257 | size_t FormatWidth = sizeof(T) * 2; |
| 258 | outs() << "TLS directory:" |
| 259 | << "\n StartAddressOfRawData: " |
| 260 | << format_hex(TLSDir->StartAddressOfRawData, FormatWidth) |
| 261 | << "\n EndAddressOfRawData: " |
| 262 | << format_hex(TLSDir->EndAddressOfRawData, FormatWidth) |
| 263 | << "\n AddressOfIndex: " |
| 264 | << format_hex(TLSDir->AddressOfIndex, FormatWidth) |
| 265 | << "\n AddressOfCallBacks: " |
| 266 | << format_hex(TLSDir->AddressOfCallBacks, FormatWidth) |
| 267 | << "\n SizeOfZeroFill: " |
| 268 | << TLSDir->SizeOfZeroFill |
| 269 | << "\n Characteristics: " |
| 270 | << TLSDir->Characteristics |
| 271 | << "\n Alignment: " |
| 272 | << TLSDir->getAlignment() |
| 273 | << "\n\n"; |
| 274 | } |
| 275 | |
| 276 | static void printTLSDirectory(const COFFObjectFile *Obj) { |
| 277 | const pe32_header *PE32Header; |
| 278 | error(Obj->getPE32Header(PE32Header)); |
| 279 | |
| 280 | const pe32plus_header *PE32PlusHeader; |
| 281 | error(Obj->getPE32PlusHeader(PE32PlusHeader)); |
| 282 | |
| 283 | // Skip if it's not executable. |
| 284 | if (!PE32Header && !PE32PlusHeader) |
| 285 | return; |
| 286 | |
| 287 | const data_directory *DataDir; |
| 288 | error(Obj->getDataDirectory(COFF::TLS_TABLE, DataDir)); |
| 289 | uintptr_t IntPtr = 0; |
| 290 | if (DataDir->RelativeVirtualAddress == 0) |
| 291 | return; |
| 292 | error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr)); |
| 293 | |
| 294 | if (PE32Header) { |
| 295 | auto *TLSDir = reinterpret_cast<const coff_tls_directory32 *>(IntPtr); |
| 296 | printTLSDirectoryT(TLSDir); |
| 297 | } else { |
| 298 | auto *TLSDir = reinterpret_cast<const coff_tls_directory64 *>(IntPtr); |
| 299 | printTLSDirectoryT(TLSDir); |
| 300 | } |
| 301 | |
| 302 | outs() << "\n"; |
| 303 | } |
| 304 | |
Rui Ueyama | c514a80 | 2014-02-19 03:53:11 +0000 | [diff] [blame] | 305 | static void printLoadConfiguration(const COFFObjectFile *Obj) { |
Rui Ueyama | 5cf3285 | 2014-02-21 20:27:15 +0000 | [diff] [blame] | 306 | // Skip if it's not executable. |
| 307 | const pe32_header *PE32Header; |
Davide Italiano | ccd53fe | 2015-08-05 07:18:31 +0000 | [diff] [blame] | 308 | error(Obj->getPE32Header(PE32Header)); |
Rui Ueyama | 5cf3285 | 2014-02-21 20:27:15 +0000 | [diff] [blame] | 309 | if (!PE32Header) |
| 310 | return; |
| 311 | |
Rui Ueyama | c514a80 | 2014-02-19 03:53:11 +0000 | [diff] [blame] | 312 | // Currently only x86 is supported |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 313 | if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_I386) |
Rui Ueyama | c514a80 | 2014-02-19 03:53:11 +0000 | [diff] [blame] | 314 | return; |
| 315 | |
| 316 | const data_directory *DataDir; |
Davide Italiano | ccd53fe | 2015-08-05 07:18:31 +0000 | [diff] [blame] | 317 | error(Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir)); |
Rui Ueyama | c514a80 | 2014-02-19 03:53:11 +0000 | [diff] [blame] | 318 | uintptr_t IntPtr = 0; |
| 319 | if (DataDir->RelativeVirtualAddress == 0) |
| 320 | return; |
Davide Italiano | ccd53fe | 2015-08-05 07:18:31 +0000 | [diff] [blame] | 321 | error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr)); |
Rui Ueyama | 215a586 | 2014-02-20 06:51:07 +0000 | [diff] [blame] | 322 | |
Rui Ueyama | 8c1d4c9 | 2014-03-04 04:15:59 +0000 | [diff] [blame] | 323 | auto *LoadConf = reinterpret_cast<const coff_load_configuration32 *>(IntPtr); |
Rui Ueyama | c514a80 | 2014-02-19 03:53:11 +0000 | [diff] [blame] | 324 | outs() << "Load configuration:" |
| 325 | << "\n Timestamp: " << LoadConf->TimeDateStamp |
| 326 | << "\n Major Version: " << LoadConf->MajorVersion |
| 327 | << "\n Minor Version: " << LoadConf->MinorVersion |
| 328 | << "\n GlobalFlags Clear: " << LoadConf->GlobalFlagsClear |
| 329 | << "\n GlobalFlags Set: " << LoadConf->GlobalFlagsSet |
| 330 | << "\n Critical Section Default Timeout: " << LoadConf->CriticalSectionDefaultTimeout |
| 331 | << "\n Decommit Free Block Threshold: " << LoadConf->DeCommitFreeBlockThreshold |
| 332 | << "\n Decommit Total Free Threshold: " << LoadConf->DeCommitTotalFreeThreshold |
| 333 | << "\n Lock Prefix Table: " << LoadConf->LockPrefixTable |
| 334 | << "\n Maximum Allocation Size: " << LoadConf->MaximumAllocationSize |
| 335 | << "\n Virtual Memory Threshold: " << LoadConf->VirtualMemoryThreshold |
| 336 | << "\n Process Affinity Mask: " << LoadConf->ProcessAffinityMask |
| 337 | << "\n Process Heap Flags: " << LoadConf->ProcessHeapFlags |
| 338 | << "\n CSD Version: " << LoadConf->CSDVersion |
| 339 | << "\n Security Cookie: " << LoadConf->SecurityCookie |
| 340 | << "\n SEH Table: " << LoadConf->SEHandlerTable |
| 341 | << "\n SEH Count: " << LoadConf->SEHandlerCount |
| 342 | << "\n\n"; |
Rui Ueyama | 215a586 | 2014-02-20 06:51:07 +0000 | [diff] [blame] | 343 | printSEHTable(Obj, LoadConf->SEHandlerTable, LoadConf->SEHandlerCount); |
| 344 | outs() << "\n"; |
Rui Ueyama | c514a80 | 2014-02-19 03:53:11 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Rui Ueyama | c2bed42 | 2013-09-27 21:04:00 +0000 | [diff] [blame] | 347 | // Prints import tables. The import table is a table containing the list of |
| 348 | // DLL name and symbol names which will be linked by the loader. |
| 349 | static void printImportTables(const COFFObjectFile *Obj) { |
Rui Ueyama | ef8dede | 2014-01-16 20:57:55 +0000 | [diff] [blame] | 350 | import_directory_iterator I = Obj->import_directory_begin(); |
| 351 | import_directory_iterator E = Obj->import_directory_end(); |
| 352 | if (I == E) |
Rui Ueyama | 908dfcd | 2014-01-15 23:46:18 +0000 | [diff] [blame] | 353 | return; |
Rui Ueyama | c2bed42 | 2013-09-27 21:04:00 +0000 | [diff] [blame] | 354 | outs() << "The Import Tables:\n"; |
Rafael Espindola | 5e812af | 2014-01-30 02:49:50 +0000 | [diff] [blame] | 355 | for (; I != E; I = ++I) { |
Rui Ueyama | c2bed42 | 2013-09-27 21:04:00 +0000 | [diff] [blame] | 356 | const import_directory_table_entry *Dir; |
| 357 | StringRef Name; |
Rui Ueyama | ef8dede | 2014-01-16 20:57:55 +0000 | [diff] [blame] | 358 | if (I->getImportTableEntry(Dir)) return; |
| 359 | if (I->getName(Name)) return; |
Rui Ueyama | c2bed42 | 2013-09-27 21:04:00 +0000 | [diff] [blame] | 360 | |
| 361 | outs() << format(" lookup %08x time %08x fwd %08x name %08x addr %08x\n\n", |
| 362 | static_cast<uint32_t>(Dir->ImportLookupTableRVA), |
| 363 | static_cast<uint32_t>(Dir->TimeDateStamp), |
| 364 | static_cast<uint32_t>(Dir->ForwarderChain), |
| 365 | static_cast<uint32_t>(Dir->NameRVA), |
| 366 | static_cast<uint32_t>(Dir->ImportAddressTableRVA)); |
| 367 | outs() << " DLL Name: " << Name << "\n"; |
| 368 | outs() << " Hint/Ord Name\n"; |
| 369 | const import_lookup_table_entry32 *entry; |
Rui Ueyama | ef8dede | 2014-01-16 20:57:55 +0000 | [diff] [blame] | 370 | if (I->getImportLookupEntry(entry)) |
Rui Ueyama | c2bed42 | 2013-09-27 21:04:00 +0000 | [diff] [blame] | 371 | return; |
Rui Ueyama | 350fe8e | 2014-10-02 22:13:44 +0000 | [diff] [blame] | 372 | for (; entry->Data; ++entry) { |
Rui Ueyama | c2bed42 | 2013-09-27 21:04:00 +0000 | [diff] [blame] | 373 | if (entry->isOrdinal()) { |
| 374 | outs() << format(" % 6d\n", entry->getOrdinal()); |
| 375 | continue; |
| 376 | } |
| 377 | uint16_t Hint; |
| 378 | StringRef Name; |
| 379 | if (Obj->getHintName(entry->getHintNameRVA(), Hint, Name)) |
| 380 | return; |
| 381 | outs() << format(" % 6d ", Hint) << Name << "\n"; |
| 382 | } |
| 383 | outs() << "\n"; |
| 384 | } |
| 385 | } |
| 386 | |
Rui Ueyama | ad882ba | 2014-01-16 07:05:49 +0000 | [diff] [blame] | 387 | // Prints export tables. The export table is a table containing the list of |
| 388 | // exported symbol from the DLL. |
| 389 | static void printExportTable(const COFFObjectFile *Obj) { |
| 390 | outs() << "Export Table:\n"; |
| 391 | export_directory_iterator I = Obj->export_directory_begin(); |
| 392 | export_directory_iterator E = Obj->export_directory_end(); |
| 393 | if (I == E) |
| 394 | return; |
Rui Ueyama | da49d0d | 2014-01-16 20:50:34 +0000 | [diff] [blame] | 395 | StringRef DllName; |
Rui Ueyama | e5df609 | 2014-01-17 22:02:24 +0000 | [diff] [blame] | 396 | uint32_t OrdinalBase; |
Rui Ueyama | da49d0d | 2014-01-16 20:50:34 +0000 | [diff] [blame] | 397 | if (I->getDllName(DllName)) |
| 398 | return; |
Rui Ueyama | e5df609 | 2014-01-17 22:02:24 +0000 | [diff] [blame] | 399 | if (I->getOrdinalBase(OrdinalBase)) |
| 400 | return; |
Rui Ueyama | da49d0d | 2014-01-16 20:50:34 +0000 | [diff] [blame] | 401 | outs() << " DLL name: " << DllName << "\n"; |
Rui Ueyama | e5df609 | 2014-01-17 22:02:24 +0000 | [diff] [blame] | 402 | outs() << " Ordinal base: " << OrdinalBase << "\n"; |
Rui Ueyama | ad882ba | 2014-01-16 07:05:49 +0000 | [diff] [blame] | 403 | outs() << " Ordinal RVA Name\n"; |
Rafael Espindola | 5e812af | 2014-01-30 02:49:50 +0000 | [diff] [blame] | 404 | for (; I != E; I = ++I) { |
Rui Ueyama | ad882ba | 2014-01-16 07:05:49 +0000 | [diff] [blame] | 405 | uint32_t Ordinal; |
| 406 | if (I->getOrdinal(Ordinal)) |
| 407 | return; |
| 408 | uint32_t RVA; |
| 409 | if (I->getExportRVA(RVA)) |
| 410 | return; |
Rui Ueyama | 6161b38 | 2016-01-12 23:28:42 +0000 | [diff] [blame] | 411 | bool IsForwarder; |
| 412 | if (I->isForwarder(IsForwarder)) |
| 413 | return; |
| 414 | |
| 415 | if (IsForwarder) { |
| 416 | // Export table entries can be used to re-export symbols that |
| 417 | // this COFF file is imported from some DLLs. This is rare. |
| 418 | // In most cases IsForwarder is false. |
| 419 | outs() << format(" % 4d ", Ordinal); |
| 420 | } else { |
| 421 | outs() << format(" % 4d %# 8x", Ordinal, RVA); |
| 422 | } |
Rui Ueyama | ad882ba | 2014-01-16 07:05:49 +0000 | [diff] [blame] | 423 | |
| 424 | StringRef Name; |
Rui Ueyama | da49d0d | 2014-01-16 20:50:34 +0000 | [diff] [blame] | 425 | if (I->getSymbolName(Name)) |
Rui Ueyama | ad882ba | 2014-01-16 07:05:49 +0000 | [diff] [blame] | 426 | continue; |
| 427 | if (!Name.empty()) |
| 428 | outs() << " " << Name; |
Rui Ueyama | 6161b38 | 2016-01-12 23:28:42 +0000 | [diff] [blame] | 429 | if (IsForwarder) { |
| 430 | StringRef S; |
| 431 | if (I->getForwardTo(S)) |
| 432 | return; |
| 433 | outs() << " (forwarded to " << S << ")"; |
| 434 | } |
Rui Ueyama | ad882ba | 2014-01-16 07:05:49 +0000 | [diff] [blame] | 435 | outs() << "\n"; |
| 436 | } |
| 437 | } |
| 438 | |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 439 | // Given the COFF object file, this function returns the relocations for .pdata |
| 440 | // and the pointer to "runtime function" structs. |
| 441 | static bool getPDataSection(const COFFObjectFile *Obj, |
| 442 | std::vector<RelocationRef> &Rels, |
| 443 | const RuntimeFunction *&RFStart, int &NumRFs) { |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 444 | for (const SectionRef &Section : Obj->sections()) { |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 445 | StringRef Name; |
Davide Italiano | ccd53fe | 2015-08-05 07:18:31 +0000 | [diff] [blame] | 446 | error(Section.getName(Name)); |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 447 | if (Name != ".pdata") |
| 448 | continue; |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 449 | |
Alexey Samsonov | 27dc839 | 2014-03-18 06:53:02 +0000 | [diff] [blame] | 450 | const coff_section *Pdata = Obj->getCOFFSection(Section); |
| 451 | for (const RelocationRef &Reloc : Section.relocations()) |
Alexey Samsonov | aa4d295 | 2014-03-14 14:22:49 +0000 | [diff] [blame] | 452 | Rels.push_back(Reloc); |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 453 | |
| 454 | // Sort relocations by address. |
| 455 | std::sort(Rels.begin(), Rels.end(), RelocAddressLess); |
| 456 | |
| 457 | ArrayRef<uint8_t> Contents; |
Davide Italiano | ccd53fe | 2015-08-05 07:18:31 +0000 | [diff] [blame] | 458 | error(Obj->getSectionContents(Pdata, Contents)); |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 459 | if (Contents.empty()) |
| 460 | continue; |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 461 | |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 462 | RFStart = reinterpret_cast<const RuntimeFunction *>(Contents.data()); |
| 463 | NumRFs = Contents.size() / sizeof(RuntimeFunction); |
| 464 | return true; |
| 465 | } |
| 466 | return false; |
| 467 | } |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 468 | |
Rui Ueyama | 6dfd4e1 | 2014-03-04 03:08:45 +0000 | [diff] [blame] | 469 | static void printWin64EHUnwindInfo(const Win64EH::UnwindInfo *UI) { |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 470 | // The casts to int are required in order to output the value as number. |
| 471 | // Without the casts the value would be interpreted as char data (which |
| 472 | // results in garbage output). |
Rui Ueyama | 595932f | 2014-03-04 19:23:56 +0000 | [diff] [blame] | 473 | outs() << " Version: " << static_cast<int>(UI->getVersion()) << "\n"; |
| 474 | outs() << " Flags: " << static_cast<int>(UI->getFlags()); |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 475 | if (UI->getFlags()) { |
| 476 | if (UI->getFlags() & UNW_ExceptionHandler) |
| 477 | outs() << " UNW_ExceptionHandler"; |
| 478 | if (UI->getFlags() & UNW_TerminateHandler) |
| 479 | outs() << " UNW_TerminateHandler"; |
| 480 | if (UI->getFlags() & UNW_ChainInfo) |
| 481 | outs() << " UNW_ChainInfo"; |
| 482 | } |
| 483 | outs() << "\n"; |
Rui Ueyama | 595932f | 2014-03-04 19:23:56 +0000 | [diff] [blame] | 484 | outs() << " Size of prolog: " << static_cast<int>(UI->PrologSize) << "\n"; |
| 485 | outs() << " Number of Codes: " << static_cast<int>(UI->NumCodes) << "\n"; |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 486 | // Maybe this should move to output of UOP_SetFPReg? |
| 487 | if (UI->getFrameRegister()) { |
Rui Ueyama | 595932f | 2014-03-04 19:23:56 +0000 | [diff] [blame] | 488 | outs() << " Frame register: " |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 489 | << getUnwindRegisterName(UI->getFrameRegister()) << "\n"; |
Rui Ueyama | 595932f | 2014-03-04 19:23:56 +0000 | [diff] [blame] | 490 | outs() << " Frame offset: " << 16 * UI->getFrameOffset() << "\n"; |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 491 | } else { |
Rui Ueyama | 595932f | 2014-03-04 19:23:56 +0000 | [diff] [blame] | 492 | outs() << " No frame pointer used\n"; |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 493 | } |
| 494 | if (UI->getFlags() & (UNW_ExceptionHandler | UNW_TerminateHandler)) { |
| 495 | // FIXME: Output exception handler data |
| 496 | } else if (UI->getFlags() & UNW_ChainInfo) { |
| 497 | // FIXME: Output chained unwind info |
| 498 | } |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 499 | |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 500 | if (UI->NumCodes) |
Rui Ueyama | 595932f | 2014-03-04 19:23:56 +0000 | [diff] [blame] | 501 | outs() << " Unwind Codes:\n"; |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 502 | |
Craig Topper | 0013be1 | 2015-09-21 05:32:41 +0000 | [diff] [blame] | 503 | printAllUnwindCodes(makeArrayRef(&UI->UnwindCodes[0], UI->NumCodes)); |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 504 | |
Rui Ueyama | 595932f | 2014-03-04 19:23:56 +0000 | [diff] [blame] | 505 | outs() << "\n"; |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 506 | outs().flush(); |
| 507 | } |
| 508 | |
Rui Ueyama | fd3cb9e | 2014-03-04 04:22:41 +0000 | [diff] [blame] | 509 | /// Prints out the given RuntimeFunction struct for x64, assuming that Obj is |
Rui Ueyama | 9c674e6 | 2014-03-04 04:00:55 +0000 | [diff] [blame] | 510 | /// pointing to an executable file. |
Rui Ueyama | 6dfd4e1 | 2014-03-04 03:08:45 +0000 | [diff] [blame] | 511 | static void printRuntimeFunction(const COFFObjectFile *Obj, |
Rui Ueyama | 9c674e6 | 2014-03-04 04:00:55 +0000 | [diff] [blame] | 512 | const RuntimeFunction &RF) { |
| 513 | if (!RF.StartAddress) |
| 514 | return; |
| 515 | outs() << "Function Table:\n" |
Rui Ueyama | ad80765 | 2014-03-05 23:03:37 +0000 | [diff] [blame] | 516 | << format(" Start Address: 0x%04x\n", |
| 517 | static_cast<uint32_t>(RF.StartAddress)) |
| 518 | << format(" End Address: 0x%04x\n", |
| 519 | static_cast<uint32_t>(RF.EndAddress)) |
| 520 | << format(" Unwind Info Address: 0x%04x\n", |
| 521 | static_cast<uint32_t>(RF.UnwindInfoOffset)); |
Rui Ueyama | 9c674e6 | 2014-03-04 04:00:55 +0000 | [diff] [blame] | 522 | uintptr_t addr; |
| 523 | if (Obj->getRvaPtr(RF.UnwindInfoOffset, addr)) |
| 524 | return; |
| 525 | printWin64EHUnwindInfo(reinterpret_cast<const Win64EH::UnwindInfo *>(addr)); |
| 526 | } |
| 527 | |
Rui Ueyama | fd3cb9e | 2014-03-04 04:22:41 +0000 | [diff] [blame] | 528 | /// Prints out the given RuntimeFunction struct for x64, assuming that Obj is |
| 529 | /// pointing to an object file. Unlike executable, fields in RuntimeFunction |
Rui Ueyama | 9c674e6 | 2014-03-04 04:00:55 +0000 | [diff] [blame] | 530 | /// struct are filled with zeros, but instead there are relocations pointing to |
| 531 | /// them so that the linker will fill targets' RVAs to the fields at link |
| 532 | /// time. This function interprets the relocations to find the data to be used |
| 533 | /// in the resulting executable. |
| 534 | static void printRuntimeFunctionRels(const COFFObjectFile *Obj, |
| 535 | const RuntimeFunction &RF, |
| 536 | uint64_t SectionOffset, |
| 537 | const std::vector<RelocationRef> &Rels) { |
Rui Ueyama | 6dfd4e1 | 2014-03-04 03:08:45 +0000 | [diff] [blame] | 538 | outs() << "Function Table:\n"; |
| 539 | outs() << " Start Address: "; |
| 540 | printCOFFSymbolAddress(outs(), Rels, |
| 541 | SectionOffset + |
| 542 | /*offsetof(RuntimeFunction, StartAddress)*/ 0, |
| 543 | RF.StartAddress); |
| 544 | outs() << "\n"; |
| 545 | |
| 546 | outs() << " End Address: "; |
| 547 | printCOFFSymbolAddress(outs(), Rels, |
| 548 | SectionOffset + |
| 549 | /*offsetof(RuntimeFunction, EndAddress)*/ 4, |
| 550 | RF.EndAddress); |
| 551 | outs() << "\n"; |
| 552 | |
| 553 | outs() << " Unwind Info Address: "; |
| 554 | printCOFFSymbolAddress(outs(), Rels, |
| 555 | SectionOffset + |
| 556 | /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8, |
| 557 | RF.UnwindInfoOffset); |
| 558 | outs() << "\n"; |
| 559 | |
| 560 | ArrayRef<uint8_t> XContents; |
| 561 | uint64_t UnwindInfoOffset = 0; |
Davide Italiano | ccd53fe | 2015-08-05 07:18:31 +0000 | [diff] [blame] | 562 | error(getSectionContents( |
Rui Ueyama | 6dfd4e1 | 2014-03-04 03:08:45 +0000 | [diff] [blame] | 563 | Obj, Rels, SectionOffset + |
| 564 | /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8, |
Davide Italiano | ccd53fe | 2015-08-05 07:18:31 +0000 | [diff] [blame] | 565 | XContents, UnwindInfoOffset)); |
Rui Ueyama | 6dfd4e1 | 2014-03-04 03:08:45 +0000 | [diff] [blame] | 566 | if (XContents.empty()) |
| 567 | return; |
| 568 | |
| 569 | UnwindInfoOffset += RF.UnwindInfoOffset; |
| 570 | if (UnwindInfoOffset > XContents.size()) |
| 571 | return; |
| 572 | |
Rui Ueyama | 8c1d4c9 | 2014-03-04 04:15:59 +0000 | [diff] [blame] | 573 | auto *UI = reinterpret_cast<const Win64EH::UnwindInfo *>(XContents.data() + |
| 574 | UnwindInfoOffset); |
Rui Ueyama | 6dfd4e1 | 2014-03-04 03:08:45 +0000 | [diff] [blame] | 575 | printWin64EHUnwindInfo(UI); |
| 576 | } |
| 577 | |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 578 | void llvm::printCOFFUnwindInfo(const COFFObjectFile *Obj) { |
David Majnemer | 44f51e5 | 2014-09-10 12:51:52 +0000 | [diff] [blame] | 579 | if (Obj->getMachine() != COFF::IMAGE_FILE_MACHINE_AMD64) { |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 580 | errs() << "Unsupported image machine type " |
| 581 | "(currently only AMD64 is supported).\n"; |
| 582 | return; |
| 583 | } |
| 584 | |
| 585 | std::vector<RelocationRef> Rels; |
| 586 | const RuntimeFunction *RFStart; |
| 587 | int NumRFs; |
| 588 | if (!getPDataSection(Obj, Rels, RFStart, NumRFs)) |
| 589 | return; |
| 590 | ArrayRef<RuntimeFunction> RFs(RFStart, NumRFs); |
| 591 | |
Rui Ueyama | 9c674e6 | 2014-03-04 04:00:55 +0000 | [diff] [blame] | 592 | bool IsExecutable = Rels.empty(); |
| 593 | if (IsExecutable) { |
| 594 | for (const RuntimeFunction &RF : RFs) |
| 595 | printRuntimeFunction(Obj, RF); |
| 596 | return; |
| 597 | } |
| 598 | |
Rui Ueyama | 39f1b97 | 2014-03-04 00:31:48 +0000 | [diff] [blame] | 599 | for (const RuntimeFunction &RF : RFs) { |
| 600 | uint64_t SectionOffset = |
| 601 | std::distance(RFs.begin(), &RF) * sizeof(RuntimeFunction); |
Rui Ueyama | 9c674e6 | 2014-03-04 04:00:55 +0000 | [diff] [blame] | 602 | printRuntimeFunctionRels(Obj, RF, SectionOffset, Rels); |
Michael J. Spencer | 0c6ec48 | 2012-12-05 20:12:35 +0000 | [diff] [blame] | 603 | } |
| 604 | } |
Rui Ueyama | c2bed42 | 2013-09-27 21:04:00 +0000 | [diff] [blame] | 605 | |
| 606 | void llvm::printCOFFFileHeader(const object::ObjectFile *Obj) { |
Rui Ueyama | ad882ba | 2014-01-16 07:05:49 +0000 | [diff] [blame] | 607 | const COFFObjectFile *file = dyn_cast<const COFFObjectFile>(Obj); |
David Majnemer | 0ab61bf | 2016-03-15 06:14:01 +0000 | [diff] [blame] | 608 | printTLSDirectory(file); |
Rui Ueyama | c514a80 | 2014-02-19 03:53:11 +0000 | [diff] [blame] | 609 | printLoadConfiguration(file); |
Rui Ueyama | ad882ba | 2014-01-16 07:05:49 +0000 | [diff] [blame] | 610 | printImportTables(file); |
| 611 | printExportTable(file); |
Rui Ueyama | c2bed42 | 2013-09-27 21:04:00 +0000 | [diff] [blame] | 612 | } |
Davide Italiano | e85abf7 | 2015-12-20 09:54:34 +0000 | [diff] [blame] | 613 | |
| 614 | void llvm::printCOFFSymbolTable(const COFFObjectFile *coff) { |
| 615 | for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) { |
| 616 | ErrorOr<COFFSymbolRef> Symbol = coff->getSymbol(SI); |
| 617 | StringRef Name; |
| 618 | error(Symbol.getError()); |
| 619 | error(coff->getSymbolName(*Symbol, Name)); |
| 620 | |
| 621 | outs() << "[" << format("%2d", SI) << "]" |
| 622 | << "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")" |
| 623 | << "(fl 0x00)" // Flag bits, which COFF doesn't have. |
| 624 | << "(ty " << format("%3x", unsigned(Symbol->getType())) << ")" |
| 625 | << "(scl " << format("%3x", unsigned(Symbol->getStorageClass())) << ") " |
| 626 | << "(nx " << unsigned(Symbol->getNumberOfAuxSymbols()) << ") " |
| 627 | << "0x" << format("%08x", unsigned(Symbol->getValue())) << " " |
| 628 | << Name << "\n"; |
| 629 | |
| 630 | for (unsigned AI = 0, AE = Symbol->getNumberOfAuxSymbols(); AI < AE; ++AI, ++SI) { |
| 631 | if (Symbol->isSectionDefinition()) { |
| 632 | const coff_aux_section_definition *asd; |
| 633 | error(coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd)); |
| 634 | |
| 635 | int32_t AuxNumber = asd->getNumber(Symbol->isBigObj()); |
| 636 | |
| 637 | outs() << "AUX " |
| 638 | << format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x " |
| 639 | , unsigned(asd->Length) |
| 640 | , unsigned(asd->NumberOfRelocations) |
| 641 | , unsigned(asd->NumberOfLinenumbers) |
| 642 | , unsigned(asd->CheckSum)) |
| 643 | << format("assoc %d comdat %d\n" |
| 644 | , unsigned(AuxNumber) |
| 645 | , unsigned(asd->Selection)); |
| 646 | } else if (Symbol->isFileRecord()) { |
| 647 | const char *FileName; |
| 648 | error(coff->getAuxSymbol<char>(SI + 1, FileName)); |
| 649 | |
| 650 | StringRef Name(FileName, Symbol->getNumberOfAuxSymbols() * |
| 651 | coff->getSymbolTableEntrySize()); |
| 652 | outs() << "AUX " << Name.rtrim(StringRef("\0", 1)) << '\n'; |
| 653 | |
| 654 | SI = SI + Symbol->getNumberOfAuxSymbols(); |
| 655 | break; |
| 656 | } else { |
| 657 | outs() << "AUX Unknown\n"; |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | } |