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

Unable to detect compiler error on armv7 build #2189

Closed
andrewdavidmackenzie opened this issue Dec 18, 2024 · 11 comments
Closed

Unable to detect compiler error on armv7 build #2189

andrewdavidmackenzie opened this issue Dec 18, 2024 · 11 comments

Comments

@andrewdavidmackenzie
Copy link

When trying to build ring on my mac, for armv7, with armv gcc tools installed I get this error:

andrew@amackenz-mac ring % cargo build --target=armv7-unknown-linux-gnueabihf                                                                                 
   Compiling ring v0.17.8 (/Users/andrew/workspace/ring)
The following warnings were emitted during compilation:

warning: [email protected]: Compiler family detection failed due to error: ToolExecError: Command "arm-linux-gnueabihf-gcc" "-E" "/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/18273820895658169040detect_compiler_family.c" with args arm-linux-gnueabihf-gcc did not execute successfully (status code exit status: 1).
warning: [email protected]: Compiler family detection failed due to error: ToolExecError: Command "arm-linux-gnueabihf-gcc" "-E" "/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/6396566474068574259detect_compiler_family.c" with args arm-linux-gnueabihf-gcc did not execute successfully (status code exit status: 1).
warning: [email protected]: arm-linux-gnueabihf-gcc: error trying to exec 'cc1': execvp: No such file or directory

error: failed to run custom build command for `ring v0.17.8 (/Users/andrew/workspace/ring)`

Caused by:
  process didn't exit successfully: `/Users/andrew/workspace/ring/target/debug/build/ring-45d5ab41c1bb1a0a/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=CARGO_MANIFEST_DIR
  cargo:rerun-if-env-changed=CARGO_PKG_NAME
  cargo:rerun-if-env-changed=CARGO_PKG_VERSION_MAJOR
  cargo:rerun-if-env-changed=CARGO_PKG_VERSION_MINOR
  cargo:rerun-if-env-changed=CARGO_PKG_VERSION_PATCH
  cargo:rerun-if-env-changed=CARGO_PKG_VERSION_PRE
  cargo:rerun-if-env-changed=CARGO_MANIFEST_LINKS
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rerun-if-env-changed=OUT_DIR
  cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH
  cargo:rerun-if-env-changed=CARGO_CFG_TARGET_OS
  cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ENV
  cargo:rerun-if-env-changed=DEBUG
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  OPT_LEVEL = Some(0)
  OUT_DIR = Some(/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out)
  TARGET = Some(armv7-unknown-linux-gnueabihf)
  HOST = Some(aarch64-apple-darwin)
  cargo:rerun-if-env-changed=CC_armv7-unknown-linux-gnueabihf
  CC_armv7-unknown-linux-gnueabihf = None
  cargo:rerun-if-env-changed=CC_armv7_unknown_linux_gnueabihf
  CC_armv7_unknown_linux_gnueabihf = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  RUSTC_LINKER = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:warning=Compiler family detection failed due to error: ToolExecError: Command "arm-linux-gnueabihf-gcc" "-E" "/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/18273820895658169040detect_compiler_family.c" with args arm-linux-gnueabihf-gcc did not execute successfully (status code exit status: 1).
  RUSTC_WRAPPER = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some(true)
  CARGO_CFG_TARGET_FEATURE = None
  cargo:rerun-if-env-changed=CFLAGS_armv7-unknown-linux-gnueabihf
  CFLAGS_armv7-unknown-linux-gnueabihf = None
  cargo:rerun-if-env-changed=CFLAGS_armv7_unknown_linux_gnueabihf
  CFLAGS_armv7_unknown_linux_gnueabihf = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  CARGO_ENCODED_RUSTFLAGS = Some()
  cargo:warning=Compiler family detection failed due to error: ToolExecError: Command "arm-linux-gnueabihf-gcc" "-E" "/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/6396566474068574259detect_compiler_family.c" with args arm-linux-gnueabihf-gcc did not execute successfully (status code exit status: 1).
  cargo:warning=arm-linux-gnueabihf-gcc: error trying to exec 'cc1': execvp: No such file or directory

  --- stderr
  running "perl" "//Users/andrew/workspace/ring/crypto/fipsmodule/aes/asm/bsaes-armv7.pl" "linux32" "//Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/bsaes-armv7-linux32.S"
  running "perl" "//Users/andrew/workspace/ring/crypto/fipsmodule/aes/asm/vpaes-armv7.pl" "linux32" "//Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/vpaes-armv7-linux32.S"
  running "perl" "//Users/andrew/workspace/ring/crypto/fipsmodule/bn/asm/armv4-mont.pl" "linux32" "//Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/armv4-mont-linux32.S"
  running "perl" "//Users/andrew/workspace/ring/crypto/chacha/asm/chacha-armv4.pl" "linux32" "//Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/chacha-armv4-linux32.S"
  running "perl" "//Users/andrew/workspace/ring/crypto/fipsmodule/modes/asm/ghash-armv4.pl" "linux32" "//Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/ghash-armv4-linux32.S"
  running "perl" "//Users/andrew/workspace/ring/crypto/fipsmodule/sha/asm/sha256-armv4.pl" "linux32" "//Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/sha256-armv4-linux32.S"
  running "perl" "//Users/andrew/workspace/ring/crypto/fipsmodule/sha/asm/sha512-armv4.pl" "linux32" "//Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/sha512-armv4-linux32.S"


  error occurred in cc-rs: Command LC_ALL="C" "arm-linux-gnueabihf-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-march=armv7-a" "-mfpu=vfpv3-d16" "-mfloat-abi=hard" "-I" "/Users/andrew/workspace/ring/include" "-I" "/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-g3" "-Werror" "-o" "/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/25ac62e5b3c53843-curve25519.o" "-c" "/Users/andrew/workspace/ring/crypto/curve25519/curve25519.c" with args arm-linux-gnueabihf-gcc did not execute successfully (status code exit status: 1).

There seems to kind of be two separate possible causes when I dig in a bit:

  • Command "arm-linux-gnueabihf-gcc" "-E" "/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/6396566474068574259detect_compiler_family.c" with args arm-linux-gnueabihf-gcc did not execute successfully
  • error trying to exec 'cc1': execvp: No such file or directory

Investigating the armv7 tools I have installed:

andrew@amackenz-mac ring % which arm-linux-gnueabihf-gcc
/usr/local/bin/arm-linux-gnueabihf-gcc

So it's installed.

andrew@amackenz-mac ring % file /usr/local/bin/arm-linux-gnueabihf-gcc
/usr/local/bin/arm-linux-gnueabihf-gcc: Mach-O 64-bit executable x86_64

It's a x86_64 binary on my Apple Silicon Mac.
I haven't been able to force homebrew to install arm64 version of those tools yet.

But it seems to run just fine (rosetta...):

andrew@amackenz-mac ring % /usr/local/bin/arm-linux-gnueabihf-gcc --version
arm-linux-gnueabihf-gcc (crosstool-NG 1.24.0) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The file that it is trying to compile doesn't exist (I think even generated files should remain after a build fail?):

andrew@amackenz-mac ring % more /Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/6396566474068574259detect_compiler_family.c
/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/6396566474068574259detect_compiler_family.c: No such file or directory
andrew@amackenz-mac ring % 

I'm not sure about the " error trying to exec 'cc1': execvp: No such file or directory" error, if it's for real and how I can investigate it more.

Any ideas?

@briansmith
Copy link
Owner

I thin the "detect_compiler_family.c" stuff is cc-rs intentionally causing a compilation failure so it can read the compiler's name from the error output. Even successful builds' logs are littered with that, unfortunately.

@NobodyXu
Copy link
Contributor

I thin the "detect_compiler_family.c" stuff is cc-rs intentionally causing a compilation failure so it can read the compiler's name from the error outpuEven successful builds' logs are littered with that, unfortunately.

It shouldn't fail though, we only run the pre-process stage to expand the macro and then check for keywords.

warning: [email protected]: arm-linux-gnueabihf-gcc: error trying to exec 'cc1': execvp: No such file or directory

I think there's some issues with your gcc installation on macOS?

@andrewdavidmackenzie
Copy link
Author

How can I check?
Any way to get expanded error messages or something?

It seems to run OK when I invoke manually.
Possibly be related to being an x86 binary running under rosetta on apple silicon?

@NobodyXu
Copy link
Contributor

Probably can try manually running the command, the c file can be found in cc-rs

@andrewdavidmackenzie
Copy link
Author

You mean, manually execute this:

error occurred in cc-rs: Command LC_ALL="C" "arm-linux-gnueabihf-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-march=armv7-a" "-mfpu=vfpv3-d16" "-mfloat-abi=hard" "-I" "/Users/andrew/workspace/ring/include" "-I" "/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-g3" "-Werror" "-o" "/Users/andrew/workspace/ring/target/armv7-unknown-linux-gnueabihf/debug/build/ring-5da4533007b2d19d/out/25ac62e5b3c53843-curve25519.o" "-c" "/Users/andrew/workspace/ring/crypto/curve25519/curve25519.c" with args arm-linux-gnueabihf-gcc did not execute successfully (status code exit status: 1).

right?

I imagine it's this method: detect_family_inner() that does this, and that this:

            let mut tmp =
                NamedTempfile::new(&out_dir, "detect_compiler_family.c").map_err(|err| Error {
                    kind: ErrorKind::IOError,
                    message: format!(
                        "failed to create detect_compiler_family.c temp file in '{}': {}",
                        out_dir.display(),
                        err
                    )
                    .into(),
                })?;

creates the file and writes the contents into it

@andrewdavidmackenzie
Copy link
Author

In cc-rs root dir:

LC_ALL="C" arm-linux-gnueabihf-gcc -O0 -ffunction-sections -fdata-sections -fPIC -gdwarf-4 -fno-omit-frame-pointer -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard -Wall -Wextra -fvisibility=hidden -std=c1x -Wall -Wbad-function-cast -Wcast-align -Wcast-qual -Wconversion -Wmissing-field-initializers -Wmissing-include-dirs -Wnested-externs -Wredundant-decls -Wshadow -Wsign-compare -Wsign-conversion -Wstrict-prototypes -Wundef -Wuninitialized -g3 -Werror -c src/detect_compiler_family.c
arm-linux-gnueabihf-gcc: error trying to exec 'cc1': execvp: No such file or directory

So, not sure how to figure out what's wrong with that arm-linux-gnueabihf-gcc installation :-(

@NobodyXu
Copy link
Contributor

you just need to run

arm-linux-gnueabihf-gcc -E src/detect_compiler_family.c

we run the compiler with -E only

@andrewdavidmackenzie
Copy link
Author

arm-linux-gnueabihf-gcc -E src/detect_compiler_family.c
arm-linux-gnueabihf-gcc: error trying to exec 'cc1': execvp: No such file or directory

Same result.

@NobodyXu
Copy link
Contributor

you can try https://stackoverflow.com/questions/31045575/how-to-trace-system-calls-of-a-program-in-mac-os-x to trace the syscalls like strace on linux and find out which process is spawned

@andrewdavidmackenzie
Copy link
Author

These are all the "cc1"s I can find on my mac:

find / -type f -name "cc1" 2>&1 |grep -v Permission                  
/usr/local/opt/libexec/gcc/i386-elf/4.9.2/cc1
/usr/local/opt/libexec/gcc/x86_64-apple-darwin15.2.0/4.9.3/cc1
/usr/local/opt/libexec/gcc/i686-apple-darwin11/4.2.1/cc1
/usr/local/opt/libexec/gcc/x86_64-apple-darwin16.3.0/6.3.0/cc1
/System/Volumes/Data/usr/local/opt/libexec/gcc/i386-elf/4.9.2/cc1
/System/Volumes/Data/usr/local/opt/libexec/gcc/x86_64-apple-darwin15.2.0/4.9.3/cc1
/System/Volumes/Data/usr/local/opt/libexec/gcc/i686-apple-darwin11/4.2.1/cc1
/System/Volumes/Data/usr/local/opt/libexec/gcc/x86_64-apple-darwin16.3.0/6.3.0/cc1
/System/Volumes/Data/Users/andrew/workspace/arm-linux-musleabihf-cross/libexec/gcc/arm-linux-musleabihf/9.3.0/cc1
/System/Volumes/Data/Users/andrew/.redoxer/toolchain/libexec/gcc/x86_64-unknown-redox/8.2.0/cc1
/System/Volumes/Data/opt/homebrew/Cellar/aarch64-elf-gcc/14.2.0/libexec/gcc/aarch64-elf/14.2.0/cc1
/System/Volumes/Data/opt/homebrew/Cellar/gcc/14.2.0_1/libexec/gcc/aarch64-apple-darwin24/14/cc1
/System/Volumes/Data/opt/homebrew/Cellar/arm-none-eabi-gcc/14.2.0/libexec/gcc/arm-none-eabi/14.2.0/cc1
/Users/andrew/workspace/arm-linux-musleabihf-cross/libexec/gcc/arm-linux-musleabihf/9.3.0/cc1

arm-linux-gnueabihf-gcc binary is installed in usr/local/bin and /System/Volumes/Data/usr/local/bin/arm-linux-gnueabihf-gcc - so I guess I need to find a "full" install of that compiler for macos...

Trying from here

@andrewdavidmackenzie
Copy link
Author

Using

brew tap messense/macos-cross-toolchains
brew install arm-unknown-linux-gnueabihf

I was able to get armv7 working!

Now musl fails, but it's a step in the right direction.

I'll close this issue now.

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

No branches or pull requests

3 participants