#669 pic16 _CONFIG addresses causes segfault

closed-fixed
5
2013-05-25
2004-01-02
No

{a fix patch that worked for me is included below}

I have been playing around with the current CVS
version (the last one that compiles as of Dec 28) and
sdcc crashes in the emit*Map stage when the hardware
config bits are set with the following minimal code.

$ cat > configCrash.c << EOF
#include "p18f252.h"
typedef unsigned int cword;
cword at _CONFIG1H CONFIG1H = _HS_OSC_1H;
void main () {}
EOF

I've been using a very focussed build :)
$~/testzone/sdcc/bin/sdcc --version
SDCC : pic16/pic14 2.3.6 (Jan 1 2004) (UNIX)
$

Here is the output of a minimal run
$ ~/testzone/sdcc/bin/sdcc -mpic16 -p18f252
configCrash.c
Processor: 18f252
Caught signal 11: SIGSEGV
$

gdb gives this backtrace.
(gdb) bt
#0 adjustIChain (ebbs=0x82aefb0, count=1) at
SDCClrange.c:632
#1 0x0809ba7a in computeLiveRanges (ebbs=0x82aefb0,
count=0) at SDCClrange.c:651
#2 0x0809bba4 in recomputeLiveRanges
(ebbs=0x82aefb0, count=1) at SDCClrange.c:700
#3 0x080f35b4 in pic16_assignRegisters
(ebbs=0x82aefb0, count=1) at ralloc.c:3849
#4 0x080631a8 in eBBlockFromiCode (ic=0x0) at
SDCCopt.c:1105
#5 0x08113af9 in pic16emitRegularMap
(map=0x8149690, addPublics=1, arFlag=1)
at glue.c:204
#6 0x08114d65 in pic16emitMaps () at glue.c:532
#7 0x081156b3 in pic16glue () at glue.c:799
#8 0x0805441d in main (argc=4, argv=0x0,
envp=0xbffff9e8) at SDCCmain.c:2122
(gdb)

The problem seems to be that the CONFIG1H variable is
never explicitly referenced in any excutable code, so
there is no code for adjustIChain to work with.

/
*-----------------------------------------------------------------*/
/* adjustIChain - correct the sch and ech pointers
*/
/
*-----------------------------------------------------------------*/
void
adjustIChain (eBBlock ** ebbs, int count)
{
int i;

for (i = 0; i < count; i++)
{
iCode *ic;

if (ebbs[i]->noPath)
continue;

ic = ebbs[i]->sch;
while (ic->prev) // *crash*happens*here*
ic = ic->prev;
ebbs[i]->sch = ic;

ic = ebbs[i]->ech;
while (ic->next)
ic = ic->next;
ebbs[i]->ech = ic;
}
}

My quick fix blindly allows this situation, It works
for me. The .hex output looks fine but gpdasm is
screwing up the printed addresses for the config
bits.

$cat configCrash.diff
Index: src/SDCClrange.c
===================================================================
RCS file: /cvsroot/sdcc/sdcc/src/SDCClrange.c,v
retrieving revision 1.32
diff -u -r1.32 SDCClrange.c
--- src/SDCClrange.c 27 Nov 2003 09:14:51 -0000
1.32
+++ src/SDCClrange.c 2 Jan 2004 03:55:30 -0000
@@ -629,6 +629,9 @@
continue;

ic = ebbs[i]->sch;
+ /* is there any code for this BBlock? (e.g.
ROM assignment) */
+ if (!ic)
+ continue;
while (ic->prev)
ic = ic->prev;
ebbs[i]->sch = ic;
$

Discussion

  • Vangelis Rokas

    Vangelis Rokas - 2004-01-02
    • assigned_to: nobody --> vrokas
     
  • Vangelis Rokas

    Vangelis Rokas - 2004-01-02

    Logged In: YES
    user_id=770505

    Fixed in SDCClrange.c 1.33
    Thanks for the patch Albert, I have found the same bug earlier
    but I haven't traced it to fix it.

     
  • Vangelis Rokas

    Vangelis Rokas - 2004-01-02
    • status: open --> closed
     
  • Albert den Haan

    Albert den Haan - 2004-01-03

    Logged In: YES
    user_id=117442

    I'm glad the patch looked sane.

    I'll be looking deeper into the problem RSN. I wonder if
    the preceeding noPath check is the one I should have
    really used.

    The semantics of the eBBlock fields are a bit of a
    mystery :)

    Albert.

     
  • Vangelis Rokas

    Vangelis Rokas - 2004-01-08
    • milestone: --> fixed
    • status: closed --> closed-fixed
     

Log in to post a comment.