[Nasm-bugs] [Bug 3392448] NASM generates invalid debug_loc and debug_pubnames sections

noreply-nasm at dev.nasm.us noreply-nasm at dev.nasm.us
Thu Mar 25 04:26:55 PDT 2021


https://bugzilla.nasm.us/show_bug.cgi?id=3392448

Tom de Vries <tdevries at suse.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tdevries at suse.de

--- Comment #8 from Tom de Vries <tdevries at suse.de> ---
I.

I build nasm from source at recent commit 5368e457 "preproc: fix pasting of
TOKEN_HERE, TOKEN_BASE and TOKEN_QMARK":
...
$ ~/upstream/nasm.git/nasm -v
NASM version 2.16rc0 compiled on Mar 25 2021
...

Using:
...
$ cat test.s
GLOBAL func:function
func:
xor eax, eax
ret
...
and:
...
$ ~/upstream/nasm.git/nasm test.s -g -F dwarf -f elf64
...
I get test.o.


II.

The incorrect version of .debug_pubnames has been fixed:
...
$ dwarfdump -p test.o

.debug_pubnames

$
...
by making it an empty section:
...
$ readelf -S -W test.o
  [Nr] Name              Type            Address          Off    Size   ES Flg
Lk Inf Al
  ...
  [ 4] .debug_pubnames   PROGBITS        0000000000000000 000470 000000 00     
0   0  1
...

It's a bit odd and confusing to generate empty sections (that is, it would be
better to just drop them altogether), but I don't know whether it's wrong
perse.


III.

The .debug_loc section is still empty as well:
...
$ readelf -S -W test.o
  [Nr] Name              Type            Address          Off    Size   ES Flg
Lk Inf Al
  ...
  [ 4] .debug_pubnames   PROGBITS        0000000000000000 000470 000000 00     
0   0  1
...
and the same holds here about the section being empty, but that's not the
actual problem.

Looking at .debug_info we can see the DW_AT_frame_base attribute:
...
$ readelf -wi test.o 
Contents of the .debug_info section:

  Compilation Unit @ offset 0x0:
   Length:        0x44 (32-bit)
   Version:       3
   Abbrev Offset: 0x0
   Pointer Size:  8
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <c>   DW_AT_low_pc      : 0x0
    <14>   DW_AT_high_pc     : 0x0
    <1c>   DW_AT_stmt_list   : 0x0
    <20>   DW_AT_name        : test.s
    <27>   DW_AT_producer    : NASM 2.16rc0
    <34>   DW_AT_language    : 32769    (MIPS assembler)
 <1><36>: Abbrev Number: 2 (DW_TAG_subprogram)
    <37>   DW_AT_low_pc      : 0x0
    <3f>   DW_AT_frame_base  : 0x0 (location list)
 <1><43>: Abbrev Number: 0
...

Looking at .debug_abbrev we can see corresponding form:
...
$ readelf -wa test.o 
Contents of the .debug_abbrev section:
  ...
   2      DW_TAG_subprogram    [no children]
    DW_AT_low_pc       DW_FORM_addr
    DW_AT_frame_base   DW_FORM_data4
    DW_AT value: 0     DW_FORM value: 0
...

The DW_AT_frame_base attribute has form DW_FORM_data4, which means it's of
class loclistptr, in other words it's an offset into the .debug_loc section
referring to a location list. However, the .debug_loc section is empty, so
there's no location list to refer to.

So the problem is not necessarily that the .debug_loc section is invalid.  The
problem is that we have an invalid pointer.

So this part doesn't look fixed to me.

Then: it's not clear to me why do we emit a DW_AT_frame_base here in the first
place. Just not generating it looks like the easiest fix.  But perhaps there
are examples where it's needed? I'm not sure how complicated the dwarf is that
nasm generates.

Finally, looking at the relocations:
...
Relocation section '.rela.debug_info' at offset 0x4c0 contains 5 entries:
  Offset          Info           Type           Sym. Value    Sym. Name +
Addend
000000000037  000200000001 R_X86_64_64       0000000000000000 .text + 0
...
this seems wrong.  We want to patch a value which is an offset into the
.debug_loc section with the address of the text section?

-- 
You are receiving this mail because:
You are watching all bug changes.
You are on the CC list for the bug.


More information about the Nasm-bugs mailing list