From 9ede5c7dd00b48a1c07d9d08695228a1a68d5c33 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 13 Apr 2014 03:11:08 +0000 Subject: [PATCH] tools: teach objdump about FILE aux records Add support for file auxiliary symbol entries in COFF symbol tables. A COFF symbol table with a FILE entry is followed by sizeof(__FILE__) / 18 auxiliary symbol records which contain the filename. Read them and form the original filename that the record contains. Then display the name in the output. llvm-svn: 206126 --- llvm/include/llvm/Object/COFF.h | 4 +++ .../llvm-objdump/Inputs/file.obj.coff-arm | Bin 0 -> 374 bytes llvm/test/tools/llvm-objdump/coff-file.test | 5 +++ llvm/tools/llvm-objdump/llvm-objdump.cpp | 30 +++++++++++++++--- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100755 llvm/test/tools/llvm-objdump/Inputs/file.obj.coff-arm create mode 100644 llvm/test/tools/llvm-objdump/coff-file.test diff --git a/llvm/include/llvm/Object/COFF.h b/llvm/include/llvm/Object/COFF.h index 26620959d0f0..43dc2c8bda70 100644 --- a/llvm/include/llvm/Object/COFF.h +++ b/llvm/include/llvm/Object/COFF.h @@ -287,6 +287,10 @@ struct coff_aux_weak_external { char Unused[10]; }; +struct coff_aux_file { + char FileName[18]; +}; + struct coff_aux_section_definition { support::ulittle32_t Length; support::ulittle16_t NumberOfRelocations; diff --git a/llvm/test/tools/llvm-objdump/Inputs/file.obj.coff-arm b/llvm/test/tools/llvm-objdump/Inputs/file.obj.coff-arm new file mode 100755 index 0000000000000000000000000000000000000000..a333a87929b68eeb42539ecf1f058eb35a75d7c5 GIT binary patch literal 374 zcmX@Y$jBi1%`^A{0|Nsm5QBhTN@`MRx=JvF$G|WJ$gqKNptJ*nfD;Rl{Sk;efY^h9 zQ4l1hA6lGRRIHzzpIeZZT9l$+o?n!$pOaITt6!2@T%uo+pPy3<=Ia)vCZ^;kW$An7 z6_l0~>!)Srr0N0rK$~m?nVA?EzJQDa18yLxevFa9H#4~?zc@dwL_s4+Q^7IFSHU+C zD5Bt4T%4Mll#^NnRObM)SuZn1{n%NC|Nj{nm>C?>QWHz`3=9N-vJeqHkX>Mt85sTn f)ugjf=IX@aT&QWtA;$<5V`c<}9S9)QfINumberOfSymbols; i != e; ++i) { if (aux_count--) { - // Figure out which type of aux this is. - if (symbol->isSectionDefinition()) { // Section definition. + switch (symbol->StorageClass) { + default: outs() << "AUX Unknown\n"; + case COFF::IMAGE_SYM_CLASS_STATIC: + // Section definition. Follows a symbol-table record that defines a + // section. Such a record has a symbol name that is the name of a + // section and has storage class STATIC (3). + if (symbol->Value) { + errs() << "invalid entry in Symbol Table"; + break; + } + const coff_aux_section_definition *asd; if (error(coff->getAuxSymbol(i, asd))) return; + outs() << "AUX " << format("scnlen 0x%x nreloc %d nlnno %d checksum 0x%x " , unsigned(asd->Length) @@ -683,8 +693,20 @@ static void PrintCOFFSymbolTable(const COFFObjectFile *coff) { << format("assoc %d comdat %d\n" , unsigned(asd->Number) , unsigned(asd->Selection)); - } else - outs() << "AUX Unknown\n"; + break; + case COFF::IMAGE_SYM_CLASS_FILE: + SmallString<261> FileName; + for (unsigned AI = i, AE = i + aux_count + 1; AI < AE; ++AI) { + const coff_aux_file *AF; + if (error(coff->getAuxSymbol(AI, AF))) + return; + FileName.append(&AF->FileName[0], &AF->FileName[18]); + } + outs() << "AUX " << FileName << '\n'; + i = i + aux_count; + aux_count = 0; + break; + } } else { StringRef name; if (error(coff->getSymbol(i, symbol))) return;