This is an archive of the discontinued LLVM Phabricator instance.

[LLD] Combine read-only and writable input sections into single output section
AbandonedPublic

Authored by kettenis on Dec 20 2016, 7:27 AM.

Details

Reviewers
None
Group Reviewers
lld
Summary

On OpenBSD crtbegin.o has a read-only .ctors section whereas crtend.o has a writable .ctors.
This results in two separate .ctors sections in the output, making the resulting executable crash
because the sentinel from crtend.o is stored in the second .ctors section which doesn't immediately
follow the first .ctors section. This can be easily fixed by masking off the SHF_WRITE flag when
creating the key that is used to look up the output section. This will combine the input sections
into a single output sections that is marked as writable. This matches the behaviour of the GNU
toolchain.

Diff Detail

Event Timeline

kettenis updated this revision to Diff 82093.Dec 20 2016, 7:27 AM
kettenis retitled this revision from to [LLD] Combine read-only and writable input sections into single output section.
kettenis updated this object.
kettenis added a reviewer: lld.
kettenis added a subscriber: llvm-commits.

Didn't write a test for this yet as I couldn't figure out how to create a test with multiple input object files
Is there an example of such a test in the lld test suite?

emaste added a subscriber: emaste.Dec 20 2016, 7:30 AM

This needs a test case.

See also http://llvm.org/pr30415.

Our messages crossed paths. There are tests that use separate input files which are in the Inputs/ directory.

Others might comment on the best / canonical example to start from, but one example is relocatable.s.

kettenis updated this revision to Diff 82150.Dec 20 2016, 2:07 PM

Added a test case.

Note that the cited PR is about merging segments instead of sections; a not entirely unrelated, but different issue.

Rafael pointed out that the current behaviour matches the ELF specification.

I verified that the Solaris ld also doesn't concatenate the sections in this case.

Consider this diff withdrawn.

kettenis abandoned this revision.Dec 21 2016, 4:12 AM

Rafael pointed out that the current behaviour matches the ELF specification.

I verified that the Solaris ld also doesn't concatenate the sections in this case.