Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000040 [libFirm] backend minor always 2009-03-03 00:51 2010-08-13 13:02
Reporter moritz View Status public  
Assigned To Matze
Priority normal Resolution fixed  
Status closed   Product Version 1.16.0
Summary 0000040: __attribute__((constructor)) and __attribute__((destructor)) don't work on Cygwin
Description 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.
Attached Files

- Relationships

-  Notes
Matze (administrator)
2009-03-03 21:19

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.
moritz (manager)
2009-03-04 10:39

Sounds reasonable.
Info: __main does not take any arguments.
Here's the whole _main function of construct_destruct.c as generated by gcc:

    pushl %ebp
    movl $16, %eax
    movl %esp, %ebp
    subl $8, %esp
    andl $-16, %esp
    call __alloca
    call ___main
    movl $LC2, (%esp)
    call _puts
    xorl %eax, %eax

A test without the explicit stack aligning also worked.
moritz (manager)
2009-03-04 12:14

More info on the magical ___main function can be found at: [^]
Matze (administrator)
2009-03-09 21:02

r25652 calls __main now on mingw target. Please try if that fixes the problem.
moritz (manager)
2009-03-09 21:37

Yes, it works, thanks!
It's your honor to mark it as resolved ;)

- Issue History
Date Modified Username Field Change
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
Powered by Mantis Bugtracker