Page MenuHomeFreeBSD

rtld: set obj->textsize correctly
ClosedPublic

Authored by arichardson on Sep 11 2018, 3:26 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Dec 19, 9:56 PM
Unknown Object (File)
Thu, Dec 12, 5:56 PM
Unknown Object (File)
Thu, Dec 5, 11:46 PM
Unknown Object (File)
Nov 21 2024, 10:31 AM
Unknown Object (File)
Nov 20 2024, 7:42 AM
Unknown Object (File)
Nov 14 2024, 10:50 PM
Unknown Object (File)
Nov 6 2024, 2:40 PM
Unknown Object (File)
Oct 23 2024, 1:07 PM

Details

Summary

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.

Test Plan

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.

arichardson edited the test plan for this revision. (Show Details)

Also update map_object.c

This revision is now accepted and ready to land.Sep 13 2018, 2:39 PM
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.

This revision was automatically updated to reflect the committed changes.

Looks good to me too, and I think it's important for anything doing textrelocs on ppc.