[llvm] r243755 - [COFF] Return symbol VAs instead of RVAs for PE files

Reid Kleckner reid at kleckner.net
Fri Jul 31 09:14:23 PDT 2015


Author: rnk
Date: Fri Jul 31 11:14:22 2015
New Revision: 243755

URL: http://llvm.org/viewvc/llvm-project?rev=243755&view=rev
Log:
[COFF] Return symbol VAs instead of RVAs for PE files

This makes llvm-nm consistent with binutils nm on executables and DLLs.
For a vanilla hello world executable, the address of main should include
the default image base of 0x400000.

Added:
    llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.dll   (with props)
    llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.exe   (with props)
    llvm/trunk/test/Object/nm-pe-image.test
Modified:
    llvm/trunk/lib/Object/COFFObjectFile.cpp

Modified: llvm/trunk/lib/Object/COFFObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/COFFObjectFile.cpp?rev=243755&r1=243754&r2=243755&view=diff
==============================================================================
--- llvm/trunk/lib/Object/COFFObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/COFFObjectFile.cpp Fri Jul 31 11:14:22 2015
@@ -171,6 +171,14 @@ ErrorOr<uint64_t> COFFObjectFile::getSym
   if (std::error_code EC = getSection(SectionNumber, Section))
     return EC;
   Result += Section->VirtualAddress;
+
+  // The section VirtualAddress does not include ImageBase, and we want to
+  // return virtual addresses.
+  if (PE32Header)
+    Result += PE32Header->ImageBase;
+  else if (PE32PlusHeader)
+    Result += PE32Header->ImageBase;
+
   return Result;
 }
 

Added: llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.dll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.dll?rev=243755&view=auto
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.dll (added) and llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.dll Fri Jul 31 11:14:22 2015 differ

Propchange: llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.dll
------------------------------------------------------------------------------
    svn:executable = *

Added: llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.exe
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.exe?rev=243755&view=auto
==============================================================================
Binary files llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.exe (added) and llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.exe Fri Jul 31 11:14:22 2015 differ

Propchange: llvm/trunk/test/Object/Inputs/main-ret-zero-pe-i386.exe
------------------------------------------------------------------------------
    svn:executable = *

Added: llvm/trunk/test/Object/nm-pe-image.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/nm-pe-image.test?rev=243755&view=auto
==============================================================================
--- llvm/trunk/test/Object/nm-pe-image.test (added)
+++ llvm/trunk/test/Object/nm-pe-image.test Fri Jul 31 11:14:22 2015
@@ -0,0 +1,31 @@
+The executable was generated like so:
+$ cat t.c
+int main() { return 0; }
+$ clang --target=i686-windows -c t.c -o t.o
+$ lld-link2 t.o -out:t.exe -entry:main -debug
+
+It has a mingw-style symbol table in the executable, which MSVC-produced images
+don't have.
+
+RUN: llvm-nm %p/Inputs/main-ret-zero-pe-i386.exe \
+RUN:         | FileCheck %s -check-prefix PE-EXE
+
+PE-EXE: 00401000 t .bss
+PE-EXE: 00401000 t .data
+PE-EXE: 00401000 t .text
+PE-EXE: 00401000 T _main
+
+The DLL was generated like so:
+$ cat t.c
+int DllMain(void *mod, long reason, void *reserved) { return 1; }
+$ clang --target=i686-windows -c t.c -o t.o
+$ lld-link2 t.o -out:t.exe -entry:DllMain -debug -dll
+
+
+RUN: llvm-nm %p/Inputs/main-ret-zero-pe-i386.dll \
+RUN:         | FileCheck %s -check-prefix PE-DLL
+
+PE-DLL: 10001000 t .bss
+PE-DLL: 10001000 t .data
+PE-DLL: 10001000 t .text
+PE-DLL: 10001000 T _DllMain





More information about the llvm-commits mailing list