abseil / abseil-cpp

Abseil Common Libraries (C++)
https://abseil.io
Apache License 2.0
14.27k stars 2.51k forks source link

Build by aarch64 failed. #1241

Open wanguxiang1218 opened 1 year ago

wanguxiang1218 commented 1 year ago

I cannot build abseil by aarch64 for arm53.

1.download new release tag. 2.build it by cmake. mkdir build cd build /home/tools/cmake-3.19.6-Linux-x86_64/bin/cmake -D CMAKE_C_COMPILER=/usr/bin/aarch64-linux-gnu-gcc -D CMAKE_CXX_COMPILER=/usr/bin/aarch64-linux-gnu-g++ ..

build error!!

aarch64-linux-gnu-g++: error: unrecognized command line option ‘-maes’ aarch64-linux-gnu-g++: error: unrecognized command line option ‘-msse4.1’ make[2]: [absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/build.make:82: absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o] Error 1 make[1]: [CMakeFiles/Makefile2:2730: absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/all] Error 2 make: *** [Makefile:160: all] Error 2

How can i build for arm53? Thanks!

ilanbiala commented 1 year ago

I'm also seeing this behavior when building through Bazel (v4.2.2), which seems to indicate that https://github.com/abseil/abseil-cpp/blob/master/absl/copts/configure_copts.bzl#L45-L57 or something in the platform-specific flags selection path is failing?

This seems related to or possibly the same bug as https://github.com/abseil/abseil-cpp/issues/1227 and https://github.com/abseil/abseil-cpp/issues/1210 maybe?

anpol commented 1 year ago

Changing CMAKE_C_COMPILER variable shouldn't affect build, as Abseil is a C++ only library.

Changing CMAKE_CXX_COMPILER variable doesn't change other CMake variables, so it's not the same as changing a toolchain.

E.g. AbseilConfigureCopts.cmake relies on variables like CMAKE_SYSTEM_PROCESSOR and CMAKE_CXX_COMPILER_ID. You can print their values by editing that file:

message("CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
message("CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}")

See CMake documentation on cross-compiling.

If you do not cross-compile, you should set CC and CXX environment variables before running CMake.

barracuda156 commented 1 year ago

It does look that there is something wrong with how abseil build system is set up. Fixing it on upstream side gonna fix it for everyone, otherwise such tickets will keep arising (even though this can be solved on a user end by manual changes).

thx123 commented 6 months ago

This basically means that the abseil-cpp module cannot compile on any AARCH64 processor based systems. I am surprised that this bug hasn't been fixed after more than a year.

The simplest solution seems to be just remove those X86_64 specific flags to unbreak AARCH64 processor support, like in this patch. Can this fix be provided? I'd appreciate Abseil team's timely response.

Vangof commented 5 months ago

abseil-cpp-20230802.1 has the same problem

cmake -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ .. make -j8

output: [ 14%] Building CXX object absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o aarch64-linux-gnu-g++: error: unrecognized command line option '-maes' aarch64-linux-gnu-g++: error: unrecognized command line option '-msse4.1' absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/build.make:81: recipe for target 'absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o' failed make[2]: [absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o] Error 1 CMakeFiles/Makefile2:3683: recipe for target 'absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/all' failed make[1]: [absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... [ 14%] Building CXX object absl/time/CMakeFiles/time_zone.dir/internal/cctz/src/time_zone_lookup.cc.o

Is there any solution?

Hackerl commented 1 month ago

This library has been able to compile on macos m1 before, because llvm-17 ignores the '-msse4.1' option. Once llvm is upgraded to 18, it will no longer compile on any macos m1.

17169755747947

alexkaratarakis commented 1 month ago

It is not specific to macos, happens on other host platforms like linux. clang-18 rejects -maes and -msse4.1 as invalid for the target platform, which was not the case for clang-17.

The patch provided by @thx123 is a valid workaround for the issue.

The intended behavior seems to be to select one of the other options:

    "ABSL_RANDOM_HWAES_ARM64_FLAGS": ["-march=armv8-a+crypto"],
    "ABSL_RANDOM_HWAES_ARM32_FLAGS": ["-mfpu=neon"],
    "ABSL_RANDOM_HWAES_X64_FLAGS": [
        "-maes",
        "-msse4.1",
    ],
    "ABSL_RANDOM_HWAES_MSVC_X64_FLAGS": [],

(from link)

derekmauro commented 1 month ago

For those of you who are having this problem with CMake, are you setting CMAKE_SYSTEM_PROCESSOR correctly?

No one has provided Bazel reproduction instructions, but I would guess that the problem is similar. Does your build set the target CPU correctly?

emezeske commented 1 month ago

My CMAKE_SYSTEM_PROCESSOR is set to arm64 and I get:

absl_random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o.ddi [build] warning: argument unused during compilation: '-Xarch_x86_64 -maes' [build] error: unsupported option '-msse4.1' for target 'arm64-apple-darwin23.5.0' [build] Error while scanning dependencies for /Users/emezeske/Developer/anukari/lib/abseil/absl/random/internal/randen_hwaes.cc: [build] error: unsupported option '-msse4.1' for target 'arm64-apple-darwin23.5.0

emezeske commented 1 month ago

I looked at AbseilConfigureCopts.cmake and it seems pretty obvious that CMAKE_SYSTEM_PROCESSOR is explicitly ignored. There's a huge comment on line 14 explaining this.

Look at the last part of the comment:

In both cases, the viable strategy is to pass all arguments at once, allowing the compiler to dispatch arch-specific arguments to a designated backend.

Given that a prior comment on this issue thread mentioned that clang 18 changed to make invalid options errors instead of warnings, it seems that the "pass all arguments at once" approach is no longer valid and breaks all users of clang 18+ on APPLE.

emezeske commented 1 month ago

If I disable that branch "if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES [[Clang]])" and force it to fall through to the branches below, on my mac it works perfectly and abseil compiles.