[Tinycc-devel] question about bit-fields

2012-05-27 Thread Didier Barvaux
Hello all,

I'm trying to build my project with tcc (yesterday's git version). It
succeeds without any required change (cool!), but tests fail :(

I narrowed the problem to bit-fields, and more especially to the length
of some bit-fields. I created a small test program to explain the
problem:

$ cat test.c 

#include stdint.h

struct data
{
unsigned int foo:4;
unsigned int bar:4;
uint8_t other;
uint16_t other2;
};

int main(void)
{
return sizeof(struct data);
}

$ gcc -Wall -Werror -Wextra -g -O2 -o test_gcc test.c
$ ./test_gcc ; echo $?
4
$ clang -Wall -Werror -Wextra -g -O2 -o test_clang test.c
$ ./test_clang ; echo $?
4
$ tcc -Wall -Werror -Wextra -g -O2 -o test_tcc test.c
$ ./test_tcc ; echo $?
8

Length 4 is expected, but tcc reports 8. Reporting the expected
length is important because the structure defines a network header.

I then tried to replace unsigned-int-based bitfield by an uint8_t-based
bitfield:

$ cat test2.c 

#include stdint.h

struct data
{
uint8_t foo:4;
uint8_t bar:4;
uint8_t other;
uint16_t other2;
};

int main(void)
{
return sizeof(struct data);
}

$ gcc -Wall -Werror -Wextra -g -O2 -o test2_gcc test2.c
$ ./test2_gcc ; echo $?
4
$ clang -Wall -Werror -Wextra -g -O2 -o test2_clang test2.c
$ ./test2_clang ; echo $?
4
$ tcc -Wall -Werror -Wextra -g -O2 -o test2_tcc test2.c
$ ./test2_tcc ; echo $?
4

Expected result is given by tcc this time. Problem is that I cannot
change the struct's definition from unsigned int to uint8_t.

Is there an option or a declaration to make tcc compute the expected
length for unsigned-int-based bit fields?

For the record, GCC is version 4.5.3, clang is version 3.0, and tcc is
git rev f98c2306a0857ad3f8800f91e0554a27adc7f675.

Regards,
Didier


signature.asc
Description: PGP signature
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] question about bit-fields

2012-05-27 Thread Rick Hodgin
Didier,

You're able to take the code and modify that requirement.  It seems 
straight-forward enough that TinyCC is (in memory at compile-time) determining 
the target size, regardless of the storage size, and using that for the storage 
size in memory.  You could alter that code to always use the smallest 
storage-size, and automatically upsize to the larger form, such as something 
stored as 1..7 bits always being stored as a single byte, even if it's scoped 
as an int.

Such a patch would be desirable, and could work with a command-line switch 
(something like --pack-bit-fields).

Best regards,
Rick C. Hodgin

--- On Sun, 5/27/12, Didier Barvaux did...@barvaux.org wrote:

 From: Didier Barvaux did...@barvaux.org
 Subject: Re: [Tinycc-devel] question about bit-fields
 To: tinycc-devel@nongnu.org
 Date: Sunday, May 27, 2012, 7:47 AM
 
   Is there an option or a declaration to make tcc
 compute the expected
   length for unsigned-int-based bit fields?
  
  No, there isn't.
  
  AFAIK the C standard says this is
 implementation-defined.
  For portability don't use bitfields.
 
 Thank for your answer. I see the problem. I added a check
 for this
 compiler's behaviour in my configure script.
 
 The code of my example is a reduced version of struct iphdr
 defined
 by GNU libc's netinet/ip.h. It means that every programs
 using the
 GNU libc's IPv4 header (or its BSD variant) cannot work fine
 if built
 with tinycc.
 
 Regards,
 Didier
 
 -Inline Attachment Follows-
 
 ___
 Tinycc-devel mailing list
 Tinycc-devel@nongnu.org
 https://lists.nongnu.org/mailman/listinfo/tinycc-devel
 

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] question about bit-fields

2012-05-27 Thread Michael Matz

Hi,

On Sun, 27 May 2012, Rick Hodgin wrote:


Didier,

You're able to take the code and modify that requirement.  It seems 
straight-forward enough that TinyCC is (in memory at compile-time) 
determining the target size, regardless of the storage size, and using 
that for the storage size in memory.  You could alter that code to 
always use the smallest storage-size, and automatically upsize to the 
larger form, such as something stored as 1..7 bits always being stored 
as a single byte, even if it's scoped as an int.


If one changes anything at all then it only makes sense to change it so as 
to be layout compatible with GCC.  A third layout (GCC, TCC-old, TCC-new) 
wouldn't help.  Although the rules of GCC are relatively obscure and 
complex in corner cases.



Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] question about bit-fields

2012-05-27 Thread Rick C. Hodgin
Alright. Sounds good. I'm in. :-)

Best regards,
Rick C. Hodgin

 Original Message 
 From: Michael Matz matz@frakked.de
 Sent: Sun, May 27, 2012 04:49 PM
 To: tinycc-devel@nongnu.org
 CC: 
 Subject: Re: [Tinycc-devel] question about bit-fields

Hi,

On Sun, 27 May 2012, Rick Hodgin wrote:

 Didier,

 You're able to take the code and modify that requirement.  It seems 
 straight-forward enough that TinyCC is (in memory at compile-time) 
 determining the target size, regardless of the storage size, and using 
 that for the storage size in memory.  You could alter that code to 
 always use the smallest storage-size, and automatically upsize to the 
 larger form, such as something stored as 1..7 bits always being stored 
 as a single byte, even if it's scoped as an int.

If one changes anything at all then it only makes sense to change it so as 
to be layout compatible with GCC.  A third layout (GCC, TCC-old, TCC-new) 
wouldn't help.  Although the rules of GCC are relatively obscure and 
complex in corner cases.


Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] question about bit-fields

2012-05-27 Thread Michael Matz

Hi,

On Sun, 27 May 2012, Michael Matz wrote:

If one changes anything at all then it only makes sense to change it so 
as to be layout compatible with GCC.  A third layout (GCC, TCC-old, 
TCC-new) wouldn't help.  Although the rules of GCC are relatively 
obscure and complex in corner cases.


Actually I have to correct myself here.  After studying the layout code a 
bit I see that TCC implements mostly microsoft's bit-field layout.  We 
don't want to get rid of that capability, so GCCs layout (which is PCC 
layout for i386 and arm AAPCS, and funky layout for legacy arm) would have 
to be implemented in addition.



Ciao,
Michael.

___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] include more options in configure

2012-05-27 Thread Pedro A ARANDA

 Subject: Re: [Tinycc-devel] include more options in configure to be
   able to build tinycc with debian
 Message-ID: 201205252045.44099.robo...@celest.fr
 Content-Type: text/plain; charset=utf-8
 
 Le vendredi 25 mai 2012 19:59:59, Pedro A ARANDA a ?crit :
  I  needed to force configure to ignore the following options for a
  successful build in Debian/Ubuntu
  
--build=*|--sysconfdir=*|--localstatedir=*|--libexecdir=*
--disable-maintainer-mode|--disable-dependency-tracking
 
 I don't understand. If I do ./configure --prefix=/usr I get the same 
 parameter 
 as if the package was installed from the package. If you want it in 
 /usr/local 
 then there's even nothing to do as it's the default. What do you get when 
 running ./configure and what would you like to get?
 
  
  It would be nice if there was some way this could be included in future
  versions,
  
  /PA
 
 Best regards,
 
 Thomas Preud'homme

Salut Thomas,

I fear I didn't tell the whole story , sorry :( The problem is not when you 
call ./configure directly but when you call it from dpkg-buildpackage to 
actually build the package. In this case, configure is excepted not to report 
an error on the options of my first mail. I have seen other configure scripts 
that send out a warning (unknown option) but continue processing the command 
line. That would be the best solution. I have checked that myself and it works. 
With the last mob, tcc builds as a .deb package both for i386 and x86_64 
flawlessly. I have it running on Ubuntu 12.04LTS on an Atom netbook and on my 
(desk|lap)top.

I ould also like to report that I have been able to compile and run the last 
tinycc mob on a 64 bit MAC (Snow Leopard). I'm currently investigating what is 
happenning on a 32 bit system, where tcc just bails out with a stack alignment 
trap during the build process...

Cheers,/PA
  ___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel