I’m trying to write some assembly programs using nasm on linux. Everything is good, but I make heavy use of local symbols (.loop, .else, etc.), which is a pain when debugging, because these symbols are emitted to the symbol table, e.g.:
[BITS 32] global main section .text main: do stuff .else: do other stuff
will produce a disassembly that looks like:
<main>: 00000000 do stuff <main.else>: 00000000 do other stuff
which is a bit annoying just because gdb will think these are all separate functions, so when I ‘disas’ it will only disassemble a couple of instructions before it runs into another label and stops.
Is there a way to suppress emitting these symbols to the ELF symbol table using nasm under linux?
Advertisement
Answer
I haven’t found a way to do it directly with nasm
, however if you link your object with ld
, then you have at your disposal a very handy switch.
Quoting from ld’s man page:
-x –discard-all Delete all local symbols.
-X –discard-locals Delete all temporary local symbols. (These symbols start with system-specific local label prefixes, typically .L for ELF systems or L for traditional a.out systems.)
so if you have, for example, this:
section .data hello: db 'Hello world!',10 helen: equ $-hello hi: db 'Hi!',10 hilen: equ $-hi section .text global _start _start: mov eax,4 mov ebx,1 mov ecx,hello mov edx,helen int 80h .there: mov eax,4 mov ebx,1 mov ecx,hi mov edx,hilen int 80h .end: mov eax,1 mov ebx,0 int 80h
and then build, link (and run) it like this:
$ nasm -g -f elf32 prog.asm && ld -x prog.o -o prog && ./prog Hello world! Hi!
then, when you load it in gdb
, you get this:
$ gdb prog ..... Reading symbols from prog...done. (gdb) disas _start Dump of assembler code for function _start: 0x08048080 <+0>: mov $0x4,%eax 0x08048085 <+5>: mov $0x1,%ebx 0x0804808a <+10>: mov $0x80490b8,%ecx 0x0804808f <+15>: mov $0xd,%edx 0x08048094 <+20>: int $0x80 0x08048096 <+22>: mov $0x4,%eax 0x0804809b <+27>: mov $0x1,%ebx 0x080480a0 <+32>: mov $0x80490c5,%ecx 0x080480a5 <+37>: mov $0x4,%edx 0x080480aa <+42>: int $0x80 0x080480ac <+44>: mov $0x1,%eax 0x080480b1 <+49>: mov $0x0,%ebx 0x080480b6 <+54>: int $0x80 End of assembler dump. (gdb)
where the disassembly is not hindered by the local symbols any more.