Kbuild, lto: Add a gcc-ld script to let run gcc as ld
authorAndi Kleen <ak@linux.intel.com>
Sat, 8 Feb 2014 08:01:14 +0000 (09:01 +0100)
committerH. Peter Anvin <hpa@linux.intel.com>
Fri, 14 Feb 2014 04:25:02 +0000 (20:25 -0800)
For LTO we need to run the link step with gcc, not ld.
Since there are a lot of linker options passed to it, add a gcc-ld wrapper
that wraps them as -Wl,

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1391846481-31491-10-git-send-email-ak@linux.intel.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
scripts/gcc-ld [new file with mode: 0644]

diff --git a/scripts/gcc-ld b/scripts/gcc-ld
new file mode 100644 (file)
index 0000000..cadab9a
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+# run gcc with ld options
+# used as a wrapper to execute link time optimizations
+# yes virginia, this is not pretty
+
+ARGS="-nostdlib"
+
+while [ "$1" != "" ] ; do
+       case "$1" in
+       -save-temps|-m32|-m64) N="$1" ;;
+       -r) N="$1" ;;
+       -[Wg]*) N="$1" ;;
+       -[olv]|-[Ofd]*|-nostdlib) N="$1" ;;
+       --end-group|--start-group)
+                N="-Wl,$1" ;;
+       -[RTFGhIezcbyYu]*|\
+--script|--defsym|-init|-Map|--oformat|-rpath|\
+-rpath-link|--sort-section|--section-start|-Tbss|-Tdata|-Ttext|\
+--version-script|--dynamic-list|--version-exports-symbol|--wrap|-m)
+               A="$1" ; shift ; N="-Wl,$A,$1" ;;
+       -[m]*) N="$1" ;;
+       -*) N="-Wl,$1" ;;
+       *)  N="$1" ;;
+       esac
+       ARGS="$ARGS $N"
+       shift
+done
+
+exec $CC $ARGS