Page MenuHomePhabricator

Default to -fuse-init-array

Authored by MaskRay on Dec 11 2019, 10:38 PM.



Very few ELF platforms still use .ctors/.dtors now. Linux (glibc: 1999-07),
DragonFlyBSD, FreeBSD (2012-03) and Solaris have supported .init_array
for many years. Some architectures like AArch64/RISC-V default to
.init_array . GNU ld and gold can even convert .ctors to .init_array .

It makes more sense to flip the CC1 default, and only uses
-fno-use-init-array on platforms that don't support .init_array .
For example, OpenBSD did not support DT_INIT_ARRAY before Aug 2016

I may miss some ELF platforms that still use .ctors, but their
maintainers can easily diagnose such problems.

Event Timeline

MaskRay created this revision.Dec 11 2019, 10:38 PM

Fan of this change, but let's definitely wait for more reviews :)

sberg added a subscriber: sberg.Dec 11 2019, 11:40 PM

The title should probably read "Default to -fuse-init-array" (dropping the "no-")?

MaskRay retitled this revision from Default to -fno-use-init-array to Default to -fuse-init-array.Dec 12 2019, 9:30 AM
rnk accepted this revision.Dec 12 2019, 10:12 AM

+1, the list of exceptions that will use .ctors is smaller than the list of platforms that default to init_array. And in general, I support anything that reduces the length of -cc1 command lines for standard compilation (for example, -mthread-model, which is basically always posix).

I think we have enough approver power to land it.


I'd like to consider inverting the default. I suspect for a lot of the cases where this results in defaulting to ctors, we actually want to use init_array. However, that would be a functional change, and therefore out of scope.

This revision is now accepted and ready to land.Dec 12 2019, 10:12 AM
This revision was automatically updated to reflect the committed changes.
MaskRay marked an inline comment as done.Dec 12 2019, 10:47 AM
MaskRay added inline comments.

The difficult part of "inverting the default" is to figure out the exceptions ;-) I am preparing a patch for that.