[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-dev
Subject: Re: [cfe-dev] Why -fno-pic and -fPIC gives the same results?
From: Nico Weber via cfe-dev <cfe-dev () lists ! llvm ! org>
Date: 2019-01-25 21:23:31
Message-ID: CAMGbLiGtE9ZKTBJM8aewcWGduO9g1Bvz6sBDCq-DFXJh4eUQVg () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
64-bit mac binaries (both x86 and arm) always force PIC on and it can't be
disabled there. (cf
http://llvm-cs.pcc.me.uk/tools/clang/lib/Driver/ToolChains/Darwin.cpp#2222)
On Thu, Jan 24, 2019 at 11:40 AM Peng Yu via cfe-dev <cfe-dev@lists.llvm.org>
wrote:
> On Thu, Jan 24, 2019 at 10:21 AM Peter Smith <peter.smith@linaro.org>
> wrote:
> >
> > A caveat, this is on X86_64. Your clang may have a target where all
> > code is PIC. Let me know if I've misunderstood your question?
> >
> > int global;
> >
> > int f() { return global; }
> >
> > I've edited the assembler output to remove directives.
> > clang f.c -fno-pic -S -o -
> > f:
> > pushq %rbp
> > movq %rsp, %rbp
> > movl global, %eax
> > popq %rbp
> > retq
> >
> > clang f.c -fPIC -S -o -
> > f:
> > pushq %rbp
> > movq %rsp, %rbp
> > movq global@GOTPCREL(%rip), %rax
> > movl (%rax), %eax
> > popq %rbp
> > retq
>
> Here is what I have. So Mac OS X does not support -fno-pic? I think
> that clang should show some messages when -fno-pic is not supported.
>
> $ uname
> Darwin
> $ cat main.sh
> #!/usr/bin/env bash
> # vim: set noexpandtab tabstop=2:
>
> set -v
> function cmd {
> diff <($CC -S -fno-pic f.c -c -o -) <($CC -S -fPIC f.c -c -o -)
> }
>
> CC=clang cmd
> CC=gcc cmd
> $ ./main.sh
> function cmd {
> diff <($CC -S -fno-pic f.c -c -o -) <($CC -S -fPIC f.c -c -o -)
> }
>
> CC=clang cmd
> CC=gcc cmd
> $ cat f.c
> /* vim: set noexpandtab tabstop=2: */
> #include <stdio.h>
>
> int global;
> int f() { return global; }
>
> $ uname
> Linux
> $ ./main.sh
> function cmd {
> diff <("$CC" -S -fno-pic f.c -c -o -) <("$CC" -S -fPIC f.c -c -o -)
> }
>
> CC=clang cmd
> "$CC" -S -fPIC f.c -c -o -
> "$CC" -S -fno-pic f.c -c -o -
> 14c14,15
> < movl global, %eax
> ---
> > movq global@GOTPCREL(%rip), %rax
> > movl (%rax), %eax
> CC=gcc cmd
> "$CC" -S -fPIC f.c -c -o -
> "$CC" -S -fno-pic f.c -c -o -
> 14c14,15
> < movl global(%rip), %eax
> ---
> > movq global@GOTPCREL(%rip), %rax
> > movl (%rax), %eax
>
>
> --
> Regards,
> Peng
> _______________________________________________
> cfe-dev mailing list
> cfe-dev@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
[Attachment #5 (text/html)]
<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>
[Attachment #6 (text/plain)]
_______________________________________________
cfe-dev mailing list
cfe-dev@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic