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

target triple overrides mcpu in zig cc #14467

Closed
SuperFluffy opened this issue Jan 26, 2023 · 1 comment
Closed

target triple overrides mcpu in zig cc #14467

SuperFluffy opened this issue Jan 26, 2023 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior zig cc Zig as a drop-in C compiler feature

Comments

@SuperFluffy
Copy link

SuperFluffy commented Jan 26, 2023

Zig Version

0.10.1

Steps to Reproduce and Observed Behavior

I fail to cross compile an asm file that you can find here from an x86_64 machine to aarch64-linux-gnu and an nvidia jetson carmel+v8_2a+crypto:

❯ zig cc -O0 -ffunction-sections -fdata-sections -fPIC -g -fno-omit-frame-pointer -Wall -Wextra -mcpu=carmel+v8_2a+crypto --target=aarch64-linux-gnu -c -o sha256_aarch64.so -c src/sha256_aarch64.S
src/sha256_aarch64.S:75:2: error: instruction requires: sha2
sha256su0 v8.4s, v9.4s

I have also tried -mcpu=generic+v8a+crypto and -mcpu=apple_m1+crypto, but none of them work.

Using verbose output I noticed that neither CPU nor features seem to be passed through:

❯ zig cc -v -O0 -ffunction-sections -fdata-sections -fPIC -g -fno-omit-frame-pointer -Wall -Wextra -mcpu=carmel+v8_2a+crypto --target=aarch64-linux-gnu -c -o sha256_aarch64.so -c src/sha256_aarch64.S
clang version 15.0.7
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/zig" -cc1 -triple aarch64-unknown-linux-gnu -E -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name sha256_aarch64.S -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=non-leaf -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +neon -target-feature +v8a -target-abi aapcs -fallow-half-arguments-and-returns -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -v -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/home/janis/dev/worldcoin/asm-hashes/sha2 -resource-dir /usr/lib/clang/15.0.7 -D __GLIBC_MINOR__=19 -internal-isystem /usr/lib/clang/15.0.7/include -internal-isystem /usr/local/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wall -Wextra -fdebug-compilation-dir=/home/janis/dev/worldcoin/asm-hashes/sha2 -ferror-limit 19 -stack-protector 2 -fno-signed-char -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/sha256_aarch64-b93408.s -x assembler-with-cpp src/sha256_aarch64.S
clang -cc1 version 15.0.7 based upon LLVM 15.0.7 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/clang/15.0.7/include
 /usr/local/include
 /usr/include
End of search list.
 "/usr/bin/zig" -cc1as -triple aarch64-unknown-linux-gnu -filetype obj -main-file-name sha256_aarch64.S -target-cpu generic -target-feature +neon -target-feature +v8a -fdebug-compilation-dir=/home/janis/dev/worldcoin/asm-hashes/sha2 -dwarf-debug-producer "clang version 15.0.7" -debug-info-kind=constructor -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -object-file-name=/home/janis/.cache/zig/tmp/5ea73be61cd6ff63-sha256_aarch64.o -o /home/janis/.cache/zig/tmp/5ea73be61cd6ff63-sha256_aarch64.o /tmp/sha256_aarch64-b93408.s
src/sha256_aarch64.S:75:2: error: instruction requires: sha2
 sha256su0 v8.4s, v9.4s
 ^

Note -target-cpu generic -target-feature +neon -target-feature +v8a and the absence of my -mcpu settings. Changing the last command adding my desired features compiles without errors:

"/usr/bin/zig" -cc1as -triple aarch64-unknown-linux-gnu -filetype obj -main-file-name sha256_aarch64.S -target-cpu carmel -target-feature +neon -target-feature +v8a -target-feature crypto -fdebug-compilation-dir
=/home/janis/dev/worldcoin/asm-hashes/sha2 -dwarf-debug-producer "clang version 15.0.7" -debug-info-kind=constructor -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -object-file-name=/home/janis/.cach
e/zig/tmp/4c1793aa0f782f3d-sha256_aarch64.o -o /home/janis/.cache/zig/tmp/4c1793aa0f782f3d-sha256_aarch64.o /tmp/sha256_aarch64-fb28b5.s

(side note: it looks like -target-feature +v8_2a is not a valid target feature? If I set it I get '+v8_2a' is not a recognized feature for this target (ignoring feature))

Expected Behavior

I expect zig to respect -mcpu and not override it using the defaults(?) of the target triple. Or noisily complain that it will do that

It looks like this was previously addressed in these issues: #9196 #4912

@SuperFluffy SuperFluffy added the bug Observed behavior contradicts documented or intended behavior label Jan 26, 2023
@SuperFluffy SuperFluffy changed the title target triple still overrides mcpu in zig cc target triple overrides mcpu in zig cc Jan 26, 2023
@Vexu Vexu added the zig cc Zig as a drop-in C compiler feature label Jan 26, 2023
@Vexu Vexu added this to the 0.12.0 milestone Jan 26, 2023
@mikdusan
Copy link
Member

duplicate of #10411 and #10411 (comment) has a good explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior zig cc Zig as a drop-in C compiler feature
Projects
None yet
Development

No branches or pull requests

3 participants