[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&#39;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 &lt;<a \
href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>&gt; \
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 &lt;<a href="mailto:peter.smith@linaro.org" \
target="_blank">peter.smith@linaro.org</a>&gt; wrote:<br> &gt;<br>
&gt; A caveat, this is on X86_64. Your clang may have a target where all<br>
&gt; code is PIC. Let me know if I&#39;ve misunderstood your question?<br>
&gt;<br>
&gt; int global;<br>
&gt;<br>
&gt; int f() { return global; }<br>
&gt;<br>
&gt; I&#39;ve edited the assembler output to remove directives.<br>
&gt; clang f.c -fno-pic -S -o -<br>
&gt; f:<br>
&gt; pushq %rbp<br>
&gt; movq %rsp, %rbp<br>
&gt; movl global, %eax<br>
&gt; popq %rbp<br>
&gt; retq<br>
&gt;<br>
&gt; clang f.c -fPIC -S -o -<br>
&gt; f:<br>
&gt; pushq %rbp<br>
&gt; movq %rsp, %rbp<br>
&gt; movq global@GOTPCREL(%rip), %rax<br>
&gt; movl (%rax), %eax<br>
&gt; popq %rbp<br>
&gt; 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 &lt;($CC -S -fno-pic f.c -c -o -) &lt;($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 &lt;($CC -S -fno-pic f.c -c -o -) &lt;($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 &lt;stdio.h&gt;<br>
<br>
int global;<br>
int f() { return global; }<br>
<br>
$ uname<br>
Linux<br>
$ ./main.sh<br>
function cmd {<br>
diff &lt;(&quot;$CC&quot; -S -fno-pic f.c -c -o -) &lt;(&quot;$CC&quot; -S -fPIC f.c \
-c -o -)<br> }<br>
<br>
CC=clang cmd<br>
&quot;$CC&quot; -S -fPIC f.c -c -o -<br>
&quot;$CC&quot; -S -fno-pic f.c -c -o -<br>
14c14,15<br>
&lt;        movl      global, %eax<br>
---<br>
&gt;        movq      global@GOTPCREL(%rip), %rax<br>
&gt;        movl      (%rax), %eax<br>
CC=gcc cmd<br>
&quot;$CC&quot; -S -fPIC f.c -c -o -<br>
&quot;$CC&quot; -S -fno-pic f.c -c -o -<br>
14c14,15<br>
&lt;        movl      global(%rip), %eax<br>
---<br>
&gt;        movq      global@GOTPCREL(%rip), %rax<br>
&gt;        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