Skip to content

Conversation

brad0
Copy link
Contributor

@brad0 brad0 commented Oct 1, 2025

Add support for AT_HWCAP3 / AT_HWCAP4 which is supported by glibc, musl,
Android and FreeBSD 15/-current.

Stop using sys/ifunc.h as libgcc has done. This is more portable as
older glibc will not have the hwcap3/4 fields.

@brad0 brad0 force-pushed the compiler_rt_hwcap branch 4 times, most recently from ea5fdd8 to 6e571ee Compare October 1, 2025 22:57
@brad0 brad0 requested review from enh-google and labrinea October 1, 2025 23:03
@@ -190,3 +190,19 @@
#ifndef HWCAP2_CSSC
#define HWCAP2_CSSC (1UL << 34)
#endif

#ifndef AT_HWCAP3
#if defined(__linux__) || defined(__ANDROID__)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't seem to care for non linux/android for other macros like AT_HWCAP and AT_HWCAP2 above. I couldn't find the values 38 and 39 for AT_HWCAP3/AT_HWCAP4 can you shed some light?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't seem to care for non linux/android for other macros like AT_HWCAP and AT_HWCAP2 above.

AT_HWCAP and AT_HWCAP2 are so old that i assume we don't support compiling with a libc that doesn't have them. 3 and 4 require relatively new libcs though.

(it might be worth saying that in a code comment, so a future reader knows they can remove this in 2028 or whenever.)

also: linux is true for ANDROID, so there's no need to explicitly mention ANDROID here.

I couldn't find the values 38 and 39 for AT_HWCAP3/AT_HWCAP4 can you shed some light?

yeah, i'm confused by that... probably worth explicitly saying (in code or #if) if this is for FreeBSD or whatever.

Copy link
Contributor Author

@brad0 brad0 Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't seem to care for non linux/android for other macros like AT_HWCAP and AT_HWCAP2 above. I couldn't find the values 38 and 39 for AT_HWCAP3/AT_HWCAP4 can you shed some light?

Only because *BSD's include sys/auxv.h where as for Linux that does not appear to be the case. AT_HWCAP / AT_HWCAP2 are guaranteed to be defined for the *BSD's if the functionality (elf_aux_info) is there, not so for 3 and 4. Those values are for *BSD's.

Copy link
Contributor Author

@brad0 brad0 Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AT_HWCAP and AT_HWCAP2 are so old that i assume we don't support compiling with a libc that doesn't have them.

getauxval() was added in glibc 2.16. AArch64 support was added in glibc 2.17. AT_HWCAP2 was added in glibc 2.18.

There is some room for simplifying some of this stuff since the expectation is that any system that is on AArch64 has some of these bits included unlike with 32-bit ARM if you go back far enough.

@brad0 brad0 force-pushed the compiler_rt_hwcap branch 2 times, most recently from a995ba2 to ec44d70 Compare October 2, 2025 23:37
@@ -12,10 +12,14 @@ void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {

unsigned long hwcap = getauxval(AT_HWCAP);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit: at this point, you don't need the locals and could just assign straight into the struct. not a regression though.)

@@ -190,3 +190,20 @@
#ifndef HWCAP2_CSSC
#define HWCAP2_CSSC (1UL << 34)
#endif

// Linux and BSD values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: having // Linux and // BSD on each of the four lines might be clearer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i realize there's no single "bsd" define we can use, otherwise i'd have suggested that and a #error instead.

actually, looking at my local checkouts ... it seems like these are only in FreeBSD atm anyway?

Add support for AT_HWCAP3 / AT_HWCAP4 which is supported by glibc, musl,
Android and FreeBSD 15/-current.

Stop using sys/ifunc.h as libgcc has done. This is more portable as
older glibc will not have the hwcap3/4 fields.
@brad0 brad0 force-pushed the compiler_rt_hwcap branch from ec44d70 to 6d0f0a4 Compare October 4, 2025 10:26
@brad0 brad0 requested review from enh-google and labrinea October 4, 2025 11:47
@brad0 brad0 merged commit edb4319 into llvm:main Oct 7, 2025
9 checks passed
@brad0 brad0 deleted the compiler_rt_hwcap branch October 7, 2025 20:51
@ilovepi
Copy link
Contributor

ilovepi commented Oct 7, 2025

We're seeing some build failures after this patch. It seems you're assuming there is some minium libc version you can assume, but AFAIK there is no such minimum stated in LLVM. I think libcxx has some minimum, but that's very much separate from compiler-rt and the builtins. I think this should probably be reverted until there's some community agreement about updating (in this case specifying at all) what's required.

[273/417](25) Building C object CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o
FAILED: CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o 
/Users/swarming/b/s/w/ir/x/w/llvm_build/./bin/clang --target=aarch64-unknown-linux-gnu --sysroot=/Users/swarming/b/s/w/ir/x/w/cipd/linux -DHAS_ASM_LSE -DVISIBILITY_HIDDEN -D_LIBATOMIC_USE_PTHREAD -I/Users/swarming/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/../../../third-party/siphash/include --target=aarch64-unknown-linux-gnu -O2 -g -DNDEBUG -std=gnu11 -fno-lto -nostdinc++ -fPIC -fno-builtin -fvisibility=hidden -fomit-frame-pointer -DCOMPILER_RT_HAS_FLOAT16 -MD -MT CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o -MF CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o.d -o CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o -c /Users/swarming/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c
In file included from /Users/swarming/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c:79:
/Users/swarming/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/getauxval.inc:19:35: error: use of undeclared identifier 'hwcap'
   19 |   __init_cpu_features_constructor(hwcap | _IFUNC_ARG_HWCAP, &arg);
      |                                   ^~~~~
1 error generated.

Bot: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-mac-arm64/b8701635553374622177/overview

Logs: https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8701635553374622177/+/u/clang/build/stdout

arg._hwcap2 = getauxval(AT_HWCAP2);
arg._hwcap3 = getauxval(AT_HWCAP3);
arg._hwcap4 = getauxval(AT_HWCAP4);
__init_cpu_features_constructor(hwcap | _IFUNC_ARG_HWCAP, &arg);
Copy link
Member

@petrhosek petrhosek Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is still referencing hwcap but the variable is no longer defined anywhere.

@ilovepi
Copy link
Contributor

ilovepi commented Oct 7, 2025

We're seeing some build failures after this patch. It seems you're assuming there is some minium libc version you can assume, but AFAIK there is no such minimum stated in LLVM. I think libcxx has some minimum, but that's very much separate from compiler-rt and the builtins. I think this should probably be reverted until there's some community agreement about updating (in this case specifying at all) what's required.

[273/417](25) Building C object CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o
FAILED: CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o 
/Users/swarming/b/s/w/ir/x/w/llvm_build/./bin/clang --target=aarch64-unknown-linux-gnu --sysroot=/Users/swarming/b/s/w/ir/x/w/cipd/linux -DHAS_ASM_LSE -DVISIBILITY_HIDDEN -D_LIBATOMIC_USE_PTHREAD -I/Users/swarming/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/../../../third-party/siphash/include --target=aarch64-unknown-linux-gnu -O2 -g -DNDEBUG -std=gnu11 -fno-lto -nostdinc++ -fPIC -fno-builtin -fvisibility=hidden -fomit-frame-pointer -DCOMPILER_RT_HAS_FLOAT16 -MD -MT CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o -MF CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o.d -o CMakeFiles/clang_rt.builtins-aarch64.dir/cpu_model/aarch64.c.o -c /Users/swarming/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c
In file included from /Users/swarming/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c:79:
/Users/swarming/b/s/w/ir/x/w/llvm-llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/getauxval.inc:19:35: error: use of undeclared identifier 'hwcap'
   19 |   __init_cpu_features_constructor(hwcap | _IFUNC_ARG_HWCAP, &arg);
      |                                   ^~~~~
1 error generated.

Bot: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-mac-arm64/b8701635553374622177/overview

Logs: https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8701635553374622177/+/u/clang/build/stdout

Actually, maybe the error is just that there's still references left? In any case, I'd appreciate it if you could take a look.

@brad0
Copy link
Contributor Author

brad0 commented Oct 7, 2025

Yes, I have a diff to revert the part that broke the build.

https://github.com/llvm/llvm-project/pull/162383/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants