From 195664b642319fd2a0a3854cc2b24a853a2e2255 Mon Sep 17 00:00:00 2001 From: dingguangya Date: Mon, 19 Dec 2022 23:26:42 +0800 Subject: [PATCH] [gcc-cross] Fix unsafe compile option PIE STRIP RPATH --- gcc-cross.spec | 8 ++++++- gcc_arm32le/build.sh | 4 ++-- gcc_arm32le/gcc_arm_linux_release.sh | 29 ++++++++++++++++++++++++ gcc_arm64le/build.sh | 4 ++-- gcc_arm64le/gcc_aarch64_linux_release.sh | 29 ++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 5 deletions(-) diff --git a/gcc-cross.spec b/gcc-cross.spec index 9dd6bd4..829e580 100644 --- a/gcc-cross.spec +++ b/gcc-cross.spec @@ -1,7 +1,7 @@ Summary: C/C++ Cross Compiler Toolchain Name: gcc-cross Version: 1.0 -Release: 3 +Release: 4 # libgcc, libgfortran, libmudflap, libgomp, libstdc++ and crtstuff have # GCC Runtime Exception. License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD @@ -42,6 +42,12 @@ cp %{_builddir}/output/gcc_arm32le/gcc_arm32le.tar.gz %{buildroot}/tmp %attr(755, root, root) /tmp/gcc_arm32le.tar.gz %changelog +* Mon Dec 19 2022 dingguangya - 1.0-4 +-Type:Fix +-ID:NA +-SUG:NA +-DESC: Fix unsafe compile option PIE STRIP RPATH + * Mon Nov 28 2022 dingguangya - 1.0-3 -Type:Fix -ID:NA diff --git a/gcc_arm32le/build.sh b/gcc_arm32le/build.sh index f3fccdb..8f79f25 100755 --- a/gcc_arm32le/build.sh +++ b/gcc_arm32le/build.sh @@ -13,11 +13,11 @@ fi [ -e "$LOG_PATH/gcc_arm32le_build.log" ] && rm $LOG_PATH/gcc_arm32le_build.log mkdir -p $LOG_PATH -source pre_construction.sh &>> $LOG_PATH/gcc_arm32le_patch.log +source pre_construction.sh 2>&1 | tee $LOG_PATH/gcc_arm32le_patch.log echo "------------------------------------------" echo "Now building the "gcc_arm32le" toolchain ..." echo "The entire build process takes about 45 minutes (build time is related to machine preformance), you can view the detailed build log in the ${LOG_PATH} file" source gcc_update_sourcecode.sh -source gcc_arm_linux_release.sh &>> $LOG_PATH/gcc_arm32le_build.log +source gcc_arm_linux_release.sh 2>&1 | tee $LOG_PATH/gcc_arm32le_build.log echo "Build gcc_arm32le toolchain completed!" diff --git a/gcc_arm32le/gcc_arm_linux_release.sh b/gcc_arm32le/gcc_arm_linux_release.sh index bec4da3..c474127 100755 --- a/gcc_arm32le/gcc_arm_linux_release.sh +++ b/gcc_arm32le/gcc_arm_linux_release.sh @@ -1,6 +1,7 @@ #!/bin/bash set -e +set -x # Target root directory,should be adapted according to your environment readonly ROOT_TAR_DIR="$PWD/arm32le_build_dir" @@ -94,6 +95,34 @@ for file in $(find "$PREFIX" -name "lib*so*.0") ; do chrpath --delete $file done +for file in $(find "$PREFIX/sysroot/usr/lib/gconv" -name "*so") ; do + chrpath --delete $file +done + +for file in $(find "$PREFIX" -name "*") ; do + if [ -f "$file" ] + then + result=$(file $file) + res=$(echo $result | grep "ELF" | cat) + if [[ "$res" != "" ]] + then + get_arch=`arch` + if [[ $get_arch =~ "x86_64" ]] + then + res1=$(echo $result | grep "ARM" | cat) + if [[ "$res1" != "" ]] + then + $PREFIX/bin/$TARGET-strip $file + else + strip $file + fi + else + strip $file + fi + fi + fi +done + pushd $PREFIX/.. && chmod 750 $INSTALL -R tar --format=gnu -czf $OUTPUT/$INSTALL.tar.gz $INSTALL && popd diff --git a/gcc_arm64le/build.sh b/gcc_arm64le/build.sh index 433ec01..88c575d 100755 --- a/gcc_arm64le/build.sh +++ b/gcc_arm64le/build.sh @@ -11,11 +11,11 @@ source $PWD/../config.xml [ -e "$LOG_PATH/gcc_arm64le_build.log" ] && rm $LOG_PATH/gcc_arm64le_build.log mkdir -p $LOG_PATH -source pre_construction.sh &>> $LOG_PATH/gcc_arm64le_patch.log +source pre_construction.sh 2>&1 | tee $LOG_PATH/gcc_arm64le_patch.log echo "------------------------------------------" echo "Now building the "gcc_arm64le" toolchain ..." echo "The entire build process takes about 45 minutes (build time is related to machine preformance), you can view the detailed build log in the ${LOG_PATH} file" source gcc_update_sourcecode.sh -source gcc_aarch64_linux_release.sh &>> $LOG_PATH/gcc_arm64le_build.log +source gcc_aarch64_linux_release.sh 2>&1 | tee $LOG_PATH/gcc_arm64le_build.log echo "Build gcc_arm64le toolchain completed!" diff --git a/gcc_arm64le/gcc_aarch64_linux_release.sh b/gcc_arm64le/gcc_aarch64_linux_release.sh index 3a0f9e3..59561c9 100755 --- a/gcc_arm64le/gcc_aarch64_linux_release.sh +++ b/gcc_arm64le/gcc_aarch64_linux_release.sh @@ -1,6 +1,7 @@ #!/bin/bash set -e +set -x # Target root directory,should be adapted according to your environment readonly ROOT_TAR_DIR="$PWD/arm64le_build_dir" @@ -96,6 +97,34 @@ for file in $(find "$PREFIX" -name "lib*so*.0") ; do chrpath --delete $file done +for file in $(find "$PREFIX/sysroot/usr/lib64/gconv" -name "*so") ; do + chrpath --delete $file +done + +for file in $(find "$PREFIX" -name "*") ; do + if [ -f "$file" ] + then + result=$(file $file) + res=$(echo $result | grep "ELF" | cat) + if [[ "$res" != "" ]] + then + get_arch=`arch` + if [[ $get_arch =~ "x86_64" ]] + then + res1=$(echo $result | grep "ARM" | cat) + if [[ "$res1" != "" ]] + then + $PREFIX/bin/$TARGET-strip $file + else + strip $file + fi + else + strip $file + fi + fi + fi +done + pushd $PREFIX/.. && chmod 750 $INSTALL -R tar --format=gnu -czf $OUTPUT/$INSTALL.tar.gz $INSTALL && popd -- Gitee