Grischka, > > Please find attached, a patch that modify TCC so that it can pack > > bit fields the way GCC does. The mechanism is optional and off by > > default. It can be enabled with the -fgcc-packing option. > > ... the way GCC does? > > > I added this mechanism because I want to use TCC to compile some > > code that manages IPv4 headers [1]. The code uses the 'struct > > iphdr' of the GNU libc, and relies on its size doing exactly 20 > > bytes. TCC does not compute the structure length the same way GCC > > does, and the program fails. > > ... the same way GCC does? > > > Someone told me that I can add code to mimic the behaviour of GCC. > > The attached patch is an attempt to do so. It is probably not very > > good as I didn't known TCC's codebase before, but it seems to work. > > I'm open for comments on it. I tested my modifications with the > > attached test program. > > ... to mimic the behavior of GCC? > > Just curious: What now is this way/behavior of GCC, actually? > > Because as you say, maybe the patch is not very good (e.g. suspicious > "copy & paste" portion) but you didn't know TCC before. > > Then again maybe some people here know TCC but still can't really > comment your patch or suggest improvements because they don't know > the details about GCC's bit packing right now.
Sorry, it was discussed in previous emails, but I forgot to repeat it. Here are some more details. On a structure such as: struct mystruct1 { unsigned int mystruct1_foo:4; unsigned int mystruct1_bar:4; uint8_t mystruct1_other; uint16_t mystruct1_other2; }; The 2 first fields uses 1 byte with GCC/Clang while they use sizeof(unsigned int) bytes with TCC. GCC/Clang pack the bit fields on the smaller type available. So, sizeof(struct mystruct1) = 4 with GCC/Clang and sizeof(struct mystruct1) = 8 with TCC. My program (and probably many others, as the struct iphdr for IPv4 header defined by the GNU libc is defined that way) relies on this behaviour. That's why I created the patch. It packs bit fields "the way GCC does". If you got a better description, I'll be happy to change it :) Regards, Didier
signature.asc
Description: PGP signature
_______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel