Skip to content

Commit 636a653

Browse files
committed
scripts/bootstrap-prefix: use GCC-5 on all Darwin bootstraps
With recent macOS we need GCC-14 in order to make sense of system headers. However, GCC-14 gets confused by (older) Clang installed on the host system. So we need GCC-5 to get us a C11/C++11 compiler that can compile GCC-14 to do the real work. Unfortunately for GCC-5 to work properly on systems that do not have /usr/{include,lib} we need wrappers such as we use in Gentoo Prefix proper, thus part of that needs to be pulled and put in place too in order to get correctly compiled and running binaries. This change succeeds bootstrap on Darwin 17, 19 and 20, 21 and 22 pending. Signed-off-by: Fabian Groffen <[email protected]>
1 parent d718d0e commit 636a653

File tree

1 file changed

+122
-50
lines changed

1 file changed

+122
-50
lines changed

scripts/bootstrap-prefix.sh

+122-50
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,10 @@ bootstrap_profile() {
391391
profile="prefix/darwin/macos/10.$((rev - 4))/x64"
392392
;;
393393
*64-apple-darwin2[0123456789])
394-
# Big Sur is 11.0
394+
# Big Sur is 11.0
395395
# Monterey is 12.0
396-
# Ventura is 13.0
396+
# Ventura is 13.0
397+
# Sanoma is 14.0
397398
rev=${CHOST##*darwin}
398399
case ${CHOST%%-*} in
399400
x86_64) arch=x64 ;;
@@ -453,44 +454,6 @@ bootstrap_profile() {
453454
;;
454455
esac
455456

456-
if [[ ${CHOST} == *-darwin* ]] ; then
457-
# setup MacOSX.sdk symlink for GCC, this should probably be
458-
# managed using an eselect module in the future
459-
# FWIW, just use system (/) if it seems OK, for some reason
460-
# early versions of TAPI-based SDKs did not include some symbols
461-
# like fclose, which ld64 is able to resolve from the dylibs
462-
# although they are unvisible using e.g. nm.
463-
rm -f "${ROOT}"/MacOSX.sdk
464-
local SDKPATH
465-
if [[ -e /usr/lib/libSystem.B.dylib && -d /usr/include ]] ; then
466-
SDKPATH=/
467-
else
468-
SDKPATH=$(xcrun --show-sdk-path --sdk macosx)
469-
if [[ -L ${SDKPATH} ]] ; then
470-
local fsdk
471-
local osvers
472-
# try and find a matching OS SDK
473-
fsdk="$(readlink -f "${SDKPATH}")"
474-
osvers="$(sw_vers -productVersion)"
475-
if [[ ${osvers%%.*} -le 10 ]] ; then
476-
osvers=$(echo "${osvers}" | cut -d'.' -f1-2)
477-
else
478-
osvers=${osvers%%.*}
479-
fi
480-
fsdk=${fsdk%/MacOSX*.sdk}
481-
fsdk=${fsdk}/MacOSX${osvers}.sdk
482-
[[ -e ${fsdk} ]] && SDKPATH=${fsdk}
483-
fi
484-
if [[ ! -e ${SDKPATH} ]] ; then
485-
SDKPATH=$(xcodebuild -showsdks | sort -nr \
486-
| grep -o "macosx.*" | head -n1)
487-
SDKPATH=$(xcode-select -print-path)/SDKs/MacOSX${SDKPATH#macosx}.sdk
488-
fi
489-
fi
490-
( cd "${ROOT}" && ln -s "${SDKPATH}" MacOSX.sdk )
491-
einfo "using system sources from ${SDKPATH}"
492-
fi
493-
494457
if [[ ${DARWIN_USE_GCC} == 1 ]] ; then
495458
# amend profile, to use gcc one
496459
profile="${profile}/gcc"
@@ -585,7 +548,7 @@ bootstrap_tree() {
585548
# retain this comment and the line below to
586549
# keep this snapshot around in the snapshots
587550
# MKSNAPSHOT-ANCHOR -- directory of rsync slaves
588-
local PV="20240622"
551+
local PV="20240718"
589552

590553
# RAP uses the latest gentoo main repo snapshot to bootstrap.
591554
is-rap && LATEST_TREE_YES=1
@@ -919,8 +882,16 @@ bootstrap_gnu() {
919882
"--disable-bootstrap"
920883
"--disable-multilib"
921884
"--disable-nls"
885+
"--disable-libsanitizer"
922886
)
923887

888+
if [[ ${CHOST} == *-darwin* ]] ; then
889+
myconf+=(
890+
"--with-native-system-header-dir=${ROOT}/MacOSX.sdk/usr/include"
891+
"--with-ld=${ROOT}/tmp/usr/bin/ldwrapper"
892+
)
893+
fi
894+
924895
export CFLAGS="-O1 -pipe"
925896
export CXXFLAGS="-O1 -pipe"
926897
fi
@@ -1320,6 +1291,33 @@ bootstrap_mpc() {
13201291
bootstrap_gnu mpc 1.2.1
13211292
}
13221293

1294+
bootstrap_ldwrapper() {
1295+
A=ldwrapper.c
1296+
1297+
einfo "Bootstrapping ${A%.c}"
1298+
1299+
efetch "https://rsync.prefix.bitzolder.nl/sys-devel/binutils-config/files/${A}" || return 1
1300+
1301+
export S="${PORTAGE_TMPDIR}/ldwrapper"
1302+
rm -rf "${S}"
1303+
mkdir -p "${S}" || return 1
1304+
cd "${S}" || return 1
1305+
cp "${DISTDIR}/${A}" . || return 1
1306+
1307+
einfo "Compiling ${A%.c}"
1308+
${CC:-gcc} \
1309+
-o ldwrapper \
1310+
-DCHOST="\"${CHOST}\"" \
1311+
-DEPREFIX="\"${ROOT}\"" \
1312+
ldwrapper.c || return 1
1313+
1314+
einfo "Installing ${A%.c}"
1315+
mkdir -p "${ROOT}"/tmp/usr/bin
1316+
cp -a ldwrapper "${ROOT}"/tmp/usr/bin/ || return 1
1317+
1318+
einfo "${A%.c} bootstrapped"
1319+
}
1320+
13231321
bootstrap_gcc5() {
13241322
# bootstraps with gcc-4.0.1 (Darwin 8), provides C11
13251323
bootstrap_gnu gcc 5.5.0
@@ -1482,12 +1480,51 @@ bootstrap_stage1() {
14821480
[[ -e ${ROOT}/tmp/${x} ]] || ( cd "${ROOT}"/tmp && ln -s usr/${x} )
14831481
done
14841482

1485-
# we could check compiler version here, but we just know
1486-
# it's Darwin 8 and 9 being affected here, so handle them to
1487-
# get a GCC-5 which is sufficient to compile the current tree
1488-
# packages
1483+
configure_toolchain
1484+
export CC CXX
1485+
1486+
# GCC 14 cannot be compiled by versions of Clang at least on
1487+
# Darwin17, so go the safe route and get GCC-5 which is sufficient
1488+
# and the last one we can compile without C11. This also compiles
1489+
# on Darwin 8 and 9.
14891490
# see also configure_toolchain
1490-
if [[ ${CHOST} == *-darwin[89] ]] ; then
1491+
if [[ ${CHOST} == *-darwin* ]] ; then
1492+
# setup MacOSX.sdk symlink for GCC, this should probably be
1493+
# managed using an eselect module in the future
1494+
# FWIW, just use system (/) if it seems OK, for some reason
1495+
# early versions of TAPI-based SDKs did not include some symbols
1496+
# like fclose, which ld64 is able to resolve from the dylibs
1497+
# although they are unvisible using e.g. nm.
1498+
rm -f "${ROOT}"/MacOSX.sdk
1499+
local SDKPATH
1500+
if [[ -e /usr/lib/libSystem.B.dylib && -d /usr/include ]] ; then
1501+
SDKPATH=/
1502+
else
1503+
SDKPATH=$(xcrun --show-sdk-path --sdk macosx)
1504+
if [[ -L ${SDKPATH} ]] ; then
1505+
local fsdk
1506+
local osvers
1507+
# try and find a matching OS SDK
1508+
fsdk="$(readlink -f "${SDKPATH}")"
1509+
osvers="$(sw_vers -productVersion)"
1510+
if [[ ${osvers%%.*} -le 10 ]] ; then
1511+
osvers=$(echo "${osvers}" | cut -d'.' -f1-2)
1512+
else
1513+
osvers=${osvers%%.*}
1514+
fi
1515+
fsdk=${fsdk%/MacOSX*.sdk}
1516+
fsdk=${fsdk}/MacOSX${osvers}.sdk
1517+
[[ -e ${fsdk} ]] && SDKPATH=${fsdk}
1518+
fi
1519+
if [[ ! -e ${SDKPATH} ]] ; then
1520+
SDKPATH=$(xcodebuild -showsdks | sort -nr \
1521+
| grep -o "macosx.*" | head -n1)
1522+
SDKPATH=$(xcode-select -print-path)/SDKs/MacOSX${SDKPATH#macosx}.sdk
1523+
fi
1524+
fi
1525+
( cd "${ROOT}" && ln -s "${SDKPATH}" MacOSX.sdk )
1526+
einfo "using system sources from ${SDKPATH}"
1527+
14911528
# benefit from 4.2 if it's present
14921529
if [[ -e /usr/bin/gcc-4.2 ]] ; then
14931530
export CC=gcc-4.2
@@ -1499,12 +1536,47 @@ bootstrap_stage1() {
14991536
|| (bootstrap_mpfr) || return 1
15001537
[[ -e ${ROOT}/tmp/usr/include/mpc.h ]] \
15011538
|| (bootstrap_mpc) || return 1
1539+
[[ -x ${ROOT}/tmp/usr/bin/ldwrapper ]] \
1540+
|| (bootstrap_ldwrapper) || return 1
1541+
# get ldwrapper target in PATH
1542+
export BINUTILS_CONFIG_LD="$(type -P ld)"
1543+
# force deployment target in GCCs build, GCC-5 doesn't quite get
1544+
# the newer macOS versions (20+) and thus confuses ld when it
1545+
# passes on the deployment version. Use High Sierra as it has
1546+
# everything we need
1547+
[[ ${CHOST##*darwin} -gt 10 ]] && export MACOSX_DEPLOYMENT_TARGET=10.13
15021548
[[ -x ${ROOT}/tmp/usr/bin/gcc ]] \
15031549
|| (bootstrap_gcc5) || return 1
1504-
fi
15051550

1506-
configure_toolchain
1507-
export CC CXX
1551+
if [[ ${CHOST##*darwin} -gt 10 ]] ; then
1552+
# install wrappers in tmp/usr/local/bin which comes before
1553+
# /tmp/usr/bin in PATH
1554+
mkdir -p "${ROOT}"/tmp/usr/local/bin
1555+
rm -f "${ROOT}"/tmp/usr/local/bin/{gcc,${CHOST}-gcc}
1556+
cat > "${ROOT}/tmp/usr/local/bin/${CHOST}-gcc" <<-EOS
1557+
#!/usr/bin/env sh
1558+
export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}
1559+
export BINUTILS_CONFIG_LD="$(type -P ld)"
1560+
exec "${ROOT}"/tmp/usr/bin/${CHOST}-gcc "\$@"
1561+
EOS
1562+
chmod 755 "${ROOT}/tmp/usr/local/bin/${CHOST}-gcc"
1563+
ln -s ${CHOST}-gcc "${ROOT}"/tmp/usr/local/bin/gcc
1564+
1565+
rm -f "${ROOT}"/tmp/usr/local/bin/{g++,${CHOST}-g++}
1566+
cat > "${ROOT}"/tmp/usr/local/bin/${CHOST}-g++ <<-EOS
1567+
#!/usr/bin/env sh
1568+
export MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}
1569+
export BINUTILS_CONFIG_LD="$(type -P ld)"
1570+
exec "${ROOT}"/tmp/usr/bin/${CHOST}-g++ "\$@"
1571+
EOS
1572+
chmod 755 "${ROOT}"/tmp/usr/local/bin/${CHOST}-g++
1573+
ln -s ${CHOST}-g++ "${ROOT}"/tmp/usr/local/bin/g++
1574+
fi
1575+
1576+
# reset after gcc-4.2 usage
1577+
export CC=gcc
1578+
export CXX=g++
1579+
fi
15081580

15091581
# Run all bootstrap_* commands in a subshell since the targets
15101582
# frequently pollute the environment using exports which affect
@@ -3018,7 +3090,7 @@ EOF
30183090
# location seems ok
30193091
break
30203092
done
3021-
export PATH="$EPREFIX/usr/bin:$EPREFIX/bin:$EPREFIX/tmp/usr/bin:$EPREFIX/tmp/bin:$EPREFIX/tmp/usr/local/bin:${PATH}"
3093+
export PATH="$EPREFIX/usr/bin:$EPREFIX/bin:$EPREFIX/tmp/usr/local/bin:$EPREFIX/tmp/usr/bin:$EPREFIX/tmp/bin:${PATH}"
30223094

30233095
cat << EOF
30243096

0 commit comments

Comments
 (0)