LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 13410 - option to generate PIE by default
Summary: option to generate PIE by default
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: 3.1
Hardware: PC Linux
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-19 16:42 PDT by wbrana
Modified: 2021-04-16 03:10 PDT (History)
9 users (show)

See Also:
Fixed By Commit(s):


Attachments
built-in specs file generated by: gcc -dumpspecs (6.72 KB, text/plain)
2012-07-20 02:53 PDT, wbrana
Details

Note You need to log in before you can comment on or make changes to this bug.
Description wbrana 2012-07-19 16:42:51 PDT
GCC in Gentoo Hardened generates PIE by default
clang could have configure option to generate PIE by default
Comment 1 Duncan Sands 2012-07-20 02:22:30 PDT
Does GCC have such a configure option (I don't see one in mainline GCC)?
Comment 2 wbrana 2012-07-20 02:44:34 PDT
GCC supports optional configuration file named "specs", which can be used to enable PIE by default. If specs file isn't present default built-in specs is used. On Gentoo modification of built-in specs is used to enable PIE by default.
optional specs file on my PC is located at 
/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.4/specs
Comment 3 wbrana 2012-07-20 02:53:28 PDT
Created attachment 8933 [details]
built-in specs file generated by: gcc -dumpspecs
Comment 4 wbrana 2017-03-15 14:00:30 PDT
GCC 6 has configure option
https://gcc.gnu.org/gcc-6/changes.html
The --enable-default-pie configure option enables generation of PIE by default.
Comment 5 Evangelos Foutras 2017-06-30 19:59:33 PDT
In addition to an option to enable PIE by default, it would also be nice to have an option to enable SSP by default; something similar to GCC's:

  --enable-default-ssp: Default flag_stack_protect to -fstack-protector-strong
Comment 6 Nick Lewycky 2019-03-25 12:38:50 PDT
+Richard and I were talking about this recently.

IMO, we should link PIE by default and not bother with an configure option. If you want a no-pie link, use the -no-pie flag.

Source packages already have to specify -no-pie if they want to link against a non-pie .o file when building with a distro-distributed GCCs, because distro GCCs already enable PIC by default through the GCC configure flag.
Comment 7 Nick Lewycky 2019-03-25 13:06:23 PDT
FYI, distros are starting to patch clang to add the feature just as they enable the configure flag for GCC. Here's one from ArchLinux referencing this bug: https://git.archlinux.org/svntogit/packages.git/tree/trunk/0002-Enable-SSP-and-PIE-by-default.patch?h=packages/llvm&id=1d5568f96e56efb2186b3ae081488e1e5a509397