[llvm] r201760 - llvm-objdump/COFF: Print SEH table addresses.
NAKAMURA Takumi
geek4civic at gmail.com
Thu Feb 20 02:27:54 PST 2014
Ueyama san,
Tweaked in r201769 to appease msvc.
I wonder if I could truncate i64 here...
...Takumi
2014-02-20 15:51 GMT+09:00 Rui Ueyama <ruiu at google.com>:
> Author: ruiu
> Date: Thu Feb 20 00:51:07 2014
> New Revision: 201760
>
> URL: http://llvm.org/viewvc/llvm-project?rev=201760&view=rev
> Log:
> llvm-objdump/COFF: Print SEH table addresses.
>
> SEH table addresses are VA in COFF file. In this patch we convert VA to RVA
> before printing it, because dumpbin prints them as RVAs.
>
> Modified:
> llvm/trunk/include/llvm/Object/COFF.h
> llvm/trunk/lib/Object/COFFObjectFile.cpp
> llvm/trunk/test/tools/llvm-objdump/coff-private-headers.test
> llvm/trunk/tools/llvm-objdump/COFFDump.cpp
>
> Modified: llvm/trunk/include/llvm/Object/COFF.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=201760&r1=201759&r2=201760&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Object/COFF.h (original)
> +++ llvm/trunk/include/llvm/Object/COFF.h Thu Feb 20 00:51:07 2014
> @@ -397,6 +397,7 @@ public:
> error_code getSectionContents(const coff_section *Sec,
> ArrayRef<uint8_t> &Res) const;
>
> + error_code getVaPtr(uint32_t Rva, uintptr_t &Res) const;
> error_code getRvaPtr(uint32_t Rva, uintptr_t &Res) const;
> error_code getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const;
>
>
> Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=201760&r1=201759&r2=201760&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
> +++ llvm/trunk/lib/Object/COFFObjectFile.cpp Thu Feb 20 00:51:07 2014
> @@ -381,15 +381,21 @@ error_code COFFObjectFile::initSymbolTab
> return object_error::success;
> }
>
> +// Returns the file offset for the given VA.
> +error_code COFFObjectFile::getVaPtr(uint32_t Addr, uintptr_t &Res) const {
> + uint32_t ImageBase = PE32Header ? PE32Header->ImageBase : PE32PlusHeader->ImageBase;
> + return getRvaPtr(Addr - ImageBase, Res);
> +}
> +
> // Returns the file offset for the given RVA.
> -error_code COFFObjectFile::getRvaPtr(uint32_t Rva, uintptr_t &Res) const {
> +error_code COFFObjectFile::getRvaPtr(uint32_t Addr, uintptr_t &Res) const {
> for (section_iterator I = section_begin(), E = section_end(); I != E;
> ++I) {
> const coff_section *Section = getCOFFSection(I);
> uint32_t SectionStart = Section->VirtualAddress;
> uint32_t SectionEnd = Section->VirtualAddress + Section->VirtualSize;
> - if (SectionStart <= Rva && Rva < SectionEnd) {
> - uint32_t Offset = Rva - SectionStart;
> + if (SectionStart <= Addr && Addr < SectionEnd) {
> + uint32_t Offset = Addr - SectionStart;
> Res = uintptr_t(base()) + Section->PointerToRawData + Offset;
> return object_error::success;
> }
>
> Modified: llvm/trunk/test/tools/llvm-objdump/coff-private-headers.test
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/coff-private-headers.test?rev=201760&r1=201759&r2=201760&view=diff
> ==============================================================================
> --- llvm/trunk/test/tools/llvm-objdump/coff-private-headers.test (original)
> +++ llvm/trunk/test/tools/llvm-objdump/coff-private-headers.test Thu Feb 20 00:51:07 2014
> @@ -64,3 +64,4 @@ LOADCFG-NEXT: CSD Version: 0
> LOADCFG-NEXT: Security Cookie: 4206616
> LOADCFG-NEXT: SEH Table: 4202768
> LOADCFG-NEXT: SEH Count: 1
> +LOADCFG: SEH Table: 0x401689
>
> Modified: llvm/trunk/tools/llvm-objdump/COFFDump.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/COFFDump.cpp?rev=201760&r1=201759&r2=201760&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-objdump/COFFDump.cpp (original)
> +++ llvm/trunk/tools/llvm-objdump/COFFDump.cpp Thu Feb 20 00:51:07 2014
> @@ -233,6 +233,25 @@ static void printCOFFSymbolAddress(llvm:
> Out << format(" + 0x%04x", Disp);
> }
>
> +static void
> +printSEHTable(const COFFObjectFile *Obj, uint32_t TableVA, int Count) {
> + if (Count == 0)
> + return;
> +
> + const pe32_header *PE32Header;
> + if (error(Obj->getPE32Header(PE32Header)))
> + return;
> + uint32_t ImageBase = PE32Header->ImageBase;
> + uintptr_t IntPtr = 0;
> + if (error(Obj->getVaPtr(TableVA, IntPtr)))
> + return;
> + const support::ulittle32_t *P = (const support::ulittle32_t *)IntPtr;
> + outs() << "SEH Table:";
> + for (int I = 0; I < Count; ++I)
> + outs() << format(" 0x%x", P[I] + ImageBase);
> + outs() << "\n\n";
> +}
> +
> static void printLoadConfiguration(const COFFObjectFile *Obj) {
> const coff_file_header *Header;
> if (error(Obj->getCOFFHeader(Header)))
> @@ -249,6 +268,7 @@ static void printLoadConfiguration(const
> return;
> if (error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr)))
> return;
> +
> const coff_load_configuration32 *LoadConf =
> reinterpret_cast<const coff_load_configuration32 *>(IntPtr);
>
> @@ -271,6 +291,8 @@ static void printLoadConfiguration(const
> << "\n SEH Table: " << LoadConf->SEHandlerTable
> << "\n SEH Count: " << LoadConf->SEHandlerCount
> << "\n\n";
> + printSEHTable(Obj, LoadConf->SEHandlerTable, LoadConf->SEHandlerCount);
> + outs() << "\n";
> }
>
> // Prints import tables. The import table is a table containing the list of
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list