06-gcc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. # Build script for gcc.
  2. #
  3. # Copyright (c) 2016-2021 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=10-20210206
  17. # Prerequisites
  18. gmp_version=6.2.1
  19. mpfr_version=4.1.0
  20. mpc_version=1.2.1
  21. isl_version=0.23
  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. # http://port70.net/~nsz/musl/gcc-10.1.0/
  34. patch -Np1 -i "${worktree}/patches/gcc/10/0002-posix_memalign.patch"
  35. patch -Np1 -i "${worktree}/patches/gcc/10/0003-j2.patch"
  36. patch -Np1 -i "${worktree}/patches/gcc/10/0004-static-pie.patch"
  37. # Apply extra patches to increment the security
  38. patch -Np1 -i "${worktree}/patches/gcc/10/extra-relro-in-dragora.patch"
  39. patch -Np1 -i "${worktree}/patches/gcc/10/extra-musl_libssp.patch"
  40. # Apply patches from "Alpine Linux" in order to improve the security (Thanks!)
  41. patch -Np1 -i "${worktree}/patches/gcc/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch"
  42. patch -Np1 -i "${worktree}/patches/gcc/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch"
  43. patch -Np1 -i "${worktree}/patches/gcc/0006-Enable-Wformat-and-Wformat-security-by-default.patch"
  44. patch -Np1 -i "${worktree}/patches/gcc/0007-Enable-Wtrampolines-by-default.patch"
  45. patch -Np1 -i "${worktree}/patches/gcc/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch"
  46. patch -Np1 -i "${worktree}/patches/gcc/0020-add-fortify-headers-paths.patch"
  47. patch -Np1 -i "${worktree}/patches/gcc/0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch"
  48. # Hard code default ld path to look at /tools
  49. find . -type f -name '*.h' -exec grep -l "/lib/ld-" {} + | while read -r file
  50. do
  51. test -f "$file" || continue;
  52. cp -f "$file" "${file}.orig"
  53. sed -e 's@/lib\(64\)\{0,1\}\(32\)\{0,1\}/ld@/tools&@g' \
  54. -e 's@/usr@/tools@g' "${file}.orig" > "$file"
  55. echo '
  56. #undef STANDARD_STARTFILE_PREFIX_1
  57. #undef STANDARD_STARTFILE_PREFIX_2
  58. #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
  59. #define STANDARD_STARTFILE_PREFIX_2 ""' >> "$file"
  60. done
  61. # Make symlinks for requisites
  62. ln -s ../gmp-${gmp_version} gmp
  63. ln -s ../mpfr-${mpfr_version} mpfr
  64. ln -s ../mpc-${mpc_version} mpc
  65. ln -s ../isl-${isl_version} isl
  66. # Apply patches for MPFR
  67. (
  68. cd mpfr || exit 1
  69. for file in "${worktree}"/patches/mpfr/*
  70. do
  71. if test -f "$file"
  72. then
  73. rm -f PATCHES
  74. patch -p1 < "$file"
  75. fi
  76. done
  77. )
  78. # Update detection for hosts based on musl
  79. cp -f "${worktree}/archive/common/config.guess" gmp/configfsf.guess
  80. cp -f "${worktree}/archive/common/config.sub" gmp/config.sub
  81. cp -f "${worktree}/archive/common/config.guess" isl/config.guess
  82. cp -f "${worktree}/archive/common/config.sub" isl/config.sub
  83. # Build in a separate directory
  84. rm -rf ../gcc-build
  85. mkdir ../gcc-build
  86. cd ../gcc-build
  87. # Import and export toolchain variables
  88. . "${worktree}/stages/env.d/cross-staticenv"
  89. ../gcc-${version}/configure \
  90. AR="$AR" AS="$AS" LD="$LD" RANLIB="$RANLIB" READELF="$READELF" STRIP="$STRIP" \
  91. CC="$BTCC" CXX="$BTCXX" \
  92. CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
  93. --prefix=/tools \
  94. --libdir=/tools/lib${libSuffix} \
  95. --build=$host \
  96. --host=$target \
  97. --target=$target \
  98. --enable-languages=c,c++ \
  99. --enable-clocale=generic \
  100. --enable-cet=auto \
  101. --enable-initfini-array \
  102. --enable-tls \
  103. --enable-libstdcxx-time \
  104. --enable-fully-dynamic-string \
  105. --enable-default-ssp \
  106. --enable-default-pie \
  107. --enable-libssp \
  108. --disable-symvers \
  109. --disable-bootstrap \
  110. --disable-libstdcxx-pch \
  111. --disable-gnu-indirect-function \
  112. --disable-libmudflap \
  113. --disable-libsanitizer \
  114. --disable-nls \
  115. --disable-install-libiberty \
  116. --with-linker-hash-style=gnu \
  117. --with-local-prefix=/tools \
  118. --with-native-system-header-dir=/tools/include \
  119. $multilib_options \
  120. $gcc_options
  121. make -j${jobs} all \
  122. AS_FOR_TARGET="$AS" \
  123. LD_FOR_TARGET="$LD"
  124. make -j${jobs} install
  125. # Provide minimal libssp_nonshared.a
  126. $BTCC -c "${worktree}/archive/gcc/__stack_chk_fail_local.c" \
  127. -o __stack_chk_fail_local.o
  128. $AR rc libssp_nonshared.a __stack_chk_fail_local.o
  129. $RANLIB libssp_nonshared.a
  130. cp -p libssp_nonshared.a /tools/lib${libSuffix}
  131. # Unset some imported variables from file
  132. unset AR AS LD RANLIB READELF STRIP
  133. cd -- "$TMPDIR"
  134. cleanup()
  135. {
  136. rm -rf gcc-${version} gcc-build \
  137. gmp-${gmp_version} mpfr-${mpfr_version} \
  138. mpc-${mpc_version} isl-${isl_version}
  139. }