Add AT_HWCAP and AT_EHDRFLAGS on all platforms.
ClosedPublic

Authored by jhb on Sep 9 2017, 2:29 PM.

Details

Summary

AT_HWCAP is populated with the value of global elf32_hwcap and
elf64_hwcap values. Platform-specific code can adjust these
global variables to control the values passed in exec.

Test Plan

This is part of a series which I tested by using VFP registers with
gdb on armv7. powerpc could probably set elf*_hwcap easily as I think
we currently export sysctls with those values now.

I think moving AT_* to elf_common.h is still a useful followup.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
jhb created this revision.Sep 9 2017, 2:29 PM
emaste added a comment.Sep 9 2017, 2:39 PM

Looks good to me.

I think it's sensible to follow up with migration to a single elf.h, probably @jhibbits can first make powerpc's match the rest?

stevek added a subscriber: stevek.Sep 9 2017, 2:44 PM

One common typo: "CPU featire flags" should be "CPU feature flags".

kib added inline comments.Sep 9 2017, 6:04 PM
sys/kern/imgact_elf.c
140 ↗(On Diff #32846)

Shouldn't this be per elf brand or per sysvec, I am not sure which one is more useful, perhaps sysvec is enough.

I believe that requiring that linux and native hwcap bits always match is not going to work, even ifit is now.

jhb added inline comments.Sep 9 2017, 9:55 PM
sys/kern/imgact_elf.c
140 ↗(On Diff #32846)

The callback that uses it (elf32/64freebsd_fixup) is already per-sysvec. Non-FreeBSD ABIs have to use a separate sv_fixup callback to set their ABI-specific auxv values which won't use this variable (e.g. elf_linux_fixup in sys/amd64/linux32/linux32_sysvec.c)

kib accepted this revision.Sep 10 2017, 8:34 AM
kib added inline comments.
sys/kern/imgact_elf.c
140 ↗(On Diff #32846)

Yes, I do not like that the variable is global instead of living in sysvecent.

This revision is now accepted and ready to land.Sep 10 2017, 8:34 AM
jhb added inline comments.Sep 10 2017, 11:24 AM
sys/kern/imgact_elf.c
140 ↗(On Diff #32846)

Hmm, I could either store a pointer to a variable in sysvecent or the variable itself in the sysvecent. The latter would require exporting the entire sysvecent as an extern and probably makes it harder to share values across sysvecent if needed (e.g. I imagine on aarch64 the same hwcap might end up being shared for an eventual COMPAT_FREEBSD32), so perhaps the first is better?

kib added inline comments.Sep 10 2017, 11:33 AM
sys/kern/imgact_elf.c
140 ↗(On Diff #32846)

A pointer to a variable sounds fine.

On ARM platforms I expect we'll need more bits. Linux already has AT_HWCAP2, it might pay to include it from the start.

jhb updated this revision to Diff 32980.Sep 12 2017, 6:39 PM
  • Replace elf32/64_hwcap with a sv_hwcap pointer in sysentvec.
  • Only provide AT_HWCAP if the pointer exists.
This revision now requires review to proceed.Sep 12 2017, 6:39 PM
jhb updated this revision to Diff 32981.Sep 12 2017, 6:41 PM
  • Fix feature typo.
jhb marked 2 inline comments as done.Sep 12 2017, 6:43 PM

Re: AT_HWCAP2, once elf.h is unified (which I will probably work on soon) it will be fairly easy to add.

One question is if 'u_long' is the right type for 'sv_hwcap'.

kib accepted this revision.EditedSep 13 2017, 9:42 AM
In D12290#255968, @jhb wrote:

One question is if 'u_long' is the right type for 'sv_hwcap'.

De-facto long becomes the way to express the 'native word size' of a machine. It is used more often than register_t, and I think that register_t is actually wrong e.g. on mips n32 for this purpose.

So the actual initialization of *sv_hwcap for native sysents will follow in a separate patch, I suppose ?

This revision is now accepted and ready to land.Sep 13 2017, 9:42 AM
jhb added a comment.Sep 14 2017, 12:21 AM
In D12290#256189, @kib wrote:
In D12290#255968, @jhb wrote:

One question is if 'u_long' is the right type for 'sv_hwcap'.

De-facto long becomes the way to express the 'native word size' of a machine. It is used more often than register_t, and I think that register_t is actually wrong e.g. on mips n32 for this purpose.

So the actual initialization of *sv_hwcap for native sysents will follow in a separate patch, I suppose ?

You can see the other patches for arm in this series if you click on 'Stack' in the revision contents box (and I'd appreciate your review on any of the others if you wish). So far I've only implemented this for arm. ppc is probably trivial to add, and arm64 may very well use the same values as 32-bit arm, but I'll defer to Andrew on that. Also, the values I have supported for arm so far are fairly limited, but more can be added by others easily enough.

This revision was automatically updated to reflect the committed changes.