Hello everyone,
I recently uncovered some segfaulting code when compiling code with macros that manipulate certain Perl structs on 64-bit Linux. I boiled the problem down to a discrepancy between how tcc and gcc determine the size needed by a series of bit fields. The tcc-compiled function would get the Perl interpreter struct produced by gcc-compiled code, then reach into the wrong memory slot for something. A reduced example is provided below.
Question 1: Would anybody be opposed to changing tcc's behavior to match gcc's behavior here? This could lead to binary incompatibility with object code previously compiled with tcc, but that seems to me highly unlikely to be a real problem for anyone.
Question 2: Does anybody know tccgen.c well enough to fix this? I can work on it, but if anybody knows exactly where this goes wrong, it would save me a few hours.
--------%<--------
#include <stdint.h>
#include <stdio.h>
struct t1 {
uint8_t op_type:1;
uint8_t op_flags;
};
struct t2 {
uint32_t op_type:1;
uint8_t op_flags;
};
struct t3 {
unsigned op_type:1;
char op_flags;
};
int main() {
printf("t1 struct size: %ld\n", sizeof(struct t1));
printf("t2 struct size: %ld\n", sizeof(struct t2));
printf("t3 struct size: %ld\n", sizeof(struct t3));
return 0;
}
-------->%--------