06-gcc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. # Build script for gcc.
  2. #
  3. # Copyright (c) 2016-2022 Matias Fonzo, <selk@dragora.org>.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. version=11-20220429
  17. # Prerequisites
  18. gmp_version=6.2.1
  19. mpfr_version=4.1.0
  20. mpc_version=1.2.1
  21. isl_version=0.24
  22. cd -- "$TMPDIR"
  23. rm -rf gcc-${version} gmp-${gmp_version} \
  24. mpfr-${mpfr_version} mpc-${mpc_version} isl-${isl_version}
  25. unpack "${worktree}/sources/gcc-${version}.tar.xz" \
  26. "${worktree}/sources/gmp-${gmp_version}.tar.lz" \
  27. "${worktree}/sources/mpfr-${mpfr_version}.tar.bz2" \
  28. "${worktree}/sources/mpc-${mpc_version}.tar.gz" \
  29. "${worktree}/sources/isl-${isl_version}.tar.bz2"
  30. # Build instructions
  31. cd gcc-${version}
  32. # Apply specific patches for the support in musl.
  33. # https://port70.net/~nsz/musl/gcc-11.1.0/
  34. patch -Np1 -i "${worktree}/patches/gcc/11/0002-posix_memalign.patch"
  35. patch -Np1 -i "${worktree}/patches/gcc/11/0003-j2.patch"
  36. patch -Np1 -i "${worktree}/patches/gcc/11/0004-static-pie.patch"
  37. patch -Np1 -i "${worktree}/patches/gcc/11/0005-m68k-sqrt.patch"
  38. patch -Np1 -i "${worktree}/patches/gcc/11/extra-musl_libssp.patch"
  39. # Apply patches from "Alpine Linux" in order to improve the security (Thanks!)
  40. echo "patch1:"
  41. patch -Np1 -i "${worktree}/patches/gcc/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch"
  42. echo "patch2:"
  43. patch -Np1 -i "${worktree}/patches/gcc/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch"
  44. echo "patch3:"
  45. patch -Np1 -i "${worktree}/patches/gcc/0006-Enable-Wformat-and-Wformat-security-by-default.patch"
  46. echo "patch4:"
  47. patch -Np1 -i "${worktree}/patches/gcc/0007-Enable-Wtrampolines-by-default.patch"
  48. echo "patch5:"
  49. patch -Np1 -i "${worktree}/patches/gcc/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch"
  50. echo "patch6:"
  51. patch -Np1 -i "${worktree}/patches/gcc/0021-add-fortify-headers-paths.patch"
  52. # Hard code default ld path to look at /tools
  53. find . -type f -name '*.h' -exec grep -l "/lib/ld-" {} + | while read -r file
  54. do
  55. test -f "$file" || continue;
  56. cp -f "$file" "${file}.orig"
  57. sed -e 's@/lib\(64\)\{0,1\}\(32\)\{0,1\}/ld@/tools&@g' \
  58. -e 's@/usr@/tools@g' "${file}.orig" > "$file"
  59. echo '
  60. #undef STANDARD_STARTFILE_PREFIX_1
  61. #undef STANDARD_STARTFILE_PREFIX_2
  62. #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
  63. #define STANDARD_STARTFILE_PREFIX_2 ""' >> "$file"
  64. done
  65. # Make symlinks for requisites
  66. ln -s ../gmp-${gmp_version} gmp
  67. ln -s ../mpfr-${mpfr_version} mpfr
  68. ln -s ../mpc-${mpc_version} mpc
  69. ln -s ../isl-${isl_version} isl
  70. # Apply patches for MPFR
  71. (
  72. cd mpfr || exit 1
  73. for file in "${worktree}"/patches/mpfr/*
  74. do
  75. if test -f "$file"
  76. then
  77. rm -f PATCHES
  78. patch -p1 < "$file"
  79. fi
  80. done
  81. )
  82. # Update detection for hosts based on musl
  83. cp -f "${worktree}/archive/common/config.guess" gmp/configfsf.guess
  84. cp -f "${worktree}/archive/common/config.sub" gmp/config.sub
  85. cp -f "${worktree}/archive/common/config.guess" isl/config.guess
  86. cp -f "${worktree}/archive/common/config.sub" isl/config.sub
  87. # Build in a separate directory
  88. rm -rf ../gcc-build
  89. mkdir ../gcc-build
  90. cd ../gcc-build
  91. # Import and export toolchain variables
  92. . "${worktree}/stages/env.d/cross-staticenv"
  93. ../gcc-${version}/configure \
  94. AR="$AR" AS="$AS" LD="$LD" RANLIB="$RANLIB" READELF="$READELF" STRIP="$STRIP" \
  95. CC="$BTCC" CXX="$BTCXX" \
  96. CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
  97. --prefix=/tools \
  98. --libdir=/tools/lib${libSuffix} \
  99. --build=$host \
  100. --host=$target \
  101. --target=$target \
  102. --enable-languages=c,c++ \
  103. --enable-clocale=generic \
  104. --enable-cet=auto \
  105. --enable-initfini-array \
  106. --enable-tls \
  107. --enable-libstdcxx-time \
  108. --enable-fully-dynamic-string \
  109. --enable-default-ssp \
  110. --enable-default-pie \
  111. --enable-libssp \
  112. --disable-symvers \
  113. --disable-bootstrap \
  114. --disable-libstdcxx-pch \
  115. --disable-gnu-indirect-function \
  116. --disable-libsanitizer \
  117. --disable-nls \
  118. --disable-install-libiberty \
  119. --with-linker-hash-style=gnu \
  120. --with-local-prefix=/tools \
  121. --with-native-system-header-dir=/tools/include \
  122. $multilib_options \
  123. $gcc_options
  124. make -j${jobs} all \
  125. AS_FOR_TARGET="$AS" \
  126. LD_FOR_TARGET="$LD"
  127. make -j${jobs} install
  128. # Provide minimal libssp_nonshared.a
  129. $BTCC -c "${worktree}/archive/gcc/__stack_chk_fail_local.c" \
  130. -o __stack_chk_fail_local.o
  131. $AR rc libssp_nonshared.a __stack_chk_fail_local.o
  132. $RANLIB libssp_nonshared.a
  133. cp -p libssp_nonshared.a /tools/lib${libSuffix}
  134. # Unset some imported variables from file
  135. unset AR AS LD RANLIB READELF STRIP
  136. cd -- "$TMPDIR"
  137. cleanup()
  138. {
  139. rm -rf gcc-${version} gcc-build \
  140. gmp-${gmp_version} mpfr-${mpfr_version} \
  141. mpc-${mpc_version} isl-${isl_version}
  142. }