This is an archive of the discontinued LLVM Phabricator instance.

Default to -fuse-init-array
ClosedPublic

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

Details

Summary

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
(https://github.com/openbsd/src/commit/86fa57a2792c6374b0849dd7b818a11e676e60ba)

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

Diff Detail

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.

clang/lib/Driver/ToolChains/Gnu.cpp
2786–2799

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.
clang/lib/Driver/ToolChains/Gnu.cpp
2786–2799

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