This is an archive of the discontinued LLVM Phabricator instance.

Allow SIZEOF() command on nonexistent section.
ClosedPublic

Authored by ruiu on Nov 17 2016, 12:26 PM.

Details

Summary

Linker script doesn't create a section if it has no content. So the following
script doesn't create .norelocs section if it doesn't have any .rel* sections.

.norelocs : { *(.rel*) }

Later, if you assert that the size of .norelocs is 0, LLD printed out
an error message, because it didn't allow calling SIZEOF() on nonexistent
sections.

This patch allows SIZEOF() on nonexistent sections, so that you can do
something like this.

ASSERT(SIZEOF(.norelocs), "shouldn't contain .rel sections!")

Note that this behavior is compatible with GNU.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu updated this revision to Diff 78401.Nov 17 2016, 12:26 PM
ruiu retitled this revision from to Allow SIZEOF() command on nonexistent section..
ruiu updated this object.
ruiu added a reviewer: phosek.
ruiu added a subscriber: llvm-commits.
ruiu updated this object.Nov 17 2016, 12:28 PM
phosek accepted this revision.Nov 17 2016, 12:30 PM
phosek edited edge metadata.

LGTM, thanks! Would it make sense to do the same for ALIGNOF of non-existent section for consistency?

This revision is now accepted and ready to land.Nov 17 2016, 12:30 PM
ruiu added a comment.Nov 17 2016, 12:32 PM

I don't know -- do you need it? It makes sense to me that nonexistent sections have size 0, but I'm not sure about their alignments.

In D26810#598929, @ruiu wrote:

I don't know -- do you need it? It makes sense to me that nonexistent sections have size 0, but I'm not sure about their alignments.

We don't and I've never seen it being used, so it's probably not necessary.

This revision was automatically updated to reflect the committed changes.