From de7ff00de56741bbe87c5f2d0f2eed8fc3a229b2 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Mon, 27 May 2013 17:57:00 +0200 Subject: [PATCH 1/3] waf: add --with[out]-pie configure arguments The arguments do not currently have any effect. Reviewed-by: Andrew Bartlett --- wscript | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/wscript b/wscript index 645deb2..d77f3fa 100644 --- a/wscript +++ b/wscript @@ -56,6 +56,13 @@ def set_options(opt): help='disable AD DC functionality (enables Samba 4 client and Samba 3 code base).', action='store_true', dest='without_ad_dc', default=False) + opt.add_option('--with-pie', + help=("Build Position Independent Executables (default)"), + action="store_true", dest='enable_pie', default=True) + opt.add_option('--without-pie', + help=("Disable Position Independent Executable builds"), + action="store_false", dest='enable_pie') + gr = opt.option_group('developer options') opt.add_option('--disable-ntdb', @@ -168,6 +175,10 @@ def configure(conf): conf.SAMBA_CONFIG_H('include/config.h') + if Options.options.enable_pie == True: + conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=True, + msg="Checking compiler for PIE support") + conf.env['ENABLE_PIE'] = True def etags(ctx): '''build TAGS file using etags''' -- 1.8.1.4 From 27f03d44059a5574dcde463848db281df47105af Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Mon, 27 May 2013 17:57:01 +0200 Subject: [PATCH 2/3] waf: build position independent executables 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. Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Tue May 28 02:56:36 CEST 2013 on sn-devel-104 --- 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 3559cc1..46ba35a 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 From ecaeda0ec530d7b53c8a4c9809519ed845a3d25f Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Tue, 28 May 2013 15:00:47 +0200 Subject: [PATCH 3/3] waf: build PIEs if supported by the compiler Currently waf performs a mandatory check for compiler PIE support, unless --without-pie is specified. This change makes Waf only perform the mandatory check if --with-pie is specified. If neither --with-pie nor --without-pie are specified, then PIEs are only built if compiler support is available. Signed-off-by: David Disseldorp --- wscript | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/wscript b/wscript index d77f3fa..2e97745 100644 --- a/wscript +++ b/wscript @@ -57,8 +57,9 @@ def set_options(opt): action='store_true', dest='without_ad_dc', default=False) opt.add_option('--with-pie', - help=("Build Position Independent Executables (default)"), - action="store_true", dest='enable_pie', default=True) + help=("Build Position Independent Executables " + + "(default if supported by compiler)"), + action="store_true", dest='enable_pie') opt.add_option('--without-pie', help=("Disable Position Independent Executable builds"), action="store_false", dest='enable_pie') @@ -175,10 +176,15 @@ def configure(conf): conf.SAMBA_CONFIG_H('include/config.h') - if Options.options.enable_pie == True: - conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=True, - msg="Checking compiler for PIE support") - conf.env['ENABLE_PIE'] = True + if Options.options.enable_pie != False: + if Options.options.enable_pie == True: + need_pie = True + else: + # not specified, only build PIEs if supported by compiler + need_pie = False + if conf.check_cc(cflags='-fPIE', ldflags='-pie', mandatory=need_pie, + msg="Checking compiler for PIE support"): + conf.env['ENABLE_PIE'] = True def etags(ctx): '''build TAGS file using etags''' -- 1.8.1.4