This is an archive of the discontinued LLVM Phabricator instance.

[ELF/LinkerScript] Support ONLY_IF_{RO, RW} directive
ClosedPublic

Authored by davide on Jul 21 2016, 7:23 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

davide updated this revision to Diff 65013.Jul 21 2016, 7:23 PM
davide retitled this revision from to [ELF/LinkerScript] Support ONLY_IF_{RO, RW} directive..
davide updated this object.
davide retitled this revision from [ELF/LinkerScript] Support ONLY_IF_{RO, RW} directive. to [ELF/LinkerScript] Support ONLY_IF_{RO, RW} directive.
davide added a reviewer: ruiu.
davide added a subscriber: llvm-commits.

Including llvm-commits.

ruiu edited edge metadata.Jul 21 2016, 7:37 PM

Is this a feature to build FreeBSD?

ELF/LinkerScript.cpp
269 ↗(On Diff #65013)

I would not use a default argument here.

282 ↗(On Diff #65013)

Why don't you set Live flag of the section to false?

816 ↗(On Diff #65013)

You can write

if (skip("ONLY_IF_RO"))
ELF/LinkerScript.h
70 ↗(On Diff #65013)
ConstraintKind Constraint = NoConstraint;
In D22660#492409, @ruiu wrote:

Is this a feature to build FreeBSD?

https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l78
As a general note, I'm going to implement only linker script directives/linker features for software running in the wild. You can keep that in mind.
Going to update the patch in a minute.

davide updated this revision to Diff 65018.Jul 21 2016, 7:53 PM
davide edited edge metadata.

Addressed comments (at least a subset of them).

ELF/LinkerScript.cpp
282 ↗(On Diff #65013)

From what I see OutputSections have no Live flag, so, I assume you mean InputSections.
I'm not very familiar with the gc code, so I'll ask you. Is marking a single InputSection "dead" enough to prevent the output section to appear in the output?
You set the Live flag to false while processing \DISCARD\ in order to avoid input sections to appear in the output, but the semantic is a little bit different here.

Thanks!

ruiu added a comment.Jul 21 2016, 8:15 PM

I really appreciate adding linker script features as-needed basis. Still I got to ask for a reference if its not in a commit message, so please include a sentence that "it's used by FreeBSD kernel". :)

ELF/LinkerScript.cpp
277 ↗(On Diff #65018)

I see the reason why you need it, but it can be done without adding a new field to OutputSection because this flag is used only in this function. You can define

DenseSet<OitputSectionBase<ELFT>> Removed;

and add a section to the set of it needs to be removed at end of this function.

davide updated this revision to Diff 65024.Jul 21 2016, 8:28 PM
ruiu accepted this revision.Jul 21 2016, 8:38 PM
ruiu edited edge metadata.

LGTM with a nit.

ELF/LinkerScript.cpp
815 ↗(On Diff #65024)

You want to remove this line.

This revision is now accepted and ready to land.Jul 21 2016, 8:38 PM
This revision was automatically updated to reflect the committed changes.