Page MenuHomeFreeBSD

rtld-elf: Support IFUNCs on riscv
ClosedPublic

Authored by jrtc27 on Aug 13 2024, 4:24 AM.
Tags
None
Referenced Files
F102929883: D46278.diff
Mon, Nov 18, 9:25 PM
Unknown Object (File)
Sat, Nov 16, 2:22 PM
Unknown Object (File)
Fri, Nov 15, 5:14 AM
Unknown Object (File)
Fri, Nov 1, 1:38 AM
Unknown Object (File)
Sun, Oct 20, 2:27 AM
Unknown Object (File)
Oct 16 2024, 2:39 AM
Unknown Object (File)
Oct 13 2024, 8:52 AM
Unknown Object (File)
Oct 11 2024, 5:51 PM
Subscribers

Details

Summary

GNU/Linux has historically had the following two resolver prototypes:

  1. Elf_Addr(uint64_t, void *)
  2. Elf_Addr(uint64_t, void *, void *)

For the former, AT_HWCAP is passed in the first argument, and NULL in
the second. For the latter, AT_HWCAP is still passed, and the second
argument is a pointer to their home-grown __riscv_hwprobe function.
Should they want to use the third argument in future, they'll have to
introduce yet another prototype to allow for later expansion, and then
all users will have to check whether the second argument is NULL to know
if the third argument really exists. This is all rather silly and will
surely prove fun in the face of type-checking CFI.

Instead, be like arm64 and just define all 8 possible general purpose
register arguments up front. To naive source code that forgets non-Linux
OSes exist this will be compatible with prototype 1 above, since the
second argument will be 0 and it won't look further (though should we
start using the second argument for something that wouldn't be true any
more and it might think it's __riscv_hwprobe, but that incompatibility
is one we can defer committing to, and can choose to never adopt).

Until the standard interface for querying extension information[1] is
settled and implemented in FreeBSD there's not much you can do in a
resolver other than use HWCAP_ISA_B, but this gets the infrastructure in
place for when that day comes.

[1] https://github.com/riscv-non-isa/riscv-c-api-doc/pull/74

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

In the first sentence of the summary, I believe you are talking about prototype for the resolver functions?

This revision is now accepted and ready to land.Aug 13 2024, 8:53 AM
In D46278#1055441, @kib wrote:

In the first sentence of the summary, I believe you are talking about prototype for the resolver functions?

Yes, description now clarified

Looks reasonable. Thank you for taking your time writing this!

mhorne added a subscriber: mhorne.

I don't fully understand the rtld/ifunc machinery, so I can't give much feedback on the implementation here although it seems straightforward. Some cosmetic tweaks suggested.

I feel good about the current approach of providing AT_HWCAP to the resolver, until the interface is standardized.

In a future patch (soon) I will add the parsing/export of HWCAP_ISA_ZBA/HWCAP_ISA_ZBB.

libexec/rtld-elf/riscv/reloc.c
231–232

These args are now used, so drop the annotations. Some functions below have this problem too.

241

Suggested spacing. Here and in the functions below.

245

Here and below.

286–296

The whole code block is visually dense; I would add a space here.

The various spacing issues you pointed out are all present in the arm64 code I based this on. I'll go fix it there first.

In a future patch (soon) I will add the parsing/export of HWCAP_ISA_ZBA/HWCAP_ISA_ZBB.

Historically on arm64 we've aligned AT_HWCAP* with Linux's definition. I'm not sure we want to deviate from that practice on riscv.

This revision was automatically updated to reflect the committed changes.