Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000066 [libFirm] backend minor always 2011-06-04 17:47 2011-12-24 03:47
Reporter piper View Status public  
Assigned To Matze
Priority normal Resolution fixed  
Status closed   Product Version development
Summary 0000066: wrong section type for ELF .ctors section
Description In emit_section in ir/be/begnuas.c, the section type for section "ctors" is "init_array". GCC uses "progbits" for this section on ELF platforms.

Due to the mismatch, C++ static constructors emitted by libfirm are not linked into the same .ctors section, and are not run. Changing libfirm to use "progbits" instead of "init_array" results in working C++ static constructors.
Additional Information
Tags No tags attached.
Attached Files

- Relationships

-  Notes
Matze (administrator)
2011-06-17 20:20

The gnu ld docu indicates that @init_array is the correct thing to use. We tried a few combinations of linking together gcc and libfirm compiled code and it worked in all cases on ubuntu 11.04. Can you tell us how to reproduce the bug?
piper (reporter)
2011-06-21 17:41

I also tested on Ubuntu 11.04. But I have binutils-gold installed, which seems to be what makes the difference. I found that with, constructors in @init_array sections don't get run. With ld.bfd, they do get run.

Constructors in @progbits sections work with both. Also, this is what GCC uses:

$ readelf -SW /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/crtbegin.o |grep '\.ctors'
  [ 5] .ctors PROGBITS 0000000000000000 0000e0 000008 00 WA 0 0 8


$ cat
struct A { A(); } a;
$ g++ -S -o - | grep '\.ctors'
    .section .ctors,"aw",@progbits

And several other non-Ubuntu boxes with different versions of GCC also use @progbits for .ctors.

I didn't find anything in the gnu ld documentation which covered this.
Matze (administrator)
2011-06-21 21:44

Thanks for the additional input. I've been reading about sections here: [^]

What the documentation didn't say and I found after more reading on the net now: It appears that .ctors/.dtors sections are a traditional way to have constructors running (and I guess @progbits is correct there). There is a more modern way using 2 sections called .init_array, .fini_array for which the @init_array, @fini_array are the right thing to use. It appears gcc people are slowly converting to this new style on selected platforms.

Anyway since not working in gold is a real issue we're back to @progbits in commit 7cea41f

- Issue History
Date Modified Username Field Change
2011-06-04 17:47 piper New Issue
2011-06-17 20:20 Matze Note Added: 0000104
2011-06-17 20:20 Matze Status new => feedback
2011-06-21 17:41 piper Note Added: 0000112
2011-06-21 21:44 Matze Note Added: 0000113
2011-06-21 21:44 Matze Assigned To => Matze
2011-06-21 21:44 Matze Status feedback => resolved
2011-06-21 21:44 Matze Resolution open => fixed
2011-12-24 03:47 Matze Status resolved => closed

Mantis 1.1.5[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker