[Nasm-bugs] [Bug 3392654] Certain testcase with -felf -g results in segmentation fault

noreply-nasm at dev.nasm.us noreply-nasm at dev.nasm.us
Wed Apr 8 00:45:54 PDT 2020


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

--- Comment #5 from C. Masloch <pushbx at ulukai.org> ---
This line is causing the segfault:

https://repo.or.cz/nasm.git/blob/e91f5cc1322eed4da0de81656276e021bf352c3d:/output/outelf.c#l2964

(Recompiled after ./configure --enable-gdb. Tests segfault the same as without
that switch.)

$ gdb --args tstnasm -felf -g test1.asm -o test1.o
GNU gdb (Debian 9.1-2) 9.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from tstnasm...
(gdb) run
Starting program: /home/[...]/tstnasm -felf -g test1.asm -o test1.o

Program received signal SIGSEGV, Segmentation fault.
dwarf_output (type=64, param=0x5555556ff6c0 <sinfo>) at output/outelf.c:2965
2965        if (!(sects[s->section]->flags & SHF_EXECINSTR))
(gdb) print s
$1 = (struct symlininfo *) 0x5555556ff6c0 <sinfo>
(gdb) print sects
$2 = (struct elf_section **) 0x555555757bc0
(gdb) print s->section
$3 = 1
(gdb) print sects[s->section]
$4 = (struct elf_section *) 0x0
(gdb) print *sects
$5 = (struct elf_section *) 0x555555747aa0
(gdb) print **sects
$6 = {data = 0x555555747b20, len = 0, size = 0, nrelocs = 0, index = 16, 
  shndx = 1, type = 1, align = 16, flags = 6, pass_last_seen = 0, entsize = 0, 
  name = 0x555555757ba0 ".text", rel = 0x0, head = 0x0, tail = 0x555555747b00, 
  gsyms = 0x0}
(gdb) print *sects[s->section]
Cannot access memory at address 0x0
(gdb) print sects[s->section]
$7 = (struct elf_section *) 0x0
(gdb) quit
A debugging session is active.

        Inferior 1 [process 1705047] will be killed.

Quit anyway? (y or n) y


This patch fixes the issue for me:

$ git diff
diff --git a/output/outelf.c b/output/outelf.c
index 4976b680..7dc1a52c 100644
--- a/output/outelf.c
+++ b/output/outelf.c
@@ -2961,6 +2961,9 @@ static void dwarf_output(int type, void *param)

     s = (struct symlininfo *)param;

+    if (!sects[s->section])
+        return;
+
     /* line number info is only gathered for executable sections */
     if (!(sects[s->section]->flags & SHF_EXECINSTR))
         return;

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


More information about the Nasm-bugs mailing list