I'm compiling the following code with NASM (nasm -g -F dwarf -f elf64 test.asm && gcc -g3 test.o).
global main
section .text
main:
%line 1 test.txt
PUSH 1337
%line 2 test.txt
PUSH 1338
%line 3 test.txt
PUSH 1339
%line 8 test.txt
POP RAX
%line 9 test.txt
POP RAX
%line 10 test.txt
POP RAX
RET
I would expect this to add the lines 1, 2, 3, 8, 9 and 10 to the dwarf data, however when I explore the file (using DWARF explorer, readelf or own code) I instead get the following lines:
test.txt 2 0x1130 (PUSH 1337)
test.txt 3 0x1135 (PUSH 1338)
test.txt 4 0x113a (PUSH 1339)
test.txt 9 0x113f (POP RAX)
test.txt 10 0x1140 (POP RAX)
test.txt 11 0x1141 (POP RAX)
test.txt 13 0x1142 (RET)
Every line number is one higher than what I provided in the assembly and in addition there is an extra line #13 situated at the ret statement. Could anyone explain what is going on here, and what I should do to get the expected result?