packaging: create a wrapper for collect2 in gcc-force-options 55/139255/6
authorSangmin Seo <sangmin7.seo@samsung.com>
Tue, 18 Jul 2017 05:01:23 +0000 (14:01 +0900)
committerSangmin Seo <sangmin7.seo@samsung.com>
Fri, 28 Jul 2017 00:26:10 +0000 (09:26 +0900)
gcc-force-options used to prepend/append all force options to the
gcc/g++ wrappers.  This approach worked well for most packages but
caused some configure scripts to behave differently when linker flags
are included in the force options.  For example, if g++ is called with
-ldl appended, it always goes to the linking phase.  As a result, when
configure has expanded AC_PROG_CXXCPP macro, variables related to
preprocessor are not properly set and actual build ends up using
incorrect compile and link flags.

Since prepending or appending linker flags to the linker makes more
sense than carrying them from the compilation phase, this patch
basically divides the force options into compiler flags and linker
ones, and inserts them to corresponding wrappers.  Consequently, a
wrapper for collect2 is created, as we did for gcc and g++, in order
to pass the linker flags to the linker.  Note that collect2 bridges
the compiler and the actual linker, and thus creating a wrapper for
collect2 is more portable and succinct than doing so for linkers.

Change-Id: I8733bf14c5a2c04bfebe38a339c94e7a738cf17c
Signed-off-by: Sangmin Seo <sangmin7.seo@samsung.com>
packaging/gcc-aarch64.spec
packaging/gcc-armv7l.spec
packaging/gcc-force-options
packaging/gcc-unforce-options
packaging/linaro-gcc.spec

index 89261f6..ef0e568 100644 (file)
@@ -656,7 +656,9 @@ Scripts for ASan instrumentation
 %post -n asan-force-options
 # Change mode to allow all users to run gcc-force/unforce-options
 chmod a+w /usr/bin
-[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a+w %{libsubdir}
+[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
 /usr/bin/gcc-force-options %asan_force_options -fno-common
 # Add ASan-related macros
 cat >> /usr/lib/rpm/tizen_macros << EOF
@@ -673,7 +675,9 @@ EOF
 %preun -n asan-force-options
 # Restore read-only mode
 chmod a-w /usr/bin
-[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a-w %{libsubdir}
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
 /usr/bin/gcc-unforce-options
 
 %package -n ubsan-force-options
@@ -688,7 +692,9 @@ Scripts for UBSan instrumentation
 %post -n ubsan-force-options
 # Change mode to allow all users to run gcc-force/unforce-options
 chmod a+w /usr/bin
-[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a+w %{libsubdir}
+[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
 /usr/bin/gcc-force-options %ubsan_force_options
 # Add UBSan-related macros
 cat >> /usr/lib/rpm/tizen_macros << EOF
@@ -702,7 +708,9 @@ EOF
 %preun -n ubsan-force-options
 # Restore read-only mode
 chmod a-w /usr/bin
-[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a-w %{libsubdir}
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
 /usr/bin/gcc-unforce-options
 
 %package -n ubsan-build-env
@@ -729,7 +737,9 @@ Scripts for LSan instrumentation
 %post -n lsan-force-options
 # Change mode to allow all users to run gcc-force/unforce-options
 chmod a+w /usr/bin
-[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a+w %{libsubdir}
+[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
 /usr/bin/gcc-force-options %lsan_force_options
 # Add LSan-related macros
 cat >> /usr/lib/rpm/tizen_macros << EOF
@@ -743,7 +753,9 @@ EOF
 %preun -n lsan-force-options
 # Restore read-only mode
 chmod a-w /usr/bin
-[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a-w %{libsubdir}
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
 /usr/bin/gcc-unforce-options
 [ -d /emul/ ] && chmod a-w /emul/usr/bin/
 
index 9c163e1..878d527 100644 (file)
@@ -656,7 +656,9 @@ Scripts for ASan instrumentation
 %post -n asan-force-options
 # Change mode to allow all users to run gcc-force/unforce-options
 chmod a+w /usr/bin
-[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a+w %{libsubdir}
+[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
 /usr/bin/gcc-force-options %asan_force_options -fno-common
 # Add ASan-related macros
 cat >> /usr/lib/rpm/tizen_macros << EOF
@@ -673,7 +675,9 @@ EOF
 %preun -n asan-force-options
 # Restore read-only mode
 chmod a-w /usr/bin
-[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a-w %{libsubdir}
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
 /usr/bin/gcc-unforce-options
 
 %package -n ubsan-force-options
@@ -688,7 +692,9 @@ Scripts for UBSan instrumentation
 %post -n ubsan-force-options
 # Change mode to allow all users to run gcc-force/unforce-options
 chmod a+w /usr/bin
-[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a+w %{libsubdir}
+[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
 /usr/bin/gcc-force-options %ubsan_force_options
 # Add UBSan-related macros
 cat >> /usr/lib/rpm/tizen_macros << EOF
@@ -702,7 +708,9 @@ EOF
 %preun -n ubsan-force-options
 # Restore read-only mode
 chmod a-w /usr/bin
-[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a-w %{libsubdir}
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
 /usr/bin/gcc-unforce-options
 
 %package -n ubsan-build-env
@@ -729,7 +737,9 @@ Scripts for LSan instrumentation
 %post -n lsan-force-options
 # Change mode to allow all users to run gcc-force/unforce-options
 chmod a+w /usr/bin
-[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a+w %{libsubdir}
+[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
 /usr/bin/gcc-force-options %lsan_force_options
 # Add LSan-related macros
 cat >> /usr/lib/rpm/tizen_macros << EOF
@@ -743,7 +753,9 @@ EOF
 %preun -n lsan-force-options
 # Restore read-only mode
 chmod a-w /usr/bin
-[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a-w %{libsubdir}
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
 /usr/bin/gcc-unforce-options
 [ -d /emul/ ] && chmod a-w /emul/usr/bin/
 
index 34f4945..0dfdd9a 100644 (file)
@@ -14,27 +14,64 @@ EOF
        exit 1
 fi
 
-FLAGS="$@"
-
 if [ $(find $(dirname $0) -name \*-real | wc -l) -gt 0 ]; then
        echo >&2 "$(basename $0): directory was already processed, aborting"
        exit 1
 fi
 
+FLAGS=""
+LD_FLAGS=""
+
+function divide_flags {
+       NEED_LIB_NAME="N"
+       for f in "$@"; do
+               case $f in
+               -l)
+                       NEED_LIB_NAME="Y"
+                       ;;
+
+               -l*)
+                       LDFLAGS="$LDFLAGS $f"
+                       ;;
+
+               -Wl,*)
+                       LDFLAGS="$LDFLAGS ${f:4}"
+                       ;;
+
+               *)
+                       if [ "$NEED_LIB_NAME" = "Y" ]; then
+                               LDFLAGS="$LDFLAGS -l$f"
+                               NEED_LIB_NAME="N"
+                       else
+                               FLAGS="$FLAGS $f"
+                       fi
+               esac
+       done
+}
+
 case "$1" in
 prepend)
        shift
-       PREFLAGS="$@"
+       divide_flags $@
+       PREFLAGS=$FLAGS
        POSTFLAGS=
+       LD_PREFLAGS=$LDFLAGS
+       LD_POSTFLAGS=
        ;;
 append)
        shift
+       divide_flags $@
        PREFLAGS=
-       POSTFLAGS="$@"
+       POSTFLAGS=$FLAGS
+       LD_PREFLAGS=
+       LD_POSTFLAGS=$LDFLAGS
        ;;
 *)
+       divide_flags $@
        PREFLAGS=
-       POSTFLAGS="$@"
+       POSTFLAGS=$FLAGS
+       LD_PREFLAGS=
+       LD_POSTFLAGS=$LDFLAGS
        ;;
 esac
 
@@ -50,7 +87,9 @@ elif ! echo "\$@" | grep -q -e __KERNEL__ -e \-nostdlib; then
        # Use readlink in order to follow symlinks if any
        \$(readlink -f \$0)-real $PREFLAGS "\$@" $POSTFLAGS
 else
-       \$(readlink -f \$0)-real "\$@"
+       # -Wl,--tizen-no-force-options is used to tell collect2 to not add force
+       # options.  It will be removed in collect2.
+       \$(readlink -f \$0)-real "\$@" -Wl,--tizen-no-force-options
 fi
 EOF
 chmod +x $TMP
@@ -60,11 +99,31 @@ find -L $(dirname $0) -type f -a -perm -a=x | grep -E '(gcc|g\+\+|c\+\+)$' | whi
        cp $TMP $tool
 done
 
+LD_TMP=$(pwd)/ld_tmp.$$
+cat > $LD_TMP << EOF
+#!/bin/sh
+if ! echo "\$@" | grep -q -e \-\-tizen\-no\-force\-options; then
+       # Use readlink in order to follow symlinks if any
+       \$(readlink -f \$0)-real $LD_PREFLAGS "\$@" $LD_POSTFLAGS
+else
+       # Remove --tizen-no-force-options from the argument list
+       FLAGS=\$(echo \$@ | sed -e 's/--tizen-no-force-options//g')
+       \$(readlink -f \$0)-real \$FLAGS
+fi
+EOF
+chmod +x $LD_TMP
+
+find -L /usr/*/gcc -type f -a -perm -a=x -name 'collect2' | while read tool; do
+       mv $tool $tool-real
+       cp $LD_TMP $tool
+done
+
 if [ -d /emul ]; then
-       find -L /emul -type f -a -perm -a=x | grep -E '(gcc|g\+\+|c\+\+)$' | while read tool; do
+       find -L /emul -type f -a -perm -a=x | grep -E '(gcc|g\+\+|c\+\+|collect2)$' | while read tool; do
                ln -sf $(basename $tool) $tool-real
        done
 fi
 
 rm $TMP
+rm $LD_TMP
 
index cf36d04..7e85b75 100644 (file)
@@ -7,7 +7,7 @@ if [ $# -gt 0 ]; then
        exit 1
 fi
 
-find $(dirname $0) -name \*-real | while read tool_real; do
+find $(dirname $0) /usr/*/gcc -name \*-real | while read tool_real; do
        tool=$(echo "$tool_real" | sed -e 's/-real$//')
        mv $tool_real $tool
 done
index 49d2499..5058a99 100644 (file)
@@ -653,7 +653,9 @@ Scripts for ASan instrumentation
 %post -n asan-force-options
 # Change mode to allow all users to run gcc-force/unforce-options
 chmod a+w /usr/bin
-[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a+w %{libsubdir}
+[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
 /usr/bin/gcc-force-options %asan_force_options -fno-common
 # Add ASan-related macros
 cat >> /usr/lib/rpm/tizen_macros << EOF
@@ -670,7 +672,9 @@ EOF
 %preun -n asan-force-options
 # Restore read-only mode
 chmod a-w /usr/bin
-[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a-w %{libsubdir}
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
 /usr/bin/gcc-unforce-options
 
 %package -n ubsan-force-options
@@ -685,7 +689,9 @@ Scripts for UBSan instrumentation
 %post -n ubsan-force-options
 # Change mode to allow all users to run gcc-force/unforce-options
 chmod a+w /usr/bin
-[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a+w %{libsubdir}
+[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
 /usr/bin/gcc-force-options %ubsan_force_options
 # Add UBSan-related macros
 cat >> /usr/lib/rpm/tizen_macros << EOF
@@ -699,7 +705,9 @@ EOF
 %preun -n ubsan-force-options
 # Restore read-only mode
 chmod a-w /usr/bin
-[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a-w %{libsubdir}
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
 /usr/bin/gcc-unforce-options
 
 %package -n ubsan-build-env
@@ -726,7 +734,9 @@ Scripts for LSan instrumentation
 %post -n lsan-force-options
 # Change mode to allow all users to run gcc-force/unforce-options
 chmod a+w /usr/bin
-[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a+w %{libsubdir}
+[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
 /usr/bin/gcc-force-options %lsan_force_options
 # Add LSan-related macros
 cat >> /usr/lib/rpm/tizen_macros << EOF
@@ -740,7 +750,9 @@ EOF
 %preun -n lsan-force-options
 # Restore read-only mode
 chmod a-w /usr/bin
-[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/
+chmod a-w %{libsubdir}
+[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \
+              && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
 /usr/bin/gcc-unforce-options
 [ -d /emul/ ] && chmod a-w /emul/usr/bin/