This is an archive of the discontinued LLVM Phabricator instance.

Covnert .[cd]tors to .{init,fini}_array using synthetic section.
Needs ReviewPublic

Authored by ruiu on Jul 17 2017, 2:30 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

This patch defines InitFiniSection synthetic section to convert
.[cd]tors to .{init,fini}_array.

Event Timeline

ruiu created this revision.Jul 17 2017, 2:30 PM
grimar added a subscriber: grimar.Jul 18 2017, 2:44 AM
orivej added a subscriber: orivej.Jul 24 2017, 4:50 AM

@ruiu I'd appreciate if you continue with this review.

WRT toInitFiniName — section renaming was just a hack, and it is absent from my final patch. Is it really needed here?

rafael added inline comments.
lld/ELF/SyntheticSections.h
130

Do we need a new type?

You can have a standalone function that does the conversion and creates a InputSection directly. Not that different from how .comment is created.

lld/ELF/Writer.cpp
137

We have to check if all systems support .init_array. Ed, can you confirm?

emaste added inline comments.
lld/ELF/Writer.cpp
137

FreeBSD support was added in r232831 in March 2012.

NetBSD has support, although I don't know if there are platform-specific differences. I'm not sure about OpenBSD; I see patches were posted last year but I do not know if they were merged in. Perhaps @joerg and @kettenis can add more info?

grimar added inline comments.Jul 25 2017, 12:56 AM
lld/ELF/Writer.cpp
137

Should we show warning when have .ctors/.dtors ?

I added support for .init_array and .fini_array to OpenBSD's ld.so almost a year ago. It hasn't been extensively tested on architectures other than arm64, but there is no reason why it shouldn't work on other architectures. We don't really have any ABI concerns.

However, .init_array and .fini_array don't work (yet) for static binaries. I don't think that's a major issue.

joerg added a comment.Jul 25 2017, 5:11 AM

Warning for .ctor/.dtor use would IMO be completely bogus. They can easily be translated and they are kind of the LCD for "portable" assembler, i.e. much less problematic to deal with than plain .init/.fini segments.

ruiu updated this revision to Diff 120520.Oct 26 2017, 5:44 PM
  • Resurrect an old patch to support .ctors/.dtors to be used with .init/fini.
joerg added inline comments.Oct 27 2017, 2:13 AM
lld/ELF/SyntheticSections.cpp
124

This comment is bogus, since .init/.fini is a completely different thing.

lld/ELF/Writer.cpp
137

NetBSD uses .init_array only on new archs (arm64) and where mandated by the ABI (arm-eabi).