[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 22 14:00:25 PDT 2020


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

--- Comment #9 from C. Masloch <pushbx at ulukai.org> ---
Here is an additional trivial testcase with a few more test results.

* "nasm" is nasm-2.14.03rc2-448-gca2d991e from
https://github.com/ecm-pushbx/nasm/commit/ca2d991ec9240cb35bad9cd467aea1eab197784d

* "oldnasm" is 2.12.02

* "tstnasm" is based on nasm-2.14.03rc2-445-ge91f5cc1 from
https://repo.or.cz/nasm.git/commit/e91f5cc1322eed4da0de81656276e021bf352c3d
with the additional patch I proposed in comment #5 which is this:

$ 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;
$

* "patnasm" is based on the same revision as tstnasm but has instead the
following patch, based on the comment #7:

$ git diff
diff --git a/output/outelf.c b/output/outelf.c
index 4976b680..6175ca48 100644
--- a/output/outelf.c
+++ b/output/outelf.c
@@ -2962,12 +2962,12 @@ static void dwarf_output(int type, void *param)
     s = (struct symlininfo *)param;

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

     /* Check if section index has changed */
-    if (!(dwarf_csect && (dwarf_csect->section) == (s->section)))
-        dwarf_findsect(s->section);
+    if (!(dwarf_csect && (dwarf_csect->section) == (s->section - 1)))
+        dwarf_findsect(s->section - 1);

     /* do nothing unless line or file has changed */
     if (!debug_immcall)
$


Here is the test case and the results of assembling it with -felf -g, then
dumping the disassembly + source with objdump -S:

$ cat test.asm

section .text
global foo
foo:
        mov eax, 1234
        retn
$ nasm -v
NASM version 2.15rc0 compiled on Nov 22 2019
$ nasm -felf -g test.asm -o test.o
Segmentation fault
$ nasm -felf test.asm -o test.o
$ objdump -S test.o

test.o:     file format elf32-i386


Disassembly of section .text:

00000000 <foo>:
   0:   b8 d2 04 00 00          mov    $0x4d2,%eax
   5:   c3                      ret    
$ oldnasm -v
NASM version 2.12.02 compiled on Aug 10 2019
$ oldnasm -felf -g test.asm -o test.old
$ objdump -S test.old

test.old:     file format elf32-i386


Disassembly of section .text:

00000000 <foo>:

section .text
global foo
foo:
        mov eax, 1234
   0:   b8 d2 04 00 00          mov    $0x4d2,%eax
        retn
   5:   c3                      ret    
$ tstnasm -v
NASM version 2.15rc0 compiled on Apr  8 2020
$ tstnasm -felf -g test.asm -o test.tst
$ objdump -S test.tst

test.tst:     file format elf32-i386


Disassembly of section .text:

00000000 <foo>:
   0:   b8 d2 04 00 00          mov    $0x4d2,%eax
   5:   c3                      ret    
$ patnasm -v
NASM version 2.15rc0 compiled on Apr 22 2020
$ patnasm -felf -g test.asm -o test.pat
$ objdump -S test.pat

test.pat:     file format elf32-i386


Disassembly of section .text:

00000000 <foo>:

section .text
global foo
foo:
        mov eax, 1234
   0:   b8 d2 04 00 00          mov    $0x4d2,%eax
        retn
   5:   c3                      ret    
$ 


My earlier patch (tstnasm) does not have any source line debugging information
for the .text section of this example case. The newer patch (patnasm) seems to
restore that info to be as it should. Note that I only patched the most obvious
references in the dwarf_output function; I expect that the change should be
done in other places too. Or whatever changed the section numbering to be
1-based should be reverted.

-- 
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