Page MenuHomePhabricator

compiler-rt: Use FreeBSD's elf_aux_info for detecting ARM HW features
ClosedPublic

Authored by dim on Sep 6 2021, 10:26 AM.

Details

Summary

FreeBSD provides 'elf_aux_info' function that does the same as 'getauxval' on Linux.

Diff Detail

Event Timeline

MikaelUrankar created this revision.Sep 6 2021, 10:26 AM
MikaelUrankar requested review of this revision.Sep 6 2021, 10:26 AM
compiler-rt/lib/builtins/cpu_model.c
807

This means non-linux, non-FreeBSD systems always return false even if they prvide a getauxval() function. I would do something like the following to ensure that it fails to compile on unsupported systems instead of always returning false:

#if defined(__FreeBSD__)
  unsigned long hwcap = elf_aux_info(AT_HWCAP, &hwcap, sizeof(unsigned long));
#else
  unsigned long hwcap = getauxval(AT_HWCAP);
#endif

Address comment.

dim@FreeBSD.org committed a in slightly different version in FreeBSD src tree. Should I use its version instead?

Thanks!

arichardson added a subscriber: dim.Sep 7 2021, 4:44 AM

Address comment.

dim@FreeBSD.org committed a in slightly different version in FreeBSD src tree. Should I use its version instead?

Thanks!

Yes that looks reasonable to me. CC: @dim

dim added a comment.Sep 7 2021, 10:46 AM

Address comment.

dim@FreeBSD.org committed a in slightly different version in FreeBSD src tree. Should I use its version instead?

Thanks!

Yes that looks reasonable to me. CC: @dim

I committed a change to FreeBSD in https://cgit.freebsd.org/src/commit/?id=efe67f33c322265eb303ec0ab40275100795b22a, which is almost identical. However, I also check the return value of elf_aux_info(), since (theoretically at least) it could fail. In that case, I'm assuming that HWCAP is also not working. :)

@MikaelUrankar any objections if I add that to this review?

Address comment.

dim@FreeBSD.org committed a in slightly different version in FreeBSD src tree. Should I use its version instead?

Thanks!

Yes that looks reasonable to me. CC: @dim

I committed a change to FreeBSD in https://cgit.freebsd.org/src/commit/?id=efe67f33c322265eb303ec0ab40275100795b22a, which is almost identical. However, I also check the return value of elf_aux_info(), since (theoretically at least) it could fail. In that case, I'm assuming that HWCAP is also not working. :)

@MikaelUrankar any objections if I add that to this review?

No objection from me, feel free to commandeer this review.
Thanks!

dim commandeered this revision.Sep 7 2021, 2:33 PM
dim added a reviewer: MikaelUrankar.
dim added reviewers: emaste, arichardson.
dim updated this revision to Diff 371193.Sep 7 2021, 2:34 PM

Use version committed into FreeBSD 14-CURRENT.

Herald added a project: Restricted Project. · View Herald TranscriptSep 7 2021, 2:34 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
This revision was not accepted when it landed; it landed in state Needs Review.Nov 20 2021, 3:13 AM
This revision was automatically updated to reflect the committed changes.