[cfe-dev] PIE/PIC Clang Defaults on Linux x86-64

Eric Christopher via cfe-dev cfe-dev at lists.llvm.org
Tue Jun 2 14:58:21 PDT 2020


I'll elaborate on this a bit more since it may not be coming across clearly:

a) gcc and clang differ here:

clang++/g++  -o foo.x foo.c -fPIE

gcc passes -pie to the linker and clang doesn't. This mostly seems like an
oversight that can be fixed.

b) gcc and clang differ here

clang++/g++ -o foo.x foo.c

where gcc defaults to -pie and pie code generation and clang doesn't.

This is something where we should at least have the discussion. For what
it's worth my thought is that we should move to PIE by default for linux
if, for not other reason, as the system compiler (gcc) already does this.
We also already do this on android and in some sanitizer cases.

Anyone else have any thoughts?

Thanks!

-eric

On Tue, Jun 2, 2020 at 2:44 PM Mitch Phillips via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi folks,
>
> I recently noticed that clang and GCC differ on the default PIE/PIC flags.
> In particular, clang doesn't default to PIE/PIC on Linux x86-64, and GCC
> does.
>
> $ clang++ a.cpp && readelf -l a.out | egrep '(LOAD|VirtAddr)'
>>   Type           Offset             VirtAddr           PhysAddr
>>   LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
>>
>
> $ g++ a.cpp && readelf -l a.out | egrep '(LOAD|VirtAddr)'
>>   Type           Offset             VirtAddr           PhysAddr
>
>   LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
>
>
> Are there any concerns about changing the clang default to emit PIC and
> pass PIE to the linker?
>
> Also, using `clang++ -fPIC -fPIE <...>` doesn't emit a PIE. Any opponents
> to making `-fPIE` imply passing `-pie` to the linker?
>
> - Mitch.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200602/7cc7260f/attachment.html>


More information about the cfe-dev mailing list