diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2017-08-22 11:41:47 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-08-22 18:01:05 -0400 |
commit | 3625728a0e3a9b56c2b85ae7ea8bcabdd83ece6a (patch) | |
tree | c8d0ff7e921436d011e70018c5cea974dcf67f23 /docs | |
parent | dbaa9a237b6d9771c0e9bde0e50fd2134c2f4dd0 (diff) | |
download | haskell-3625728a0e3a9b56c2b85ae7ea8bcabdd83ece6a.tar.gz |
Add support for producing position-independent executables
Previously due to #12759 we disabled PIE support entirely. However, this
breaks the user's ability to produce PIEs. Add an explicit flag, -fPIE,
allowing the user to build PIEs.
Test Plan: Validate
Reviewers: rwbarton, austin, simonmar
Subscribers: trommler, simonmar, trofi, jrtc27, thomie
GHC Trac Issues: #12759, #13702
Differential Revision: https://phabricator.haskell.org/D3589
Diffstat (limited to 'docs')
-rw-r--r-- | docs/users_guide/phases.rst | 24 | ||||
-rw-r--r-- | docs/users_guide/shared_libs.rst | 4 |
2 files changed, 28 insertions, 0 deletions
diff --git a/docs/users_guide/phases.rst b/docs/users_guide/phases.rst index 92e308db15..0b754621dd 100644 --- a/docs/users_guide/phases.rst +++ b/docs/users_guide/phases.rst @@ -1113,3 +1113,27 @@ for example). aren't referenced by any other code linked into the executable. If you're using ``-fwhole-archive-hs-libs``, you probably also want ``-rdynamic``. + +.. ghc-flag:: -pie + :shortdesc: Instruct the linker to produce a position-independent executable. + :type: dynamic + :category: linking + + :since: 8.2.1 + + This instructs the linker to produce a position-independent executable. + This flag is only valid while producing executables and all object code + being linked must have been produced with :ghc-flag:`-fPIE`. + + Position independent executables are required by some platforms as they + enable address-space layout randomization (ASLR), a common security measure. + They can also be useful as they can be dynamically loaded and used as shared + libraries by other executables. + + Position independent executables should be dynamically-linked (e.g. built + with :ghc-flag:`-dynamic` and only loaded into other dynamically-linked + executables to ensure that only one ``libHSrts`` is present if + loaded into the address space of another Haskell process. + + Also, you may need to use the :ghc-flags:`-rdynamic` flag to ensure that + that symbols are not dropped from your PIE object. diff --git a/docs/users_guide/shared_libs.rst b/docs/users_guide/shared_libs.rst index 486df51ad9..7e525019ca 100644 --- a/docs/users_guide/shared_libs.rst +++ b/docs/users_guide/shared_libs.rst @@ -207,6 +207,10 @@ library directories of all the packages that the program depends on paths. The unix tool ``readelf --dynamic`` is handy for inspecting the ``RPATH``/``RUNPATH`` entries in ELF shared libraries and executables. +On most UNIX platforms it is also possible to build executables that can be +``dlopen``\'d like shared libraries using the :ghc-flag:`-pie` flag during +linking. + .. _finding-shared-libs-mac: Mac OS X |