Menu

#3790 Crash for big #define

closed-fixed
None
other
5
2024-11-01
2024-10-24
No

Very large #define definitions cause a crash.

>sdcc -v
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/f8 TD- 4.4.3 #14976 (MINGW64)
published under GNU General Public License (GPL)
2 Attachments

Discussion

  • Benedikt Freisen

    There is no #define in there. Did you upload the right file?

     
  • Dmitry Kharitonov

    I'm very, very sorry.

     
    • Janko Stamenović

      I don't know what you want to do, but I can rewrite your example so that it produces an equivalent result without a crash, even much more: 64k nop-s could be easily generated:

      #define nop nop
      #define nop2 nop \
          nop
      #define nop4 nop2 \
          nop2
      #define nop8 nop4 \
          nop4
      #define nop16 nop8 \
          nop8
      #define nop32 nop16 \
          nop16
      #define nop64 nop32 \
          nop32
      #define nop128 nop64 \
          nop64
      #define nop256 nop128 \
          nop128
      #define nop512 nop256 \
          nop256
      #define nop1024 nop512 \
          nop512
      #define nop2048 nop1024 \
          nop1024
      #define nop4096 nop2048 \
          nop2048
      #define nop8192 nop4096 \
          nop4096
      #define nop16384 nop8192 \
          nop8192
      #define nop32768 nop16384 \
          nop16384
      #define nop64k nop32768 \
          nop32768
      
      void main(void)  {
          __asm
          nop64k
          __endasm;
      }
      
       
  • Dmitry Kharitonov

    I don't know what you want to do

    These macros allow you to easily and conveniently select any delays.

    I have a crash in Windows 7.

     

    Last edit: Dmitry Kharitonov 2024-10-24
    • Janko Stamenović

      Then I still suggest you to change the macros the way I've shown so you won't have a crash. You don't need () and __asm and __endasm appearance in C should be minimized. If you don't want to have __asm and __endasm visible in C, but inserted with the macros then you have to create separate macros for "inside of the asm blocks" (like in my previous message) and for C:

      // to use in asm blocks:
      #define nopin nop
      #define nopin2 nopin \
          nopin
      #define nopin4 nopin2 \
          nopin2
      // etc.
      
        // to use in C lines:
      #define nop2 \
              __asm \
              nopin2 \
              __endasm
      #define nop4 \
              __asm \
              nopin4 \
              __endasm
      //etc..
      

      This also doesn't crash. Then you use the "no-in" nopN macros in C as, for example: nop1024;

      (Still, I have to note that this approach to produce "delays" is sub-optimal, the use of loops can need much less code and still be cycle exact.)

       
  • Philipp Klaus Krause

    On my Debian GNU/Linux testing on amd64 system, the segfault happens when the recursion in nicify_diffs_more hits a stack size of 4 MB.
    However, ulimit -s is 8 MB by default, and increasing it to 32 MB doesn't change the behaviour either. So where does the 4 MB limit come from?

     
    • Philipp Klaus Krause

      SDCC explicitly reduces the limit to 4 MB,since IMO 32K nop are not entirely unreasonable,I increased the limit to 8MB in [r15066]. Of course, now one still gets the error for 64K nop. But that amount of nop is entirely unreasonable for a 16-bit architecture, so I consider this bug fixed.
      P.S.: The problem is unrelated to #define. It is about the size of the function.

       

      Related

      Commit: [r15066]

  • Philipp Klaus Krause

    • status: open --> closed-fixed
    • assigned_to: Philipp Klaus Krause
     

Log in to post a comment.

MongoDB Logo MongoDB