Re: Question about genassym, locore.s and 0-sized arrays (showstopper for an icc compiled kernel)

From: Dan Nelson <dnelson_at_allantgroup.com>
Date: Thu, 4 Sep 2003 17:51:23 -0500
In the last episode (Sep 05), Alexander Leidinger said:
> On Thu, 4 Sep 2003 11:28:58 -0500
> Dan Nelson <dnelson_at_allantgroup.com> wrote:
> > If you're talking FreeBSD 5, you should be able to simply subsitute
> > a C99 "flexible array member" (basically replace "[0]" with "[]")
> > and get the same effect.  0-length arrays are a gcc extension:
> > 
> > http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
> > 
> > Under FreeBSD 4.x, you can't use them because gcc 2.95 only
> > supports the gcc extension.  Intel has added support for a lot of
> > gcc extensions recently; they may be willing to add this to the
> > list.
> 
> Please read my mail again, icc already supports my_array[0], but the
> resulting array in the binary has size '1'. The actual showstopper is
> the output of genassym.sh. To me it seems it's just a genassym.sh
> issue, but I don't really know what's going on in the kernel, so I
> ask here.

Ok, I reread the original message, and it's still a zero-length array
problem, but in a different place.

What it looks like to me is that icc silently converts zero-length
arrays to 1 element when creating the assembly output.  While it's
processing C source, sizeof(my_array) returns 0, but the emitted
assembly says otherwise:

$ cat > test.c
int test0[0];
int test1[1];
int test2[2];
^D
$ gcc -c test.c -S -o test.gcc
$ icc -c test.c -S -o test.icc
$ grep comm test.?cc
test.gcc:       .comm   test0,0,4
test.gcc:       .comm   test1,4,4
test.gcc:       .comm   test2,8,4
test.icc:       .comm test2,8,4
test.icc:       .comm test1,4,4
test.icc:       .comm test0,4,4

So gcc emitted symbols with the same size as in the source file, with
an alignment of 4 bytes (since I'm using ints in this example), but icc
adjusted the test0 symbol to be one int long.  I used ints to make it
more obvious what icc is doing; the effect is the same if you use
chars.

I guess the correct question to be asking is "does the ELF format allow
0-length symbols?"  If not, then gcc is generating invalid objects, and
genassym will have to be rewritten to not use them (maybe add one to
the array size, and have genassym.sh subtract it).  If it does, then
genassym.c (sys/assym.h actually) is legal code.  If Intel doesn't want
to change icc, we can still work around it, but there may be other code
that will break on icc just like assym.h.

-- 
	Dan Nelson
	dnelson_at_allantgroup.com
Received on Thu Sep 04 2003 - 13:51:27 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:21 UTC