Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't directly include asm/hwcap.h; fix compilation on musl aarch64 #936

Merged
merged 2 commits into from
Apr 29, 2021

Conversation

joshtriplett
Copy link
Contributor

sys/auxv.h includes the appropriate headers to provide the HWCAP
constants, on both glibc and musl, which makes it unnecessary to include
asm/hwcap.h directly. And on musl, asm/hwcap.h doesn't exist.

sys/auxv.h includes the appropriate headers to provide the HWCAP
constants, on both glibc and musl, which makes it unnecessary to include
asm/hwcap.h directly. And on musl, asm/hwcap.h doesn't exist.
@codecov
Copy link

codecov bot commented Apr 24, 2021

Codecov Report

Merging #936 (31a9ecb) into develop (f03918f) will decrease coverage by 0.30%.
The diff coverage is n/a.

❗ Current head 31a9ecb differs from pull request most recent head 6e6fdb0. Consider uploading reports for the commit 6e6fdb0 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #936      +/-   ##
===========================================
- Coverage    77.89%   77.59%   -0.31%     
===========================================
  Files           74       74              
  Lines         8307     8301       -6     
  Branches      1369     1374       +5     
===========================================
- Hits          6471     6441      -30     
- Misses        1307     1331      +24     
  Partials       529      529              
Flag Coverage Δ
macos_clang 68.65% <ø> (ø)
macos_gcc 67.64% <ø> (ø)
ubuntu_clang 73.51% <ø> (-1.68%) ⬇️
ubuntu_clang_debug 73.81% <ø> (-1.62%) ⬇️
ubuntu_clang_inflate_allow_invalid_dist 73.24% <ø> (-1.68%) ⬇️
ubuntu_clang_inflate_strict 73.51% <ø> (-1.68%) ⬇️
ubuntu_clang_mmap 73.22% <ø> (-1.67%) ⬇️
ubuntu_clang_msan 73.51% <ø> (-1.68%) ⬇️
ubuntu_gcc 73.16% <ø> (-1.43%) ⬇️
ubuntu_gcc_aarch64 74.46% <ø> (+0.25%) ⬆️
ubuntu_gcc_aarch64_compat_no_opt 74.00% <ø> (+0.38%) ⬆️
ubuntu_gcc_aarch64_no_acle 74.28% <ø> (+0.36%) ⬆️
ubuntu_gcc_aarch64_no_neon 74.03% <ø> (+0.36%) ⬆️
ubuntu_gcc_armhf 72.41% <ø> (-2.49%) ⬇️
ubuntu_gcc_armhf_compat_no_opt 74.02% <ø> (+0.38%) ⬆️
ubuntu_gcc_armhf_no_acle 73.14% <ø> (-1.95%) ⬇️
ubuntu_gcc_armhf_no_neon 75.15% <ø> (-0.31%) ⬇️
ubuntu_gcc_armsf 72.38% <ø> (-2.53%) ⬇️
ubuntu_gcc_armsf_compat_no_opt 74.02% <ø> (+0.38%) ⬆️
ubuntu_gcc_compat_no_opt 75.10% <ø> (+0.26%) ⬆️
ubuntu_gcc_mingw_i686 0.00% <ø> (ø)
ubuntu_gcc_mingw_x86_64 0.00% <ø> (ø)
ubuntu_gcc_no_avx2 75.14% <ø> (+0.35%) ⬆️
ubuntu_gcc_no_pclmulqdq 71.61% <ø> (-1.35%) ⬇️
ubuntu_gcc_no_sse2 74.10% <ø> (+0.05%) ⬆️
ubuntu_gcc_no_sse4 71.58% <ø> (-1.36%) ⬇️
ubuntu_gcc_o3 73.05% <ø> (-1.45%) ⬇️
ubuntu_gcc_osb 75.99% <ø> (-1.31%) ⬇️
ubuntu_gcc_ppc 75.46% <ø> (+0.23%) ⬆️
ubuntu_gcc_ppc64 76.23% <ø> (+0.23%) ⬆️
ubuntu_gcc_ppc64le 74.98% <ø> (+0.26%) ⬆️
ubuntu_gcc_s390x 73.84% <ø> (+0.18%) ⬆️
ubuntu_gcc_sparc64 76.70% <ø> (+0.24%) ⬆️
win64_gcc 70.63% <ø> (ø)
win64_gcc_compat_no_opt 74.16% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
arch/arm/armfeature.c 100.00% <ø> (ø)
arch/arm/crc32_acle.c 0.00% <0.00%> (-61.30%) ⬇️
arch/arm/chunkset_neon.c 75.00% <0.00%> (-25.00%) ⬇️
chunkset_tpl.h 95.14% <0.00%> (-3.89%) ⬇️
functable.c 78.90% <0.00%> (-2.35%) ⬇️
deflate.h 57.14% <0.00%> (+7.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f03918f...6e6fdb0. Read the comment docs.

@mtl1979
Copy link
Collaborator

mtl1979 commented Apr 24, 2021

We explicitly include some redundant headers to trap differences between compilers. We don't officially support every combination there is (compiler + platform + C run-time library).

@joshtriplett
Copy link
Contributor Author

joshtriplett commented Apr 24, 2021

@mtl1979 In this case, this isn't a difference between compilers, it's a difference between musl and glibc; musl doesn't seem to support directly including the kernel headers here. It'd be helpful to have support for aarch64-linux-musl, for the purposes of building statically compiled binaries for aarch64.

I've tested that with this one change included, it's possible to compile zlib-ng for an aarch64-unknown-linux-musl target.

@mtl1979
Copy link
Collaborator

mtl1979 commented Apr 24, 2021

@joshtriplett I assumed musl and glibc are both C run-time libraries... GCC usually use glibc by default, Visual C++ use its own C libary, etc...

In my personal opinion, we should support combinations that enough people use... This excludes cases that are complex to include without causing possible conflicts, including duplicate names, or names that are used for two different purposes.

@Dead2
Copy link
Member

Dead2 commented Apr 24, 2021

As long as this does not trigger any regressions, I honestly don't see any problem with including the change. Supporting musl would be nice, even if it is not something we target or spend time on, especially if it is this simple.

@joshtriplett
Copy link
Contributor Author

Both glibc and musl seem to most commonly use gcc as their compiler (though both can be compiled with clang as well).

I completely agree that not all combinations are reasonable to support. I'm hoping that since aarch64-linux-musl works with just this one line changed, this would be OK to add.

@mtl1979
Copy link
Collaborator

mtl1979 commented Apr 24, 2021

@joshtriplett Changing header filename is usually easier to accept than removing one header... This is because we assume that breaking change in one specific header file is likely break build of other projects than zlib-ng too and backfire more likely.

Personally, I have worked quite a while with Linaro gcc team and Microsoft, so I have had to fix quite a lot of header related issues.

@joshtriplett
Copy link
Contributor Author

joshtriplett commented Apr 24, 2021

Can you clarify what problem you're concerned about with this change?

Would you prefer that I wrap this in an #ifndef so that it includes the header when not on musl?

@mtl1979
Copy link
Collaborator

mtl1979 commented Apr 25, 2021

@Dead2 It's not about triggering regression, it's about opening Pandora's box... Basically this is same as Microsoft moving some intrinsics to combined header and restricting their use to only AArch64, even though ARMv8 has supported them for both 32-bit and 64-bit... In some untested configurations, hard fail is better than unknown behavior.

@joshtriplett If we remove the header check for all C run-time library possibilities, we basically assert that we support all possible C run-time libraries even if they are not API compatible with glibc. I'm not sure if we should do the existence check on configure step or in just this source file. I'm inclined to accept both solutions, but it's just my opinion.

@joshtriplett
Copy link
Contributor Author

@mtl1979 Ah, I see.

Supporting just "glibc and musl" rather than "every possible libc" seems reasonable. I do think that'd be better done using cmake detection and compilation tests, rather than by including headers like this that exist in some implementations and not in others.

As far as I can tell, musl intentionally doesn't provide any musl-specific defines, so there's no way to detect musl in this context and only stop including the header in that case. Given that, would you consider it reasonable to drop this particular header include to fix musl?

@mtl1979
Copy link
Collaborator

mtl1979 commented Apr 25, 2021

@joshtriplett I think the best solution is to move the conformity test to CMakeLists.txt and configure as build test... Basically we only need to make sure the function itself and all the used defines are declared correctly. This allows us to also trap cases when someone tries to use too old version of C run-time library, for example on Android.

@joshtriplett
Copy link
Contributor Author

@mtl1979 When you say "all the used defines", do you mean the HWCAP_* and HWCAP2_* defines? As far as I can tell, both of the used defines are checked with defined(...) around the code that uses them, presumably to prevent detecting them on systems that don't define those hwcaps. Are you wanting to drop that code, and prevent compilation on platforms that don't have those defines available? Or am I not understanding what you're proposing?

@nmoinvaz
Copy link
Member

I think it is fine also as long as it doesn't cause regression.

@mtl1979
Copy link
Collaborator

mtl1979 commented Apr 25, 2021

@joshtriplett Failing as early as possible is the best... If I remember correctly ARM and AArch64 have slightly different names for the defines, so one has to check for the correct ones depending on if the target system is 32-bit or 64-bit.

@joshtriplett
Copy link
Contributor Author

I've added an additional commit that adds compile-time detection to make sure we have the necessary hwcap defines available to do runtime detection. That way, if there's a missing definition, the user will get a message from cmake when doing initial configuration, rather than a compile-time warning or silently missing detection at runtime.

I hope this addresses the concern; now, the code will compile with more C libraries, but if the C library doesn't provide the necessary definitions, the user will get a useful message from cmake.

@mtl1979
Copy link
Collaborator

mtl1979 commented Apr 25, 2021

@joshtriplett The second commit fixes it for cmake, but not when using configure...

@joshtriplett
Copy link
Contributor Author

Pending CI confirmation, hopefully the third commit will do the same for configure.

@joshtriplett
Copy link
Contributor Author

Looks like it passed CI. So, this should cover both configure and cmake, and provide better configuration-time detection of whether runtime detection will work.

@Dead2
Copy link
Member

Dead2 commented Apr 26, 2021

Looks pretty good to me, but I find the defines are a bit long and awkward ARM_HAVE_CRC32_IN_AUXV
What about simply ARM_AUXV_CRC32?

@mtl1979
Copy link
Collaborator

mtl1979 commented Apr 26, 2021

@Dead2 I agree that the defines could be as short as possible while still being descriptive... Should definitely follow the same pattern as existing ones.

It's also matter of debate if the commits should be squashed before merging.

@nmoinvaz
Copy link
Member

nmoinvaz commented Apr 26, 2021

Well for includes we have always started them with HAVE_* but for architecture features it always started with ARM_*.

@joshtriplett
Copy link
Contributor Author

I can certainly modify the names. I do think it makes sense to put the AUXV before the hwcap name, so that the names have the same prefix. Something like ARM_AUXV_HAS_CRC32 and ARM_AUXV_HAS_NEON, perhaps?

As for squashing, please feel free to squash-merge if you prefer, or if you'd like, I can rebase into 2 commits or 1 commit. Let me know what you'd prefer and I'd be happy to structure it accordingly.

This allows us to provide useful warning messages from cmake or
configure if the system headers don't provide the necessary flags to do
runtime detection.
@joshtriplett
Copy link
Contributor Author

I pushed a new version which combines the cmake and configure commits, and which renames the definitions.

@Dead2 Dead2 merged commit a7f2956 into zlib-ng:develop Apr 29, 2021
@joshtriplett joshtriplett deleted the musl-aarch64 branch April 29, 2021 21:16
Dead2 added a commit that referenced this pull request May 8, 2021
- Include porting guide in release packages #917
- Documentation improvements #913 #949
- Added Windows ARM binaries in release packages #916
- Fix crash on ARMv7 #927
- Fix building on FreeBSD #921
- Fix building with musl on aarch64 #936
- Fix ARM float-abi detection #918
- Fix cmake detection of risc-v architectures #942
- Minor buildsystem fixes #922 #924 #933 #938 #950
- Improve zlib-compat build #915 #944
- CI/Test improvements #926 #929 #925 #937 #939 #940
Dead2 added a commit that referenced this pull request May 8, 2021
- Include porting guide in release packages #917
- Documentation improvements #913 #949
- Added Windows ARM binaries in release packages #916
- Fix crash on ARMv7 #927
- Fix building on FreeBSD #921
- Fix building with musl on aarch64 #936
- Fix ARM float-abi detection #918
- Fix cmake detection of risc-v architectures #942
- Minor buildsystem fixes #922 #924 #933 #938 #950
- Improve zlib-compat build #915 #944
- CI/Test improvements #926 #929 #927 #937 #939 #940
@Dead2 Dead2 mentioned this pull request May 8, 2021
Dead2 added a commit that referenced this pull request May 8, 2021
- Include porting guide in release packages #917
- Documentation improvements #913 #949
- Added Windows ARM binaries in release packages #916
- Fix crash on ARMv7 #927
- Fix building on FreeBSD #921
- Fix building with musl on aarch64 #936
- Fix ARM float-abi detection #918
- Fix cmake detection of risc-v architectures #942
- Minor buildsystem fixes #922 #924 #933 #938 #950
- Improve zlib-compat build #915 #944
- CI/Test improvements #926 #929 #927 #937 #939 #940
Dead2 added a commit that referenced this pull request May 9, 2021
- Include porting guide in release packages #917
- Documentation improvements #913 #949
- Added Windows ARM binaries in release packages #916
- Fix crash on ARMv7 #927
- Fix building on FreeBSD #921
- Fix building with musl on aarch64 #936 #952
- Fix ARM float-abi detection #918
- Fix cmake detection of risc-v architectures #942
- Minor buildsystem fixes #922 #924 #933 #938 #950
- Improve zlib-compat build #915 #944
- CI/Test improvements #926 #929 #927 #937 #939 #940
Dead2 added a commit that referenced this pull request May 13, 2021
- Include porting guide in release packages #917
- Documentation improvements #913 #949
- Added Windows ARM binaries in release packages #916
- Fix crash on ARMv7 #927
- Fix building on FreeBSD #921
- Fix building with musl on aarch64 #936 #952
- Fix ARM float-abi detection #918
- Fix cmake detection of risc-v architectures #942
- Minor buildsystem fixes #922 #924 #933 #938 #950
- Improve zlib-compat build #915 #944
- CI/Test improvements #926 #929 #927 #937 #939 #940
gsjaardema pushed a commit to gsjaardema/zlib-ng that referenced this pull request May 13, 2021
- Include porting guide in release packages zlib-ng#917
- Documentation improvements zlib-ng#913 zlib-ng#949
- Added Windows ARM binaries in release packages zlib-ng#916
- Fix crash on ARMv7 zlib-ng#927
- Fix building on FreeBSD zlib-ng#921
- Fix building with musl on aarch64 zlib-ng#936 zlib-ng#952
- Fix ARM float-abi detection zlib-ng#918
- Fix cmake detection of risc-v architectures zlib-ng#942
- Minor buildsystem fixes zlib-ng#922 zlib-ng#924 zlib-ng#933 zlib-ng#938 zlib-ng#950
- Improve zlib-compat build zlib-ng#915 zlib-ng#944
- CI/Test improvements zlib-ng#926 zlib-ng#929 zlib-ng#927 zlib-ng#937 zlib-ng#939 zlib-ng#940
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants