From owner-freebsd-current@FreeBSD.ORG Thu Sep 4 15:51:27 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0128716A4BF for ; Thu, 4 Sep 2003 15:51:27 -0700 (PDT) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2E40043FBF for ; Thu, 4 Sep 2003 15:51:24 -0700 (PDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.12.9/8.12.9) id h84MpNwf020027; Thu, 4 Sep 2003 17:51:23 -0500 (CDT) (envelope-from dan) Date: Thu, 4 Sep 2003 17:51:23 -0500 From: Dan Nelson To: Alexander Leidinger Message-ID: <20030904225123.GB39916@dan.emsphone.com> References: <20030904180448.021a1b6b.Alexander@Leidinger.net> <20030904162858.GI98381@dan.emsphone.com> <20030905001411.3a9030b3.Alexander@Leidinger.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030905001411.3a9030b3.Alexander@Leidinger.net> X-OS: FreeBSD 5.1-CURRENT X-message-flag: Outlook Error User-Agent: Mutt/1.5.4i cc: current@freebsd.org Subject: Re: Question about genassym, locore.s and 0-sized arrays (showstopper for an icc compiled kernel) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Sep 2003 22:51:27 -0000 In the last episode (Sep 05), Alexander Leidinger said: > On Thu, 4 Sep 2003 11:28:58 -0500 > Dan Nelson 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@allantgroup.com