zig
zig copied to clipboard
zig cc does not respect `-` to read from stdin
Zig Version
0.10.0-dev.3838+77f31ebbb
Steps to Reproduce
$ echo | zig cc -x c -c - -o x.o
LLD Link... ld.lld: error: cannot open -: No such file or directory
Expected Behavior
x.o
gets created, like with clang:
$ echo | clang-14 -x c -c - -o x.o
$ file x.o
x.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
Impact: Go toolchain uses this idiom to detect which compiler flags are supported.
Possibly refs #10915
Another data point: besides Go tests, this causes luajit
checks to fail: https://www.freelists.org/post/luajit/unable-to-compile-luajit-since-e1319361-with-zigcc,1
This is the referenced line:
echo 'extern void b(void);int a(void){b();return 0;}' | $(TARGET_CC) -c -x c - -o tmpunwind.o && { grep -qa -e eh_frame -e __unwind_info tmpunwind.o || grep -qU -e eh_frame -e __unwind_info tmpunwind.o; } && echo E; rm -f tmpunwind.o
If we decipher this, clang-15
vs zig cc
:
$ echo 'extern void b(void);int a(void){b();return 0;}' | clang-15 -c -x c - -o tmpunwind.o
$ echo 'extern void b(void);int a(void){b();return 0;}' | zig cc -target x86_64-linux-gnu.2.28 -c -x c - -o tmpunwind.o
LLD Link... ld.lld: error: cannot open -: No such file or directory
I started working on this.
Question asked originally on IRC: I have two options:
- swallow stdin to a tempfile and treat it as a regular C file all throughout src/Compilation.zig.
- make a special case that, if the source is non-seekable, do not cache it (and pass the - downstream to clang).
I am leaning towards (1), because we still may be able to use cache and it does not add complexity to Compilation.zig; any reason I should prefer (2)?
Had a chat with Andrew about this yesterday. He confirmed going with (1) is the right thing to do.