[PATCH 2/2] waf: build position independent executables

David Disseldorp ddiss at samba.org
Mon May 27 09:57:01 MDT 2013


This patch re-instates support for building Position Independent
Executables using the '-fPIE' and '-pie' compiler and linker flags
respectively.

PIE builds are enabled by default, and can be explicitly disabled using
the '--without-pie' configure argument.
---
 buildtools/wafsamba/wafsamba.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py
index 2ef68b1..0d407e6 100644
--- a/buildtools/wafsamba/wafsamba.py
+++ b/buildtools/wafsamba/wafsamba.py
@@ -342,6 +342,13 @@ def SAMBA_BINARY(bld, binname, source,
     else:
         subsystem_group = group
 
+    # only specify PIE flags for binaries
+    pie_cflags = cflags
+    pie_ldflags = TO_LIST(ldflags)
+    if bld.env['ENABLE_PIE'] == True:
+        pie_cflags += ' -fPIE'
+        pie_ldflags.extend(TO_LIST('-pie'))
+
     # first create a target for building the object files for this binary
     # by separating in this way, we avoid recompiling the C files
     # separately for the install binary and the build binary
@@ -349,7 +356,7 @@ def SAMBA_BINARY(bld, binname, source,
                         source         = source,
                         deps           = deps,
                         includes       = includes,
-                        cflags         = cflags,
+                        cflags         = pie_cflags,
                         group          = subsystem_group,
                         autoproto      = autoproto,
                         subsystem_name = subsystem_name,
@@ -379,7 +386,7 @@ def SAMBA_BINARY(bld, binname, source,
         install_path   = None,
         samba_inst_path= install_path,
         samba_install  = install,
-        samba_ldflags  = TO_LIST(ldflags)
+        samba_ldflags  = pie_ldflags
         )
 
     if manpages is not None and 'XSLTPROC_MANPAGES' in bld.env and bld.env['XSLTPROC_MANPAGES']:
-- 
1.8.1.4



More information about the samba-technical mailing list