[cfe-dev] Why -fno-pic and -fPIC gives the same results?
Peter Smith via cfe-dev
cfe-dev at lists.llvm.org
Thu Jan 24 08:21:19 PST 2019
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 at GOTPCREL(%rip), %rax
movl (%rax), %eax
popq %rbp
retq
On Thu, 24 Jan 2019 at 16:08, Peng Yu <pengyu.ut at gmail.com> wrote:
>
> > On many targets the instructions needed for an empty function won't
> > need to refer to an address at all, so will always be position
> > independent, hence no difference in code-generation. If you make the
> > example a bit more complex, such as using a global variable then
> > you'll see some code-generation differences between -fPIC and
> > -fno-pic.
>
> Could you help make a minimal example? I used some global variables.
> But the results are still the same. Thanks.
>
> --
> Regards,
> Peng
More information about the cfe-dev
mailing list