|Anonymous | Login | Signup for a new account||2020-02-28 04:07 CET|
|Main | My View | View Issues|
|Viewing Issue Simple Details|
|ID||Category||Severity||Reproducibility||Date Submitted||Last Update|
|0000040||[libFirm] backend||minor||always||2009-03-03 00:51||2010-08-13 13:02|
|Summary||0000040: __attribute__((constructor)) and __attribute__((destructor)) don't work on Cygwin|
There are two problems with the assembler code generated by libFirm e.g. for firm_testsuite/C/gnu99/construct_destruct.c on Cygwin:
1. The .ctors and .dtors sections are declared like '.section .ctors,"w",@progbits' which is not valid syntax for GAS in MinGW mode. (already solved)
2. The assembler code generated by gcc calls the magical function "___main" at the very begining of main (after initializing the stack frame and aligning the stack). Without this function call the constructors and destructors are not called.
|Additional Information||The "___main" function is called independently of whether there are constructors/destructors or not. It seems to be defined in gcc/libgcc2.c in the gcc source code (SYMBOL__MAIN).|
|Tags||No tags attached.|
So if I understand that correctly, we have to add a call to ___main at the beginning of the main function.
The remaining question is wether this should be added by libfirm or the frontend.
I'd tend to put it into the frontend as the frontend is already responsible for other platform quirks like the name mangling of functions (with _ prefix on windows, without on linux, ...)
It's also not necessarily clear to libfirm what the "main" function is.
Info: __main does not take any arguments.
Here's the whole _main function of construct_destruct.c as generated by gcc:
movl $16, %eax
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $LC2, (%esp)
xorl %eax, %eax
A test without the explicit stack aligning also worked.
|More info on the magical ___main function can be found at: http://gcc.gnu.org/onlinedocs/gccint/Collect2.html [^]|
|r25652 calls __main now on mingw target. Please try if that fixes the problem.|
Yes, it works, thanks!
It's your honor to mark it as resolved ;)
|2009-03-03 00:51||moritz||New Issue|
|2009-03-03 21:19||Matze||Note Added: 0000062|
|2009-03-03 21:19||Matze||Status||new => confirmed|
|2009-03-03 21:20||Matze||version||=> 1.16.0|
|2009-03-04 10:39||moritz||Note Added: 0000064|
|2009-03-04 12:14||moritz||Note Added: 0000065|
|2009-03-09 21:02||Matze||Note Added: 0000079|
|2009-03-09 21:02||Matze||Assigned To||=> Matze|
|2009-03-09 21:37||moritz||Note Added: 0000080|
|2009-03-09 23:32||Matze||Status||confirmed => resolved|
|2009-05-15 16:50||Matze||Status||resolved => closed|
|2010-08-13 13:02||Matze||Resolution||open => fixed|
|Mantis 1.1.5[^] Copyright © 2000 - 2008 Mantis Group|