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)
Feb 23 2024, 2:10 PM
Unknown Object (File)
Dec 20 2023, 1:19 AM
Unknown Object (File)
Dec 12 2023, 8:40 AM
Unknown Object (File)
Nov 28 2023, 7:17 PM
Unknown Object (File)
Nov 25 2023, 6:40 PM
Unknown Object (File)
Nov 24 2023, 8:46 AM
Unknown Object (File)
Nov 23 2023, 4:17 AM
Unknown Object (File)
Nov 22 2023, 2:59 AM

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.