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

Mitch Phillips via cfe-dev cfe-dev at lists.llvm.org
Tue Jun 2 14:31:48 PDT 2020


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200602/602cf7f8/attachment.html>


More information about the cfe-dev mailing list