summaryrefslogtreecommitdiffstats
path: root/scripts/wrapper
diff options
context:
space:
mode:
authorJan Luebbe <jlu@pengutronix.de>2012-10-18 15:14:21 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2012-10-25 00:27:22 +0200
commit1e7dd9c2f9c708060786d1f9ffc7caac8b270887 (patch)
tree777ffd57020d6ab5b54e059081bf72228e0adf26 /scripts/wrapper
parent0c9cb9718a5fabf8ae98e3dfd1c1fefdd6a367b5 (diff)
downloadptxdist-1e7dd9c2f9c708060786d1f9ffc7caac8b270887.tar.gz
ptxdist-1e7dd9c2f9c708060786d1f9ffc7caac8b270887.tar.xz
wrapper: introduce a wrapper for cc, c++ and ld
This is used to optionally pass compiler and linker options (such as for hardening). Signed-off-by: Jan Luebbe <jlu@pengutronix.de> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'scripts/wrapper')
-rwxr-xr-xscripts/wrapper/c++-wrapper3
-rwxr-xr-xscripts/wrapper/cc-wrapper50
-rwxr-xr-xscripts/wrapper/ld-wrapper19
3 files changed, 72 insertions, 0 deletions
diff --git a/scripts/wrapper/c++-wrapper b/scripts/wrapper/c++-wrapper
new file mode 100755
index 000000000..ad97e9a28
--- /dev/null
+++ b/scripts/wrapper/c++-wrapper
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec $0.real "$@"
diff --git a/scripts/wrapper/cc-wrapper b/scripts/wrapper/cc-wrapper
new file mode 100755
index 000000000..8f16b75d5
--- /dev/null
+++ b/scripts/wrapper/cc-wrapper
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+. ${PTXDIST_PLATFORMCONFIG}
+
+LINKING=1
+FORTIFY=1
+STDLIB=1
+
+for ARG in "$@"; do
+ if [[ "${ARG}" = "-c" ]]; then
+ LINKING=0
+ fi
+ if [[ "${ARG}" =~ -D_FORTIFY_SOURCE(=|$) ]]; then
+ FORTIFY=0
+ fi
+ if [[ "${ARG}" = "-nostdlib" ||
+ "${ARG}" = "-ffreestanding" ]]; then
+ STDLIB=0
+ fi
+done
+
+ARG_LIST=""
+
+if [[ "${LINKING}" = 1 ]]; then
+ if [[ "${PTXCONF_TARGET_HARDEN_RELRO}" = "y" ]]; then
+ ARG_LIST+="-Wl,-z,relro "
+ fi
+ if [[ "${PTXCONF_TARGET_HARDEN_BINDNOW}" = "y" ]]; then
+ ARG_LIST+="-Wl,-z,now "
+ fi
+ if [[ "${PTXCONF_TARGET_LINKER_GNUHASH}" = "y" ]]; then
+ ARG_LIST+="-Wl,--hash-style=gnu "
+ fi
+fi
+
+if [[ "${FORTIFY}" = 1 ]]; then
+ if [[ "${PTXCONF_TARGET_HARDEN_FORTIFY}" = "y" ]]; then
+ ARG_LIST+="-D_FORTIFY_SOURCE=2 "
+ fi
+fi
+
+if [[ "${STDLIB}" = 1 ]]; then
+ if [[ "${PTXCONF_TARGET_HARDEN_STACK}" = "y" ]]; then
+ ARG_LIST+="-fstack-protector --param=ssp-buffer-size=4 "
+ fi
+fi
+
+#echo $0 $ARG_LIST "$@" >&2
+
+exec $0.real $ARG_LIST "$@"
diff --git a/scripts/wrapper/ld-wrapper b/scripts/wrapper/ld-wrapper
new file mode 100755
index 000000000..f3f38054c
--- /dev/null
+++ b/scripts/wrapper/ld-wrapper
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+. ${PTXDIST_PLATFORMCONFIG}
+
+ARG_LIST=""
+
+if [ "${PTXCONF_TARGET_HARDEN_RELRO}" = "y" ]; then
+ ARG_LIST+="-z relro "
+fi
+if [ "${PTXCONF_TARGET_HARDEN_BINDNOW}" = "y" ]; then
+ ARG_LIST+="-z now "
+fi
+if [[ "${PTXCONF_TARGET_LINKER_GNUHASH}" = "y" ]]; then
+ ARG_LIST+="--hash-style=gnu "
+fi
+
+#echo $0 $ARG_LIST "$@" >&2
+
+exec $0.real $ARG_LIST "$@"