List of Bugs
Posted: Wed Dec 24, 2014 7:31 am
Bugfixes are applied as of the time of the posting and will be fixed in the next successful nightly build.
Bug #1 (fixed) sccz80
sccz80 places statically initialized variables in rodata section when they should be placed in data section.
Bug #2 (fixed) bss initialization
The crt saves the stack pointer into a bss variable before the bss section is initialized, meaning bss initialization wipes out the stored value.
A new section was introduced ("BSS_UNINITIALIZED") to allocate space for data that is never initialized.
Test program:
This program tests the random number generator's distribution.
This is a RAM model program so no section initialization is normally performed, however the pragma forces the crt to do a bss initialization in the startup. This allows the program to be executed more than once as all data that needs to be zeroed is zeroed on each execution. The random number seed sits in a data section and its value is retained between runs, allowing a different sequence of random numbers to be generated on each run.
The bug caused the stored value of sp to be zeroed so that return after execution caused a crash. With the fix in place the program exits fine and can be re-run.
Bug #1 (fixed) sccz80
sccz80 places statically initialized variables in rodata section when they should be placed in data section.
Bug #2 (fixed) bss initialization
The crt saves the stack pointer into a bss variable before the bss section is initialized, meaning bss initialization wipes out the stored value.
A new section was introduced ("BSS_UNINITIALIZED") to allocate space for data that is never initialized.
Test program:
Code: Select all
// zcc +zx -vn -startup=1 -clib=new rand.c -o rand
#include <stdio.h>
#include <stdlib.h>
#include <arch/spectrum.h>
#include <sys/ioctl.h>
#pragma output CRT_INITIALIZE_BSS = 1
int distribution[256];
char *s, b;
int j, k;
unsigned long t;
unsigned long sum;
unsigned long n;
main()
{
int i;
zx_border(INK_WHITE);
ioctl(1, IOCTL_OTERM_CLS);
do
{
// scale RAND_MAX to [0,255]
i = rand() >> 7;
++distribution[i];
// plot(x,y)
// no graphics lib available yet
s = zx_pxy2saddr(i, 192 - distribution[i]);
b = zx_px2bitmask(i);
*s |= b;
} while (distribution[i] < 192);
// print distribution & accumulate statistics
printf("\x16\x01\x17\n\nDistribution:\n\n");
k = 127;
for (i=0; i!=256; ++i)
{
// accumulate sum
t = (j + 64) * (unsigned long)(distribution[i]);
sum += t;
n += distribution[i];
// print frequency for 20% of intervals
if ((i % 5) == 0)
printf("[%5u,%5u] = %u\n", j, k, distribution[i]);
// next interval boundary
j += 128;
k += 128;
}
// print statistics
printf("\n%11s : %lu\n", "Sample Size", n);
printf("%11s : %lu\n", "Sum", sum);
printf("%11s : %lu\n", "Average", sum / n);
printf("\n\n");
return 0;
}
This is a RAM model program so no section initialization is normally performed, however the pragma forces the crt to do a bss initialization in the startup. This allows the program to be executed more than once as all data that needs to be zeroed is zeroed on each execution. The random number seed sits in a data section and its value is retained between runs, allowing a different sequence of random numbers to be generated on each run.
The bug caused the stored value of sp to be zeroed so that return after execution caused a crash. With the fix in place the program exits fine and can be re-run.