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.
Details
- Reviewers
- None
- Group Reviewers
lld
Diff Detail
Event Timeline
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?
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.
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.
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.