Browse Source

Default to PIE binaries on Linux. Fixes #61.

woollybah 6 years ago
parent
commit
8fc8042ae6
5 changed files with 41 additions and 3 deletions
  1. 7 1
      CHANGELOG
  2. 19 1
      bmk_config.bmx
  3. 6 0
      bmk_make.bmx
  4. 3 0
      bmk_util.bmx
  5. 6 1
      make.bmk

+ 7 - 1
CHANGELOG

@@ -1,3 +1,9 @@
+## [3.34] - 2019-03-15
+### Added
+ - New 'no-pie' option to disable PIE.
+### Changed
+ - Linux binaries are now built as position independent executables (PIE) as default.
+
 ## [3.33] - 2019-03-05
 ### Fixed
  - DLLs now statically link against libgcc.
@@ -10,7 +16,7 @@
 ### Added
  - New 'single' option. Forces single-threaded build mode.
  - Allow user-provided manifest files on Win32.
- ### Changed
+### Changed
  - Use application name for default application settings.
 
 ## [3.30] - 2018-12-04

+ 19 - 1
bmk_config.bmx

@@ -10,7 +10,7 @@ Import brl.map
 
 Import "stringbuffer_core.bmx"
 
-Const BMK_VERSION:String = "3.33"
+Const BMK_VERSION:String = "3.34"
 
 Const ALL_SRC_EXTS$="bmx;i;c;m;h;cpp;cxx;mm;hpp;hxx;s;cc;asm;S"
 
@@ -61,6 +61,8 @@ Global opt_nodef:Int
 Global opt_nohead:Int
 Global opt_require_override:Int
 Global opt_override_error:Int
+Global opt_nopie:Int
+Global opt_nopie_set:Int
 
 Global opt_dumpbuild
 
@@ -255,6 +257,9 @@ Function ParseConfigArgs$[]( args$[], legacyMax:Int = False )
 			opt_require_override = True
 		Case "overerr"
 			opt_override_error = True
+		Case "no-pie"
+			opt_nopie = True
+			opt_nopie_set = True
 		Default
 			CmdError "Invalid option '" + arg[1..] + "'"
 		End Select
@@ -406,6 +411,9 @@ Function Usage:String(fullUsage:Int = False)
 		s:+ "~t-overerr~n"
 		s:+ "~t~tUpgrades -override warnings to errors. (NG only)~n"
 		s:+ "~n~n"
+		s:+ "~t-no-pie~n"
+		s:+ "~t~tDisables option to compile position independent executables. (NG & Linux only)~n"
+		s:+ "~n~n"
 		s:+ "~t-q~n"
 		s:+ "~t~tQuiet build."
 		s:+ "~n~n"
@@ -591,6 +599,16 @@ Function AsConfigurable:Int(key:String, value:String)
 				End If
 			End If
 			config = True
+		Case "opt_nopie"
+			If Not opt_nopie_set Then
+				opt_nopie = Int(value)
+				set = 1
+			Else
+				If opt_nopie <> Int(value) Then
+					set = 2
+				End If
+			End If
+			config = True
 	End Select
 	If set And opt_verbose Then
 		If set = 1 Then

+ 6 - 0
bmk_make.bmx

@@ -316,6 +316,12 @@ Type TBuildManager Extends TCallback
 			ConfigureNXPaths()
 		End If
 		
+		If processor.Platform() = "linux" Or processor.Platform() = "raspberrypi" Then
+			If opt_nopie Then
+				globals.SetVar("nopie", "true")
+			End If
+		End If
+		
 		processor.callback = Self
 	End Method
 

+ 3 - 0
bmk_util.bmx

@@ -446,6 +446,9 @@ Function LinkApp( path$,lnk_files:TList,makelib,opts$ )
 		If opt_static Then
 			sb.Append(" -static")
 		End If
+		If Not opt_nopie Then
+			sb.Append(" -pie -fpie")
+		End If
 		sb.Append(" -pthread")
 		sb.Append(" -o ").Append(CQuote( path ))
 		sb.Append(" ").Append(CQuote( tmpfile ))

+ 6 - 1
make.bmk

@@ -186,6 +186,11 @@
 		
 	elseif bmk.Platform() == "linux" or bmk.Platform() == "android" or bmk.Platform() == "raspberrypi" then
 		cmd = bmk.Option(bmk.BuildName("gcc"), "gcc")
+		
+		if bmk.Option("nopie", "") == "true" then
+			globals.SetOption("cc_opts", "pie", "")
+		end
+		
 	elseif bmk.Platform() == "emscripten" then
 		cmd = bmk.Option(bmk.BuildName("gcc"), "emcc")
 		
@@ -475,7 +480,7 @@
 			globals.SetOption("cc_opts", "arch", "-m32")
 			globals.SetOption("cc_opts", "fancymath", "-mfancy-math-387")
 		end
-	
+		globals.SetOption("cc_opts", "pie", "-fpie")
 	end
 
 	globals.SetOption("cc_opts", "exceptions", "-fno-exceptions")