With lld-generated binaries the first PT_LOAD will usually be a read-only
segment unless you pass --no-rosegment. For those binaries the textsize is
determined by the next PT_LOAD. To allow both LLD and bfd 2.17 binaries to
be parsed correctly use the end of the last PT_LOAD that is marked as
executable instead.
Details
- Reviewers
kib emaste jhb brooks - Commits
- rS339876: rtld: set obj->textsize correctly
I noticed that the value was wrong while adding some debug prints for some rtld changes for CHERI binaries.
obj->textsize only seems to be used by PPC so the effect is untested. However, the value before was definitely wrong and the new result matches the phdrs.
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Don't you need a similar fix for the map_object.c ? There we unconditionally use segment zero.
I believe that ppc/ppc64 would be fine with the patch, since obj->textsize is used to limit the range to flush icache. With the increase of the textsize after the patch, we would only flush more.
libexec/rtld-elf/rtld.c | ||
---|---|---|
1487 ↗ | (On Diff #47910) | sys/param.h MAX() will evaluate the arguments twice, do we have a better min/max macro that I can use here? |
libexec/rtld-elf/rtld.c | ||
---|---|---|
1487 ↗ | (On Diff #47910) | Kernel has inlines like imax() in libkern.h, but I am not aware of anything like that for userspace. |
Looks good to me too, and I think it's important for anything doing textrelocs on ppc.