From f8abe228960b60443ef6818efd87728da9d1ab7b Mon Sep 17 00:00:00 2001
From: chen-jan <chen_aka_jan@163.com>
Date: Tue, 6 Jun 2023 10:33:24 +0800
Subject: [PATCH] add PIE compiler options

---
 makefile.afl                                | 2 +-
 makefile.android_arm                        | 2 +-
 makefile.linux_amd64                        | 2 +-
 makefile.linux_amd64_asm                    | 2 +-
 makefile.linux_amd64_sanitizer              | 2 +-
 makefile.linux_any_cpu                      | 2 +-
 makefile.linux_any_cpu_gcc_4.X              | 2 +-
 makefile.linux_clang_amd64_asm              | 2 +-
 makefile.linux_clang_amd64_asm_sanitize     | 2 +-
 makefile.linux_cross_aarch64                | 2 +-
 makefile.linux_cross_arm                    | 2 +-
 makefile.linux_cross_m68k                   | 2 +-
 makefile.linux_cross_mipsel                 | 2 +-
 makefile.linux_cross_ppc                    | 2 +-
 makefile.linux_cross_ppc64                  | 2 +-
 makefile.linux_cross_ppc64le                | 2 +-
 makefile.linux_cross_s390x                  | 2 +-
 makefile.linux_cross_sparc64                | 2 +-
 makefile.linux_gcc6_sanitize                | 2 +-
 makefile.linux_gcc_2.95_no_need_for_libstdc | 2 +-
 makefile.linux_other                        | 2 +-
 makefile.linux_s390x                        | 2 +-
 makefile.linux_scan-build                   | 2 +-
 makefile.linux_valgrind                     | 2 +-
 makefile.linux_x32                          | 2 +-
 makefile.linux_x86_asm_gcc_4.X              | 2 +-
 makefile.linux_x86_asm_gcc_4.X_fltk         | 2 +-
 makefile.linux_x86_asm_gcc_mudflap_4.X      | 2 +-
 makefile.machine                            | 2 +-
 29 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/makefile.afl b/makefile.afl
index c1c2826..acaecbd 100644
--- a/makefile.afl
+++ b/makefile.afl
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.android_arm b/makefile.android_arm
index 8ab6073..b7b5542 100644
--- a/makefile.android_arm
+++ b/makefile.android_arm
@@ -29,7 +29,7 @@ ANDROID_LINK= \
 
 OPTFLAGS=-O3 -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	$(ANDROID_FLAGS) \
 	$(LOCAL_FLAGS)
diff --git a/makefile.linux_amd64 b/makefile.linux_amd64
index 898d9df..d2ec855 100644
--- a/makefile.linux_amd64
+++ b/makefile.linux_amd64
@@ -2,7 +2,7 @@
 OPTFLAGS=-O -s
 
 # use "-m32" to have a 32bits executable
-ALLFLAGS=-m64 ${OPTFLAGS} -pipe \
+ALLFLAGS=-m64 ${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_amd64_asm b/makefile.linux_amd64_asm
index 075c6a8..5513722 100644
--- a/makefile.linux_amd64_asm
+++ b/makefile.linux_amd64_asm
@@ -4,7 +4,7 @@
 OPTFLAGS=-O -s
 
 # use "-m32" to have a 32bits executable
-ALLFLAGS=-m64 ${OPTFLAGS} -pipe \
+ALLFLAGS=-m64 ${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_amd64_sanitizer b/makefile.linux_amd64_sanitizer
index 93bbe97..6178756 100644
--- a/makefile.linux_amd64_sanitizer
+++ b/makefile.linux_amd64_sanitizer
@@ -6,7 +6,7 @@ OPTFLAGS=-g2 -fsanitize=address -fno-omit-frame-pointer
 # OPTFLAGS=-g2 -fsanitize=thread -fno-omit-frame-pointer
 #OPTFLAGS=-g2 -fsanitize=undefined -ftrapv -fsanitize=address -fsanitize=undefined -fno-sanitize=alignment -fno-omit-frame-pointer
 
-ALLFLAGS=${OPTFLAGS} -pipe  \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie  \
 	-DDONT_REDEFINE_NEW \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
diff --git a/makefile.linux_any_cpu b/makefile.linux_any_cpu
index 9e34c34..a1162b8 100644
--- a/makefile.linux_any_cpu
+++ b/makefile.linux_any_cpu
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_any_cpu_gcc_4.X b/makefile.linux_any_cpu_gcc_4.X
index be093b5..ec8cf2c 100644
--- a/makefile.linux_any_cpu_gcc_4.X
+++ b/makefile.linux_any_cpu_gcc_4.X
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_clang_amd64_asm b/makefile.linux_clang_amd64_asm
index ccbb8c3..2f51967 100644
--- a/makefile.linux_clang_amd64_asm
+++ b/makefile.linux_clang_amd64_asm
@@ -1,7 +1,7 @@
 
 OPTFLAGS=-O3
 
-ALLFLAGS=-m64 ${OPTFLAGS} -pipe \
+ALLFLAGS=-m64 ${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_clang_amd64_asm_sanitize b/makefile.linux_clang_amd64_asm_sanitize
index 65c7f1f..c5c9512 100644
--- a/makefile.linux_clang_amd64_asm_sanitize
+++ b/makefile.linux_clang_amd64_asm_sanitize
@@ -2,7 +2,7 @@
 OPTFLAGS=-g2 -fsanitize=undefined -ftrapv -fsanitize=address -fno-omit-frame-pointer -fno-sanitize=alignment
 
 
-ALLFLAGS=-m64 ${OPTFLAGS} -pipe \
+ALLFLAGS=-m64 ${OPTFLAGS} -pipe -fPIE -pie \
 	-DDONT_REDEFINE_NEW \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
diff --git a/makefile.linux_cross_aarch64 b/makefile.linux_cross_aarch64
index e27b413..e0abea4 100644
--- a/makefile.linux_cross_aarch64
+++ b/makefile.linux_cross_aarch64
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_cross_arm b/makefile.linux_cross_arm
index 6d240f0..ba3a3ce 100644
--- a/makefile.linux_cross_arm
+++ b/makefile.linux_cross_arm
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_cross_m68k b/makefile.linux_cross_m68k
index 1ccaf5e..125f173 100644
--- a/makefile.linux_cross_m68k
+++ b/makefile.linux_cross_m68k
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_cross_mipsel b/makefile.linux_cross_mipsel
index 160140c..479092a 100644
--- a/makefile.linux_cross_mipsel
+++ b/makefile.linux_cross_mipsel
@@ -6,7 +6,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_cross_ppc b/makefile.linux_cross_ppc
index fe49895..ca94609 100644
--- a/makefile.linux_cross_ppc
+++ b/makefile.linux_cross_ppc
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_cross_ppc64 b/makefile.linux_cross_ppc64
index cc34337..f20a951 100644
--- a/makefile.linux_cross_ppc64
+++ b/makefile.linux_cross_ppc64
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_cross_ppc64le b/makefile.linux_cross_ppc64le
index bbe84dc..126886b 100644
--- a/makefile.linux_cross_ppc64le
+++ b/makefile.linux_cross_ppc64le
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_cross_s390x b/makefile.linux_cross_s390x
index fc067f8..3ccfb25 100644
--- a/makefile.linux_cross_s390x
+++ b/makefile.linux_cross_s390x
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_cross_sparc64 b/makefile.linux_cross_sparc64
index 981df5a..62f4f29 100644
--- a/makefile.linux_cross_sparc64
+++ b/makefile.linux_cross_sparc64
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_gcc6_sanitize b/makefile.linux_gcc6_sanitize
index 35f3066..efb5e55 100644
--- a/makefile.linux_gcc6_sanitize
+++ b/makefile.linux_gcc6_sanitize
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O3 -fsanitize=undefined -fsanitize=bounds-strict -Wshift-overflow=2  -fdelete-null-pointer-checks -Wnull-dereference -fsanitize=bounds-strict -fno-sanitize=alignment
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_gcc_2.95_no_need_for_libstdc b/makefile.linux_gcc_2.95_no_need_for_libstdc
index 8508f31..3a0e9a4 100644
--- a/makefile.linux_gcc_2.95_no_need_for_libstdc
+++ b/makefile.linux_gcc_2.95_no_need_for_libstdc
@@ -1,7 +1,7 @@
 
 OPTFLAGS=-O2 -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_other b/makefile.linux_other
index f28394a..e0f555b 100644
--- a/makefile.linux_other
+++ b/makefile.linux_other
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_s390x b/makefile.linux_s390x
index 3c9c2ec..0eb2a94 100644
--- a/makefile.linux_s390x
+++ b/makefile.linux_s390x
@@ -5,7 +5,7 @@
 
 OPTFLAGS=-O -m31 -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
 	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_scan-build b/makefile.linux_scan-build
index dd33ed0..4182a31 100644
--- a/makefile.linux_scan-build
+++ b/makefile.linux_scan-build
@@ -4,7 +4,7 @@
 
 #OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_valgrind b/makefile.linux_valgrind
index 7d9d0de..f007990 100644
--- a/makefile.linux_valgrind
+++ b/makefile.linux_valgrind
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-g1
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_x32 b/makefile.linux_x32
index e49b305..f6fdf2a 100644
--- a/makefile.linux_x32
+++ b/makefile.linux_x32
@@ -2,7 +2,7 @@
 OPTFLAGS=-O -s
 
 # use "-m32" to have a 32bits executable
-ALLFLAGS=-mx32 ${OPTFLAGS} -pipe \
+ALLFLAGS=-mx32 ${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_x86_asm_gcc_4.X b/makefile.linux_x86_asm_gcc_4.X
index 1ac339b..33353e4 100644
--- a/makefile.linux_x86_asm_gcc_4.X
+++ b/makefile.linux_x86_asm_gcc_4.X
@@ -5,7 +5,7 @@
 # OPTFLAGS=-mfpmath=sse -Ofast -flto -march=native -funroll-loops -s
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe -m32 \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie -m32 \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_x86_asm_gcc_4.X_fltk b/makefile.linux_x86_asm_gcc_4.X_fltk
index d5ef798..7c18144 100644
--- a/makefile.linux_x86_asm_gcc_4.X_fltk
+++ b/makefile.linux_x86_asm_gcc_4.X_fltk
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -m32 -pipe \
+ALLFLAGS=${OPTFLAGS} -m32 -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX -DUSE_FLTK \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.linux_x86_asm_gcc_mudflap_4.X b/makefile.linux_x86_asm_gcc_mudflap_4.X
index d372a4b..d83d399 100644
--- a/makefile.linux_x86_asm_gcc_mudflap_4.X
+++ b/makefile.linux_x86_asm_gcc_mudflap_4.X
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-g2
 
-ALLFLAGS=${OPTFLAGS} -m32 -pipe -pthread -fmudflapth \
+ALLFLAGS=${OPTFLAGS} -m32 -pipe -fPIE -pie -pthread -fmudflapth \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
diff --git a/makefile.machine b/makefile.machine
index 9e34c34..a1162b8 100644
--- a/makefile.machine
+++ b/makefile.machine
@@ -4,7 +4,7 @@
 
 OPTFLAGS=-O -s
 
-ALLFLAGS=${OPTFLAGS} -pipe \
+ALLFLAGS=${OPTFLAGS} -pipe -fPIE -pie \
     	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
 	-DNDEBUG -D_REENTRANT -DENV_UNIX \
 	-D_7ZIP_LARGE_PAGES \
-- 
2.33.0

