<div dir="ltr"><div dir="ltr">64-bit mac binaries (both x86 and arm) always force PIC on and it can't be disabled there. (cf <a href="http://llvm-cs.pcc.me.uk/tools/clang/lib/Driver/ToolChains/Darwin.cpp#2222">http://llvm-cs.pcc.me.uk/tools/clang/lib/Driver/ToolChains/Darwin.cpp#2222</a>)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 24, 2019 at 11:40 AM Peng Yu via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, Jan 24, 2019 at 10:21 AM Peter Smith <<a href="mailto:peter.smith@linaro.org" target="_blank">peter.smith@linaro.org</a>> wrote:<br>
><br>
> A caveat, this is on X86_64. Your clang may have a target where all<br>
> code is PIC. Let me know if I've misunderstood your question?<br>
><br>
> int global;<br>
><br>
> int f() { return global; }<br>
><br>
> I've edited the assembler output to remove directives.<br>
> clang f.c -fno-pic -S -o -<br>
> f:<br>
> pushq %rbp<br>
> movq %rsp, %rbp<br>
> movl global, %eax<br>
> popq %rbp<br>
> retq<br>
><br>
> clang f.c -fPIC -S -o -<br>
> f:<br>
> pushq %rbp<br>
> movq %rsp, %rbp<br>
> movq global@GOTPCREL(%rip), %rax<br>
> movl (%rax), %eax<br>
> popq %rbp<br>
> retq<br>
<br>
Here is what I have. So Mac OS X does not support -fno-pic? I think<br>
that clang should show some messages when -fno-pic is not supported.<br>
<br>
$ uname<br>
Darwin<br>
$ cat main.sh<br>
#!/usr/bin/env bash<br>
# vim: set noexpandtab tabstop=2:<br>
<br>
set -v<br>
function cmd {<br>
diff <($CC -S -fno-pic f.c -c -o -) <($CC -S -fPIC f.c -c -o -)<br>
}<br>
<br>
CC=clang cmd<br>
CC=gcc cmd<br>
$ ./main.sh<br>
function cmd {<br>
diff <($CC -S -fno-pic f.c -c -o -) <($CC -S -fPIC f.c -c -o -)<br>
}<br>
<br>
CC=clang cmd<br>
CC=gcc cmd<br>
$ cat f.c<br>
/* vim: set noexpandtab tabstop=2: */<br>
#include <stdio.h><br>
<br>
int global;<br>
int f() { return global; }<br>
<br>
$ uname<br>
Linux<br>
$ ./main.sh<br>
function cmd {<br>
diff <("$CC" -S -fno-pic f.c -c -o -) <("$CC" -S -fPIC f.c -c -o -)<br>
}<br>
<br>
CC=clang cmd<br>
"$CC" -S -fPIC f.c -c -o -<br>
"$CC" -S -fno-pic f.c -c -o -<br>
14c14,15<br>
< movl global, %eax<br>
---<br>
> movq global@GOTPCREL(%rip), %rax<br>
> movl (%rax), %eax<br>
CC=gcc cmd<br>
"$CC" -S -fPIC f.c -c -o -<br>
"$CC" -S -fno-pic f.c -c -o -<br>
14c14,15<br>
< movl global(%rip), %eax<br>
---<br>
> movq global@GOTPCREL(%rip), %rax<br>
> movl (%rax), %eax<br>
<br>
<br>
-- <br>
Regards,<br>
Peng<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>