Re: regarding symbol table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey ranjith kumar,


>
>   
>> 1) Given an executable file(say a.out) is it possible from which files
>> that executable is produced?
>>     
>
> No, not as far as I am aware.
>
> You could add static volatile strings in your source code, which would
> indicate their origins:
>
> static char* volatile whence = __FILE__;
>
> Then you could a utility like strings (/usr/bin/strings) to find them:
>
> strings a.out
>
>   
Under certain circumstances, it might be possible to derive the source
files from an executable without having the sources. The circumstances
are that the executable is not stripped, otherwise quite all useful
information is lost.

Assuming you have two source files - 1.c and 2.c - and compile them 'gcc
1.c 2.c -o exec'.

Then you could review the source files with

andi@roma:~/Programming/c$ readelf --symbols exec | grep ABS
    33: 00000000     0 FILE    LOCAL  DEFAULT  ABS init.c
    34: 00000000     0 FILE    LOCAL  DEFAULT  ABS initfini.c
    35: 00000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    43: 00000000     0 FILE    LOCAL  DEFAULT  ABS crtstuff.c
    48: 00000000     0 FILE    LOCAL  DEFAULT  ABS initfini.c
    49: 00000000     0 FILE    LOCAL  DEFAULT  ABS 1.c
    50: 00000000     0 FILE    LOCAL  DEFAULT  ABS 2.c
    69: 0804a014     0 NOTYPE  GLOBAL DEFAULT  ABS __bss_start
    70: 0804a01c     0 NOTYPE  GLOBAL DEFAULT  ABS _end
    71: 0804a014     0 NOTYPE  GLOBAL DEFAULT  ABS _edata

Alternatively, you could also use nm:

nm -a exec | grep " a " (ugly solution to filter all the ABS values)
00000000 a 1.c
00000000 a 2.c
00000000 a crtstuff.c
00000000 a crtstuff.c
00000000 a init.c
00000000 a initfini.c
00000000 a initfini.c

Hope that helps.

Best regards,
Andi

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux