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

Build on 10.6.8 Rosetta uses ABSL_RANDOM_HWAES_X64_FLAGS despite OSX_ARCHITECTURES = ppc #1227

Open
barracuda156 opened this issue Jul 22, 2022 · 5 comments
Labels

Comments

@barracuda156
Copy link

barracuda156 commented Jul 22, 2022

Describe the bug

I am building abseil on 10.6.8 Rosetta for ppc (well, in fact I has built it, but with an ugly solution of just editing away Intel flags). Despite Cmake correctly recognizing OSX_ARCHITECTURES="ppc", it still pulls out Intel HWAES flags, which obviously cause a failure.
I tried specifying CMAKE_SYSTEM_PROCESSOR=ppc and tried a couple of patches to the source code, but nothing helped.
Removing away flags in question from abseil-abseil-cpp-273292d/absl/copts/GENERATED_AbseilCopts.cmake solved the issue, at least on the surface, but it is clearly a bad solution.

What is required is to ensure ppc is used all through, with no x86 setting pulled over.

This chunk of code causes the problem:

list(APPEND ABSL_RANDOM_HWAES_X64_FLAGS
    "-maes"
    "-msse4.1"
)

What version of Abseil are you using?

10:~ svacchanda$ port -v installed abseil
The following ports are currently installed:
  abseil @20220623.0_0 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-07-22T21:38:20+0400'

What operating system and version are you using

10.6.8 Rosetta (build for ppc32), Xcode 3.2.6

What compiler and version are you using?

10:~ svacchanda$ /opt/local/bin/gcc-mp-12 -v
Using built-in specs.
COLLECT_GCC=/opt/local/bin/gcc-mp-12
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/ppc-apple-darwin10/12.1.0/lto-wrapper
Target: ppc-apple-darwin10
Configured with: /opt/local/var/macports/build/_opt_PPCRosettaPorts_lang_gcc12/gcc12/work/gcc-12.1.0/configure --prefix=/opt/local --build=ppc-apple-darwin10 --enable-languages=c,c++,objc,obj-c++,lto,fortran,jit --libdir=/opt/local/lib/gcc12 --includedir=/opt/local/include/gcc12 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-12 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-12 --with-gxx-include-dir=/opt/local/include/gcc12/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local --with-zstd=/opt/local --enable-checking=release --disable-multilib --enable-lto --enable-libstdcxx-time --without-build-config --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --enable-host-shared --with-darwin-extra-rpath=/opt/local/lib/libgcc --with-libiconv-prefix=/opt/local --with-tune-cpu=G4 --disable-tls --with-pkgversion='MacPorts gcc12 12.1.0_3'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.1.0 (MacPorts gcc12 12.1.0_3)

What build system are you using?

I use Macports and cmake-devel 3.24.0-rc4.

@barracuda156
Copy link
Author

[ 12%] Building CXX object absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o
cd /opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/build/absl/random && /opt/local/bin/g++-mp-12 -Drandom_internal_randen_hwaes_impl_EXPORTS -I/opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/abseil-cpp-20220623.0 -pipe -Os -DNDEBUG -I/opt/local/include -D_GLIBCXX_USE_CXX11_ABI=0 -arch ppc -mmacosx-version-min=10.6 -fPIC -Wall -Wextra -Wcast-qual -Wconversion-null -Wformat-security -Wmissing-declarations -Woverlength-strings -Wpointer-arith -Wundef -Wunused-local-typedefs -Wunused-result -Wvarargs -Wvla -Wwrite-strings -DNOMINMAX -maes -msse4.1 -std=gnu++14 -MD -MT absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o -MF CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o.d -o CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o -c /opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/abseil-cpp-20220623.0/absl/random/internal/randen_hwaes.cc
g++-mp-12: error: unrecognized command-line option '-maes'
g++-mp-12: error: unrecognized command-line option '-msse4.1'
make[2]: *** [absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o] Error 1
make[2]: Leaving directory `/opt/local/var/macports/build/_opt_PPCRosettaPorts_devel_abseil/abseil/work/build'
make[1]: *** [absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/all] Error 2

@anpol
Copy link
Contributor

anpol commented Sep 5, 2022

Relying on CMAKE_OSX_ARCHITECTURES would be incorrect, the value of this variable is a list of architectures, not a single architecture.

To compile with CMake, you might need add support for your processor, e.g.:

diff --git a/absl/copts/AbseilConfigureCopts.cmake b/absl/copts/AbseilConfigureCopts.cmake
index 73435e99..beff32cf 100644
--- a/absl/copts/AbseilConfigureCopts.cmake
+++ b/absl/copts/AbseilConfigureCopts.cmake
@@ -66,6 +66,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*|aarch64")
   else()
     message(WARNING "Value of CMAKE_SIZEOF_VOID_P (${CMAKE_SIZEOF_VOID_P}) is not supported.")
   endif()
+elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc|ppc64")
+  set(ABSL_RANDOM_RANDEN_COPTS "${ABSL_RANDOM_HWAES_PPC_FLAGS}")
 else()
   message(WARNING "Value of CMAKE_SYSTEM_PROCESSOR (${CMAKE_SYSTEM_PROCESSOR}) is unknown and cannot be used to set ABSL_RANDOM_RANDEN_COPTS")
   set(ABSL_RANDOM_RANDEN_COPTS "")

Then set CMAKE_SYSTEM_PROCESSOR=ppc on CMake command line.

@barracuda156
Copy link
Author

barracuda156 commented Sep 5, 2022

Then set CMAKE_SYSTEM_PROCESSOR=ppc on CMake command line.

@anpol This is exactly what I tried, and it does not work. Cmake somehow forces cpu_arch instead, and applies Intel AES flags.

I tried now changing my patch from elseif(CMAKE_OSX_ARCHITECTURES MATCHES "ppc|ppc64") to elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc|ppc64"), and that fails.
Here is how it configures:

--->  Configuring abseil
Executing:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_abseil/abseil/work/build" && /opt/local/bin/cmake -G "CodeBlocks - Unix Makefiles" -DCMAKE_BUILD_TYPE=MacPorts -DCMAKE_INSTALL_PREFIX="/opt/local" -DCMAKE_INSTALL_NAME_DIR="/opt/local/lib" -DCMAKE_SYSTEM_PREFIX_PATH="/opt/local;/usr" -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" -DCMAKE_OBJC_COMPILER="$CC" -DCMAKE_OBJCXX_COMPILER="$CXX" -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_POLICY_DEFAULT_CMP0060=NEW -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_COLOR_MAKEFILE=ON -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_MAKE_PROGRAM=/usr/bin/make -DCMAKE_MODULE_PATH="/opt/local/share/cmake/Modules" -DCMAKE_PREFIX_PATH="/opt/local/share/cmake/Modules" -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON -DCMAKE_INSTALL_RPATH="/opt/local/lib" -Wno-dev -DCMAKE_SYSTEM_PROCESSOR="ppc" -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_STANDARD=14 -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_OSX_ARCHITECTURES="ppc" -DCMAKE_OSX_DEPLOYMENT_TARGET="10.6" -DCMAKE_OSX_SYSROOT="/" /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_abseil/abseil/work/abseil-cpp-20220623.1 
-- The CXX compiler identification is GNU 12.2.0

Looks good. And then it fails:

[ 14%] Building CXX object absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o
cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_abseil/abseil/work/build/absl/random && /opt/local/bin/g++-mp-12 -Drandom_internal_randen_hwaes_impl_EXPORTS -I/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_abseil/abseil/work/abseil-cpp-20220623.1 -pipe -Os -DNDEBUG -isystem/opt/local/include/LegacySupport -I/opt/local/include -D_GLIBCXX_USE_CXX11_ABI=0 -arch ppc -mmacosx-version-min=10.6 -fPIC -Wall -Wextra -Wcast-qual -Wconversion-null -Wformat-security -Wmissing-declarations -Woverlength-strings -Wpointer-arith -Wundef -Wunused-local-typedefs -Wunused-result -Wvarargs -Wvla -Wwrite-strings -DNOMINMAX -maes -msse4.1 -std=gnu++14 -MD -MT absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o -MF CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o.d -o CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o -c /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_devel_abseil/abseil/work/abseil-cpp-20220623.1/absl/random/internal/randen_hwaes.cc
g++-mp-12: error: unrecognized command-line option '-maes'
g++-mp-12: error: unrecognized command-line option '-msse4.1'
make[2]: *** [absl/random/CMakeFiles/random_internal_randen_hwaes_impl.dir/internal/randen_hwaes.cc.o] Error 1

The only way that I found to be working is this: #1272 (the patch quoted there, not PR commits).

@anpol
Copy link
Contributor

anpol commented Sep 7, 2022

Looks like you can't set CMAKE_SYSTEM_PROCESSOR on a CMake command line, because it gets overwritten by CMake when it identifies a host toolchain.

You might need to ask CMake community about setting that variable properly. Probably you need to create a toolchain file. Their docs says that you have to set CMAKE_SYSTEM_NAME to trigger cross-compiling.

@barracuda156
Copy link
Author

barracuda156 commented Sep 8, 2022

@anpol Thank you. Well, I have solved the problem for myself via changing to CMAKE_OSX_ARCHITECTURES (in CMakeLists), but if I find a better solution that can be general, I open a separate PR.

P. S. Often passing -DCMAKE_SYSTEM_PROCESSOR= via configure works fine. This is likely an issue of how the build system is set up here, not with Cmake as such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants