Re: [Tinycc-devel] Segfault due to ebaa5c8 dynamic executables (PIE)
On Sat, Aug 13, 2022 at 11:36:00AM +0200, Herman ten Brugge wrote: > I changed debug check in tccdbg.c on mob. Could you try again. > > Herman > > > On 8/6/22 21:35, Arthur Williams wrote: > > Was trying to compile X and noticed that it failed building hw/xfree86/ > > > > Turns out tcc was segfaulting by trying to deference a null address. > > Bisected mob to conclude that this regression was introduced by > > `ebaa5c8 dynamic executables (PIE)`. > > > > Also built tcc with its backtracing support and re-ran to get the > > following output: > > ``` > > 7f282ff1293c : by ??? > > tccelf.c:311: by section_ptr_add > > tccdbg.c:453: by put_stabs > > tccdbg.c:477: by put_stabn > > ``` > > > > And putting that all together, `section_ptr_add` received a null `Section` > > which implies `stab_section` is null. Double-checked this conclusion by > > adding an assert. > > > > Not too familiar with this part of the code so thought I'd just share my > > observations. > > > > Arthur > > > Thanks. I can no longer repro this issue on mob. Arthur ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] Segfault due to ebaa5c8 dynamic executables (PIE)
Was trying to compile X and noticed that it failed building hw/xfree86/ Turns out tcc was segfaulting by trying to deference a null address. Bisected mob to conclude that this regression was introduced by `ebaa5c8 dynamic executables (PIE)`. Also built tcc with its backtracing support and re-ran to get the following output: ``` 7f282ff1293c : by ??? tccelf.c:311: by section_ptr_add tccdbg.c:453: by put_stabs tccdbg.c:477: by put_stabn ``` And putting that all together, `section_ptr_add` received a null `Section` which implies `stab_section` is null. Double-checked this conclusion by adding an assert. Not too familiar with this part of the code so thought I'd just share my observations. Arthur ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Re: [Tinycc-devel] Segfault on musl with '-run'
On Thu, Jul 21, 2022 at 12:49:33AM -0600, arn...@skeeve.com wrote: > Arthur Williams via Tinycc-devel wrote: > > > when I changed the shebang to '#!/bin/tcc -run -g -bt4'. > > #! doesn't work that way; tcc won't get all those flags as > separate arguments. Try running from the command line. > > Arnold Thanks for the response Arnold. According to the man page, tcc wants all those arguments as one token so I believe the shebang works as I expected and the code compiles. Anyways figured out what went wrong. I had `LDFLAGS=-static` set in my environment when building. When tcc was rebuilt without this flag, then my problem went away. So guess this is a problem with building tcc statically at least on musl. Arthur ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Re: [Tinycc-devel] Segfault on musl with '-run'
On Wed, Jul 20, 2022 at 08:20:27PM +0200, grischka wrote: > On 20.07.2022 06:03, Arthur Williams via Tinycc-devel wrote: > > Hi, > > > > Was writing an application and noticed a bug. The script can be reduced > > to the following: > > > > ``` > > #!/bin/tcc -run > > #include > > int main() { > > struct timespec start, current; > > clock_gettime(CLOCK_MONOTONIC, &start); // Segfaults > > } > > ``` > > > > When the file is executed, it crashes at the indicated line. If I > > explicitly compile the program and run it, it behaves correctly. Also tested > > the same script on a glibc based machine and it also didn't crash. > > > > Not sure exactly what's special about the call to `clock_gettime`, but > > replacing it with something trivial or a printf avoids the crash. > > Maybe tcc and the system disagree about the sizeof (struct timespec) ? > > -- gr When compiling via tcc with '-run' and without it, sizeof(struct timespec) is the same (16). I did attempt to generate a backtrace to debug. However, I got the following errors ``` tcc: error: undefined symbol 'strchr' tcc: error: undefined symbol 'stderr' tcc: error: undefined symbol 'fprintf' tcc: error: undefined symbol 'fflush' ``` when I changed the shebang to '#!/bin/tcc -run -g -bt4'. Probably should have first stated that I was using 1.2.2. Upgrading to 1.2.3 didn't change the behavior though. Arthur ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] Segfault on musl with '-run'
Hi, Was writing an application and noticed a bug. The script can be reduced to the following: ``` #!/bin/tcc -run #include int main() { struct timespec start, current; clock_gettime(CLOCK_MONOTONIC, &start); // Segfaults } ``` When the file is executed, it crashes at the indicated line. If I explicitly compile the program and run it, it behaves correctly. Also tested the same script on a glibc based machine and it also didn't crash. Not sure exactly what's special about the call to `clock_gettime`, but replacing it with something trivial or a printf avoids the crash. Arthur ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] Segfault when using '-static'
So noticed that I can no longer build static packages with tcc. ``` $ cat test.c int main(){return 0;} $./tcc -static test.c Segmentation fault ``` I ran through git-bisect and concluded the regression was introduced in 4c82b003420fabbb95e077866784badc1a49189b: Update for elflint problems. Simply reverting the commit allows the above example to not error. Any objection to just reverting the offending commit. - Arthur ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Re: [Tinycc-devel] Initialiser overflow bug
On Thu, Mar 10, 2022 at 10:27:25AM -0800, Elijah Stone wrote: > Hi, > > The following code results in an initialiser overflow ICE on the latest > version of tcc (917aad3), amd64 linux. > > #include > #include > > typedef struct { char b[2]; } Barb; > > Barb *f(Barb x, Barb y) { > return memcpy(malloc(2*sizeof(Barb)), &(Barb[]){x,y}, 2*sizeof(Barb)); > } > > Note: if I declare char b[1] in Barb, there is no error; but the error > occurs on any larger size. Posted about the same issue a month ago. And I believe someone had reported the issue even before that. Last theory I heard was that the cast might be affecting padding. I believe if you have ``` Barb temp[2] = {x,y}; ``` and used temp in the memcpy you can avoid this issue. At least for me, the fact the issue is so easy to avoid is why it isn't at the top of my priority list. Arthur ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] initializer overflow with arrays on implicit size
Greetings, Found a strange error when trying to build a program with tcc. The error is ``` test.c:8: error: internal compiler error tccgen.c:7728: in init_assert(): initializer overflow ``` And here is a minimal example of how to repro it. ``` #include struct A { char a; char b; }; int main() { struct A a[] = { (struct A){1}, (struct A){2}, }; printf("%d %d\n", a[0].a, a[0].b); printf("%d %d\n", a[1].a, a[1].b); return 0; } ``` (printing isn't need to repro the problem) Took a glance at the code that was generating the error message: `init_assert`. The commit message for that function seems to imply that is was temporary and removing this function avoid the error and allows the code to compile. Tests pass and the output is also as expected. Is there a reason to keep this function around? Playing around with the function removed and while the code compiles find, running with `tcc -run` segfaults. So I imagine the real fix is a bit less trivial that what I had thought. Arthur ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel