--- gentoo/sys-libs/musl/musl-1.2.1.ebuild 2020-08-31 14:19:29.510840267 +0100 +++ tpb/sys-libs/musl/musl-1.2.1.ebuild 2020-10-08 17:31:02.225958464 +0100 @@ -60,6 +60,11 @@ fi } +src_prepare() { + cp "${FILESDIR}/__stack_chk_fail_local.c" "$T/" + default +} + src_configure() { tc-getCC ${CTARGET} just_headers && export CC=true @@ -86,9 +91,26 @@ LDFLAGS="${LDFLAGS}" \ VPATH="${DISTDIR}" fi + + # Create a static library for use with GCC fstack-protector calls + # On certain architectures gcc emits a locally defined symbol that needs linking into target app + $(tc-getCC) ${CFLAGS} -c "${T}"/__stack_chk_fail_local.c -o "${T}"/__stack_chk_fail_local.o + $(tc-getAR) r "${T}"/libssp_nonshared.a "${T}"/__stack_chk_fail_local.o } src_install() { + # Avoid breakage while swapping symlink and lib + if [ -h ${sysroot}/lib/ld-musl-* ]; then + local ldso=$(basename ${sysroot}/lib/ld-musl-*) + eerror "***********************************************************************************" + eerror "Warning: Reach carefully! Breakage possible!" + eerror "In order to do the switcheroo and swap libc location, some manual changes are needed:" + eerror "Manual upgrade needed. run:" + einfo "cp --remove-destination ${sysroot}/usr/lib/libc.so ${sysroot}/lib/${ldso}" + eerror "***********************************************************************************" + die + fi + local target="install" just_headers && target="install-headers" emake DESTDIR="${D}" ${target} @@ -110,7 +132,7 @@ cp "${FILESDIR}"/ldconfig.in "${T}" || die sed -e "s|@@ARCH@@|${arch}|" "${T}"/ldconfig.in > "${T}"/ldconfig || die into / - dosbin "${T}"/ldconfig + dosbin "${T}"/ldconfig into /usr dobin "${T}"/getconf dobin "${T}"/getent @@ -118,6 +140,18 @@ echo 'LDPATH="include ld.so.conf.d/*.conf"' > "${T}"/00musl || die doenvd "${T}"/00musl fi + + # Conditionally upgrade /usr/lib/libc.so into a linker script. Useful on x86 + write_libc_so +} + +write_libc_so() { + if [ -e "${sysroot}"/lib/ld-musl-i386.so.1 ]; then + rm ${D}/usr/lib/libc.so + insinto /usr/lib + insopts -m644 + newins ${FILESDIR}/libc-so-i386.so libc.so + fi } pkg_postinst() {