#903153 nasm does not handle rdf2 output correctly due to incorrect use of pure_func

Package:
nasm
Source:
nasm
Description:
General-purpose x86 assembler
Submitter:
Petr Vandrovec
Date:
2019-11-17 19:54:04 UTC
Severity:
normal
#903153#5
Date:
2018-07-07 06:08:12 UTC
From:
To:
Hi,
  when I tried to switch to new nasm for one of our projects,
nasm started panicking;

nasm: panic: rdf segment numbers not allocated as expected (0,0,0)

nasm code in question calls seg_alloc 3 times:

    segtext = seg_alloc();
    segdata = seg_alloc();
    segbss = seg_alloc();
    if (segtext != 0 || segdata != 2 || segbss != 4)
        nasm_panic(0,
              "rdf segment numbers not allocated as expected (%d,%d,%d)",
              segtext, segdata, segbss);

and seg_alloc returns consecutive even integers, so it should never
happen that all three would be zeroes.

Except that seg_alloc() is marked as pure_func, and so new gcc figures
out that seg_alloc() returns constant, and so it can call it just once,
and then assign returned value to all three variables :-(

Simple fix below solves the problem.

Petr

Signed-off-by: Petr Vandrovec <petr@vandrovec.name>
--- nasm-2.13.03/include/nasmlib.h	2018-02-07 13:40:15.000000000 -0800
+++ nasm-2.13.03.patched/include/nasmlib.h	2018-07-06 22:59:37.595561715 -0700
@@ -192,7 +192,7 @@
  * seg_alloc: allocate a hitherto unused segment number.
  */
 void pure_func seg_init(void);
-int32_t pure_func seg_alloc(void);
+int32_t seg_alloc(void);

 /*
  * many output formats will be able to make use of this: a standard

#903153#10
Date:
2019-02-12 09:41:25 UTC
From:
To:
Hi. Does the 2.14-1 release fix this? I see that upstream included at
patch exactly like yours:

commit 9f45a77f46829e666b35530939b9237cf978d4dc
Author: Cyrill Gorcunov <gorcunov@gmail.com>
Date:   Sat Feb 10 00:40:46 2018 +0300

    nasmlib: Drop pure_func attrib from seg_alloc

This patch should have been included is 2.14-1.

Thanks,

#903153#15
Date:
2019-11-17 19:50:23 UTC
From:
To:
Issue persists in nasm 2.14-1 (Debian 10.2 Stable)


pbikos@dev:/home/large/code/osdev$ cat main.asm

section .text

pbikos@dev:/home/large/code/osdev$ nasm -f rdf main.asm
main.asm:panic: rdf segment numbers not allocated as expected (2,4,6)
pbikos@dev:/home/large/code/osdev$ nasm -v
NASM version 2.14