bebbo / binutils-gdb

Unofficial mirror of sourceware binutils-gdb repository. Updated daily.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git
GNU General Public License v2.0
3 stars 3 forks source link

GNU ld does not save absolute symbols in executable files #23

Closed cahirwpz closed 2 years ago

cahirwpz commented 2 years ago

When I assemble syscall.S file containing following line:

        ...
    .set    _frameCount, 0x3fc
        ...

I get a relocatable file syscall.o and when I investigate exposed symbols I get following:

# m68k-amigaos-nm system/syscall.o | grep _frameCount
000003fc A _frameCount

... which is expected.

However the absolute symbols are not carried to the executable file, which I verified with m68k-amigaos-nm system/system.exe.dbg | grep _frameCount and m68k-amigaos-strings system/system.exe.dbg | grep frameCount (both give me nothing). Thus I cannot display frameCount variable defined as extern int frameCount using gdb's print command.

bebbo commented 2 years ago

to be visible in gdb, you need to add debug infos via .stabs and .stabstr.

cahirwpz commented 2 years ago

You're right! It was enough to add following STABS to assembly file:

#include <stab.h>

    .stabs  "syscall.S",N_SO,0,0,0
    .stabs  "int:t1=r1;0020000000000;0017777777777;",N_LSYM,0,0,0
        ...
    .stabs  "_frameCount", N_ABS|N_EXT, 0, 0, 0x3fc
    .stabs  "frameCount:G1", N_GSYM, 0, 1, 0

To make gdb understand what frameCount is and where is it placed in memory.

Thanks for the hint! You may close the issue if you wish to do so.