[cc65] Strange things happen with segments after BSS

From: MagerValp <MagerValp1cling.gu.se>
Date: 2005-11-18 14:46:52
When BSS isn't the last segment in the linker config file, strange
things happen. It could be related to alignment, but I'm not sure. For
my current project, the config file looks like this:

  MEMORY {
    ZP:		start = $0002, size = $001C, define = yes;
    MYZP:	start = $0057, size = $0010;
    RAM:	start = $07FF, size = $9001, file = %O, define = yes, fill = yes;
    TILERAM:	start = $9800, size = $1800, file = %O, fill = yes;
    MAPRAM:	start = $b000, size = $2000, file = %O, fill = yes;
    GFXRAM:	start = $c000, size = $4000, file = "";
  }
  SEGMENTS {
    STARTUP:	load = RAM, type = ro;
    LOWCODE:	load = RAM, type = ro, optional = yes;
    INIT:	load = RAM, type = ro, define = yes, optional = yes;
    CODE:	load = RAM, type = ro;
    RODATA:	load = RAM, type = ro, align = 64;
    DATA:	load = RAM, type = rw, align = 64;
    BSS:	load = RAM, type = bss, define = yes, align = $100;
    TILEDATA:	load = TILERAM, type = ro, align = $100;
    MAPDATA:	load = MAPRAM, type = rw, align = $400;
    GFXZP:	load = MYZP, type = zp, optional = yes;
    ZEROPAGE:	load = ZP, type = zp;
  }

In tile.s, I have:

  	.segment "TILEDATA"

  tile_bmp:
	.incbin "tile_bmp.bin"

  tile_scr:
	.incbin "tile_scr.bin"

  tile_col:
	.incbin "tile_col.bin"


	.align 64

  tile_bmp_tab_lo:
	.byte <(tile_bmp + 0 * 3 * 8)
	.byte <(tile_bmp + 1 * 3 * 8)
	.byte <(tile_bmp + 2 * 3 * 8)
	.byte <(tile_bmp + 3 * 3 * 8)
	[...]

  tile_bmp_tab_hi:
	.byte >(tile_bmp + 0 * 3 * 8)
	.byte >(tile_bmp + 1 * 3 * 8)
	.byte >(tile_bmp + 2 * 3 * 8)
	.byte >(tile_bmp + 3 * 3 * 8)
	[...]

As the graphics data has a fixed size ($1200 + $240 + $240), the
tables should start at $ae80, but instead it looks like this:

  ae00  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
  ae10  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
  ae20  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
  ae30  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
  ae40  00 00 00 00  18 30 48 60  78 90 a8 c0  d8 f0 08 20   .....0H`x...... 
  ae50  38 50 68 80  98 b0 c8 e0  f8 10 28 40  58 70 88 a0   8Ph.......(@Xp..
  ae60  b8 d0 e8 00  18 30 48 60  78 90 a8 c0  d8 f0 08 20   .....0H`x...... 
  ae70  38 50 68 80  98 b0 c8 e0  f8 10 28 40  58 70 88 a0   8Ph.......(@Xp..
  ae80  b8 d0 e8 98  98 98 98 98  98 98 98 98  98 98 99 99   ................

The table is moved forward 61 bytes. If I change the segment type to
rw, the data appears in the right place:

  ae70  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00   ................
  ae80  00 18 30 48  60 78 90 a8  c0 d8 f0 08  20 38 50 68   ..0H`x...... 8Ph
  ae90  80 98 b0 c8  e0 f8 10 28  40 58 70 88  a0 b8 d0 e8   .......(@Xp.....
  aea0  00 18 30 48  60 78 90 a8  c0 d8 f0 08  20 38 50 68   ..0H`x...... 8Ph
  aeb0  80 98 b0 c8  e0 f8 10 28  40 58 70 88  a0 b8 d0 e8   .......(@Xp.....
  aec0  98 98 98 98  98 98 98 98  98 98 98 99  99 99 99 99   ................

I have $614 bytes of BSS in my code, so it isn't just skipping the BSS
data...

ld65 bug? The workaround is simple (change BSS to type = rw), but it
took me a while to figure out what the problem was the first time it
bit me.

-- 
    ___          .     .  .         .       . +  .         .      o   
  _|___|_   +   .  +     .     +         .  Per Olofsson, arkadspelare
    o-o    .      .     .   o         +          MagerValp@cling.gu.se
     -       +            +    .     http://www.cling.gu.se/~cl3polof/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Fri Nov 18 14:47:04 2005

This archive was generated by hypermail 2.1.8 : 2005-11-18 14:47:07 CET