gccmingwmingw-w64portable-executablesymbol-table

Dynamic Symbol Table for PE compiled on Linux


I'm trying to get the content of the dynamic symbol table of compiled c file

#include<stdio.h>

int main(){
    printf("Hello, World!");
    return 0;
}

as portable executable (PE) on Linux with

i686-w64-mingw32-gcc hello_world.c -o hello32
x86_64-w64-mingw32-gcc hello_world.c -o hello64

I'm using objdump:

objdump --dynamic-syms hello32

and get the output:

hello32:    file format pei-i386

objdump: hello32: not a dynamic object
DYNAMIC SYMBOL TABLE:
no symbols

I would expect to have functions like printf in the table. It works with gcc and ELF binaries.

Does anyone know how to compile the file correctly to have a dynamic symbol table with content?


Solution

  • The concept of dynamic symbols seems to be a bit lost in PE-targetting binutils. Use objdump -p <file> or objdump -x <file> and look for import tables in the output. I haven't found a better solution with binutils yet. There's llvm-readobj --coff-imports <file> from LLVM. If you want to see where the symbols will come from at runtime, ntldd is a good tool.