This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Linkerscript: ignore SORT(CONSTRUCTORS)
ClosedPublic

Authored by grimar on Jul 27 2016, 2:29 AM.

Details

Summary

Some scripts can contain SORT(CONSTRUCTORS) expression:
https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l152

for ELF it just a nop:
"When linking object file formats which do not support arbitrary sections, such as ECOFF and XCOFF, the linker will automatically recognize C++ global constructors and destructors by name. For these object file formats, the CONSTRUCTORS command tells the linker to place constructor information in the output section where the CONSTRUCTORS command appears. The CONSTRUCTORS command is ignored for other object file formats."
(http://www.sourceware.org/binutils/docs-2.10/ld_3.html)

So patch implements ignoring.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 65688.Jul 27 2016, 2:29 AM
grimar retitled this revision from to [ELF] - Linkerscript: ignore SORT(CONSTRUCTORS).
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, davide, grimar, evgeny777.
davide accepted this revision.Jul 27 2016, 10:49 AM
davide added a reviewer: davide.

This LGTM, but, doesn't this collide with your other SORT() patch?

This revision is now accepted and ready to land.Jul 27 2016, 10:49 AM

This LGTM, but, doesn't this collide with your other SORT() patch?

Good question. Technically as far I understand, CONSTRUCTORS is outputsection keyword, which should be used inside SORT() at the top level.
All files wildcards I saw starts from '*', D22852 relies on that (and I think it is reasonable).
We are also do not plan to support sort by filenames AFAIK as nothing uses that.

So I think we can handle SORT(CONSTRUCTORS) just like it would be a single command to simplify processing, like that patch do.

Lets see what Rui think.

ELF/LinkerScript.cpp
445 ↗(On Diff #65688)

probably name could be skipSortConstructors() or something alike.

ruiu edited edge metadata.Jul 27 2016, 3:19 PM

This change seems correct in terms of semantics, but I got to ask why FreeBSD's linker scripts still have it if it is only for ECOFF or XCOFF file formats.

This change seems correct in terms of semantics, but I got to ask why FreeBSD's linker scripts still have it if it is only for ECOFF or XCOFF file formats.

I presume it was just based on the default linker script provided by GNU ld (from ld --verbose) years ago and nobody's had a reason to revisit it until now. I suspect most uses of it in the wild will have the same reason.

I should probably just remove it from FreeBSD's ldscript.

This change seems correct in terms of semantics, but I got to ask why FreeBSD's linker scripts still have it if it is only for ECOFF or XCOFF file formats.

I presume it was just based on the default linker script provided by GNU ld (from ld --verbose) years ago and nobody's had a reason to revisit it until now. I suspect most uses of it in the wild will have the same reason.

I should probably just remove it from FreeBSD's ldscript.

There's a lot of software I have to link that I don't have control of which use this feature. Please consider an implementation.

ruiu accepted this revision.Jul 27 2016, 5:13 PM
ruiu edited edge metadata.

LGTM. I had no objection to include this, was just wondering why FreeBSD needed this in the first place. It'd be a nice cleanup for FreeBSD to remove the call of SORT(CONSTURCTORS) from their linker scripts.

emaste added a comment.EditedJul 27 2016, 6:01 PM

It'd be a nice cleanup for FreeBSD to remove the call of SORT(CONSTURCTORS) from their linker scripts.

Agreed, patch here for reference https://reviews.freebsd.org/D7343
Note that some are just CONSTRUCTORS, not inside of SORT.

This revision was automatically updated to reflect the committed changes.