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

using zig cc for mips(64)-linux-gnu target w/ flag -fno-PIC generates a TargetRequiresPIC error #17414

Closed
CrepeGoat opened this issue Oct 6, 2023 · 1 comment
Labels
arch-mips 32-bit and 64-bit MIPS bug Observed behavior contradicts documented or intended behavior zig cc Zig as a drop-in C compiler feature

Comments

@CrepeGoat
Copy link
Contributor

Zig Version

0.12.0-dev.163+6780a6bbf

Steps to Reproduce and Observed Behavior

  • Take an arbitrary C file, e.g. hello.c:
int main()
{
    return 0;
}
  • compile it for either mips-linux-gnu or mips64-..., using the -fno-PIC flag, e.g.:
$ zig cc --target=mips-linux-gnu -c -v -mabi=64 -fno-PIC -mno-abicalls hello.c
  • the command returns an error (note that the -v flag doesn't add any additional output information):
error: unable to create compilation: TargetRequiresPIC

Expected Behavior

By comparison, running clang with the same inputs succeeds:

$ clang --target=mips-linux-gnu -c -mabi=64 -fno-PIC -mno-abicalls -v hello.c
clang version 11.1.0
Target: mips64-unknown-linux-gnuabi64
Thread model: posix
InstalledDir: /nix/store/2myg6jq41n774bc2pqva8rwv5jd6kzw2-clang-11.1.0/bin
clang-11: warning: argument unused during compilation: '-mmacos-version-min=10.12' [-Wunused-command-line-argument]
clang-11: warning: argument unused during compilation: '-arch x86_64' [-Wunused-command-line-argument]
 (in-process)
 "/nix/store/2myg6jq41n774bc2pqva8rwv5jd6kzw2-clang-11.1.0/bin/clang-11" -cc1 -triple mips64-unknown-linux-gnuabi64 -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -target-cpu mips64r2 -target-feature +noabicalls -target-abi n64 -mfloat-abi hard -mllvm -mgpopt -fno-split-dwarf-inlining -debugger-tuning=gdb -target-linker-version 609 -v -nostdsysteminc -resource-dir /nix/store/78yj291bzmwpqww4cgr4vm5mgax86jpy-clang-wrapper-11.1.0/resource-root -idirafter /nix/store/sq9w5y029sl08x2v7f42qldz5yvjarap-Libsystem-1238.60.2/include -isystem /nix/store/naxm44wzljym43ykf1zrg40cdlf1zqp4-gnumake-4.2.1/include -isystem /nix/store/c1031bk1zp7mfm9sfci705sb7rsqa456-mips-linux-gnu-binutils-2.37/include -isystem /nix/store/m4xswnlzvn2q65gmgjqjlnlicbgs29f0-libcxx-11.1.0-dev/include -isystem /nix/store/9fnxklyylz4a46dnpjzv7zb2r07bs2ab-libcxxabi-11.1.0-dev/include -isystem /nix/store/9p7g1yznh1hwkxx402yb3hnmcc3ai7cw-compiler-rt-libc-11.1.0-dev/include -iframework /nix/store/9knjxrwxclz7brjxx823kzriz56kls71-swift-corefoundation-unstable-2018-09-14/Library/Frameworks -isystem /nix/store/naxm44wzljym43ykf1zrg40cdlf1zqp4-gnumake-4.2.1/include -isystem /nix/store/c1031bk1zp7mfm9sfci705sb7rsqa456-mips-linux-gnu-binutils-2.37/include -isystem /nix/store/m4xswnlzvn2q65gmgjqjlnlicbgs29f0-libcxx-11.1.0-dev/include -isystem /nix/store/9fnxklyylz4a46dnpjzv7zb2r07bs2ab-libcxxabi-11.1.0-dev/include -isystem /nix/store/9p7g1yznh1hwkxx402yb3hnmcc3ai7cw-compiler-rt-libc-11.1.0-dev/include -iframework /nix/store/9knjxrwxclz7brjxx823kzriz56kls71-swift-corefoundation-unstable-2018-09-14/Library/Frameworks -U _FORTIFY_SOURCE -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -internal-isystem /nix/store/78yj291bzmwpqww4cgr4vm5mgax86jpy-clang-wrapper-11.1.0/resource-root/include -O2 -Wformat -Wformat-security -Werror=format-security -fdebug-compilation-dir /Users/beckerawqatty/Repos/sm64 -ferror-limit 19 -fwrapv -stack-protector 2 -stack-protector-buffer-size 4 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -o hello.o -x c hello.c
clang -cc1 version 11.1.0 based upon LLVM 11.1.0 default target x86_64-apple-darwin22.5.0
ignoring duplicate directory "/nix/store/naxm44wzljym43ykf1zrg40cdlf1zqp4-gnumake-4.2.1/include"
ignoring duplicate directory "/nix/store/c1031bk1zp7mfm9sfci705sb7rsqa456-mips-linux-gnu-binutils-2.37/include"
ignoring duplicate directory "/nix/store/m4xswnlzvn2q65gmgjqjlnlicbgs29f0-libcxx-11.1.0-dev/include"
ignoring duplicate directory "/nix/store/9fnxklyylz4a46dnpjzv7zb2r07bs2ab-libcxxabi-11.1.0-dev/include"
ignoring duplicate directory "/nix/store/9p7g1yznh1hwkxx402yb3hnmcc3ai7cw-compiler-rt-libc-11.1.0-dev/include"
ignoring duplicate directory "/nix/store/9knjxrwxclz7brjxx823kzriz56kls71-swift-corefoundation-unstable-2018-09-14/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /nix/store/naxm44wzljym43ykf1zrg40cdlf1zqp4-gnumake-4.2.1/include
 /nix/store/c1031bk1zp7mfm9sfci705sb7rsqa456-mips-linux-gnu-binutils-2.37/include
 /nix/store/m4xswnlzvn2q65gmgjqjlnlicbgs29f0-libcxx-11.1.0-dev/include
 /nix/store/9fnxklyylz4a46dnpjzv7zb2r07bs2ab-libcxxabi-11.1.0-dev/include
 /nix/store/9p7g1yznh1hwkxx402yb3hnmcc3ai7cw-compiler-rt-libc-11.1.0-dev/include
 /nix/store/9knjxrwxclz7brjxx823kzriz56kls71-swift-corefoundation-unstable-2018-09-14/Library/Frameworks (framework directory)
 /nix/store/78yj291bzmwpqww4cgr4vm5mgax86jpy-clang-wrapper-11.1.0/resource-root/include
 /nix/store/sq9w5y029sl08x2v7f42qldz5yvjarap-Libsystem-1238.60.2/include
End of search list.

...and the output file hello.o is parsable with mips-linux-gnu-objdump:

$ mips-linux-gnu-objdump -d hello.o

hello.o:     file format elf64-tradbigmips


Disassembly of section .text:

0000000000000000 <main>:
   0:	03e00008 	jr	ra
   4:	64020000 	daddiu	v0,zero,0
@CrepeGoat CrepeGoat added the bug Observed behavior contradicts documented or intended behavior label Oct 6, 2023
@Vexu Vexu added arch-mips 32-bit and 64-bit MIPS zig cc Zig as a drop-in C compiler feature labels Oct 6, 2023
CrepeGoat added a commit to CrepeGoat/sm64 that referenced this issue Nov 6, 2023
current error:
```
error: unable to create compilation: TargetRequiresPIC
```

`ziglang/zig` issue submitted at ziglang/zig#17414
@Vexu Vexu added this to the 0.15.0 milestone Mar 26, 2024
@alexrp
Copy link
Member

alexrp commented Sep 7, 2024

This is effectively a duplicate of #17430. Suggest closing this one since #17430 has more info/discussion.

@Vexu Vexu closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2024
@Vexu Vexu removed this from the 0.16.0 milestone Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-mips 32-bit and 64-bit MIPS 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