Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev-lang/rust: fix the build with musl-1.2.4 #31205

Closed
wants to merge 1 commit into from

Conversation

orbea
Copy link
Contributor

@orbea orbea commented May 28, 2023

This fixes the build with musl-1.2.4, may need -system-bootstrap after updating musl.

Closes: https://bugs.gentoo.org/903607
Upstream-PR: rust-lang/rust#106246
Upstream-Issue: rust-lang/libc#2934
Upstream-PR: rust-lang/libc#2935
Upstream-Commit: rust-lang/libc@1e8c55c
Upstream-PR: rust-random/getrandom#326
Upstream-Commit: rust-random/getrandom@7f73e3c

@gentoo-bot
Copy link

Pull Request assignment

Submitter: @orbea
Areas affected: ebuilds
Packages affected: dev-lang/rust

dev-lang/rust: @gyakovlev, @gentoo/rust

Linked bugs

Bugs linked: 903607


In order to force reassignment and/or bug reference scan, please append [please reassign] to the pull request title.

Docs: Code of ConductCopyright policy (expl.) ● DevmanualGitHub PRsProxy-maint guide

@gentoo-bot gentoo-bot added assigned PR successfully assigned to the package maintainer(s). bug linked Bug/Closes found in footer, and cross-linked with the PR. labels May 28, 2023
@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-05-28 23:43 UTC
Newest commit scanned: 088976d
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/9284601217/output.html

@vimproved
Copy link
Contributor

vimproved commented Jun 1, 2023

Would it potentially be a good idea to have a dependency along the lines of

elibc_musl? (
    !system-bootstrap? (
        <sys-libs/musl-1.2.4
    )
)

to ensure people aren't trying to build it without system-bootstrap on 1.2.4?
This might be better suited to a check in pre_build_checks though.

@orbea
Copy link
Contributor Author

orbea commented Jun 1, 2023

Good idea, I updated the PR. It seems there is already a elibc_musl check in DEPEND and if USE=-system-boostrap is set then emerge will try to downgrade to musl-1.2.3. I think the remaining foot gun is that when rust was built successfully without these patches before upgrading to musl-1.2.4, but it can be manually resolved and is still probably better than not being able to build rust at all.

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-06-01 13:24 UTC
Newest commit scanned: fc0a2b6
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/8227195a7b/output.html

@orbea
Copy link
Contributor Author

orbea commented Jun 5, 2023

I updated this PR for rust-1.70.0.

@gyakovlev Can you please review this PR, its a blocking issue for me.

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-06-05 00:29 UTC
Newest commit scanned: 45b1686
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/0b4d6f7466/output.html

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-06-05 17:24 UTC
Newest commit scanned: d2b0ef0
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/e73e9b4e35/output.html

@orbea orbea force-pushed the rust-musl-1.2.4 branch 2 times, most recently from 783738e to f8bcc5d Compare June 8, 2023 18:33
@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-06-08 18:44 UTC
Newest commit scanned: f8bcc5d
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/49bb719cbd/output.html

@orbea
Copy link
Contributor Author

orbea commented Jun 9, 2023

@gyakovlev Can you please review this? Its a pain to rebase this over and over again.

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-06-09 16:39 UTC
Newest commit scanned: a82e6e2
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/5645309970/output.html

@vimproved
Copy link
Contributor

Would probably be a good idea to re-add 1.69 since 1.70 is now unkeyworded and masked.

@orbea
Copy link
Contributor Author

orbea commented Jun 10, 2023

Downgrading rust is unfortunately a lot of effort to test.

@vimproved
Copy link
Contributor

Did it myself, working fine for me.

@vimproved
Copy link
Contributor

(Plus it was working fine before, so it should be fine.)

@orbea
Copy link
Contributor Author

orbea commented Jun 11, 2023

If @gyakovlev wants it I can add it back, but until I hear something one way or another I'd prefer to do as little work as possible.

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-06-29 15:35 UTC
Newest commit scanned: 3166125
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/7c0aa46e7c/output.html

@LinuxUserGD
Copy link
Contributor

if USE=-system-boostrap is set then emerge will try to downgrade to musl-1.2.3.

Downgrading musl works if only a few packages have been compiled with musl-1.2.4, otherwise the Gentoo installation might break.
https://www.openwall.com/lists/musl/2023/05/02/1

The dynamic linker (and static-PIE entry point code) adds support for
the new compact "RELR" format for relative relocations which recent
linkers can generate. Use of this linker feature for dynamic-linked
programs will make them depend on having musl 1.2.4 or later available
at runtime.

@vimproved
Copy link
Contributor

if USE=-system-boostrap is set then emerge will try to downgrade to musl-1.2.3.

Downgrading musl works if only a few packages have been compiled with musl-1.2.4, otherwise the Gentoo installation might break. https://www.openwall.com/lists/musl/2023/05/02/1

The dynamic linker (and static-PIE entry point code) adds support for
the new compact "RELR" format for relative relocations which recent
linkers can generate. Use of this linker feature for dynamic-linked
programs will make them depend on having musl 1.2.4 or later available
at runtime.

What I've been doing is reverting the musl commits that removed lfs64 support before rebuilding rust. I don't know if this would be feasible, however the only thing I can think of that would be able to fix it is adding a default disabled USE flag to musl that reverts the LFS64 removal until the issue gets fixed upstream, and then adding something like

elibc_musl? (
    !system-bootstrap? (
        || (
            <sys-libs/musl-1.2.4
            sys-libs/musl[revert-lfs64]
        )
    )
)

Obviously this would be an inelegant fix but I don't think there's a particularly good solution to this until Rust gets it together and finally fixes it upstream.

@orbea
Copy link
Contributor Author

orbea commented Jul 9, 2023

Fwiw I believe this is the only rust PR we are waiting on. rust-lang/rust#106246

Conditional patches for musl sounds like an even bigger mess to me.

@vimproved
Copy link
Contributor

Yeah, at this point it's probably best to just wait on upstream until the fixes make it into the bootstrap tarballs.

@orbea
Copy link
Contributor Author

orbea commented Jul 9, 2023

Yeah, at this point it's probably best to just wait on upstream until the fixes make it into the bootstrap tarballs.

That only makes it harder for anyone with musl-1.2.4 and downgrading your system could be problematic regardless if rust is fixed or not. Also we might be waiting a long time...

@12101111
Copy link
Contributor

12101111 commented Jul 9, 2023

I'm using this wrapper to workaround linking issue for upstream release

#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>

int fstat64(int fd, struct stat *statbuf) {
  return fstat(fd, statbuf);
}
off_t lseek64(int fd, off_t offset, int whence) {
  return lseek(fd, offset, whence);
}
int stat64(const char* pathname, struct stat* statbuf) {
  return stat(pathname, statbuf);
}
int open64(const char* pathname, int flags) {
  return open(pathname, flags);
}
int openat64(int dirfd, const char* pathname, int flags, mode_t mode) {
  return openat(dirfd, pathname, flags, mode);
}
int fstatat64(int dirfd, const char* pathname, struct stat* statbuf, int flags) {
  return fstatat(dirfd, pathname, statbuf, flags);
}
struct dirent* readdir64(DIR *dirp) {
  return readdir(dirp);
}
int lstat64(const char* pathname, struct stat* statbuf) {
  return lstat(pathname, statbuf);
}

Compile this to archive file (eg. libalias.a) and add -L/usr/local/lib -lalias to RUSTFLAGS.

cc -O2 -c -o alias.o alias.c
ar -crs libalias.a alias.o
sudo cp libalias.a /usr/local/lib

@vimproved
Copy link
Contributor

vimproved commented Jul 12, 2023

Here's a very hacky solution that allows bootstrapping from the stage0 tarball without downgrading or patching musl, using objcopy to redefine symbols in the rust stdlib:

src_prepare() {
	eapply_crate vendor/getrandom "${FILESDIR}"/1.69.0-musl-1.2.4-getrandom.patch
	eapply_crate vendor/libc-0.2.138 "${FILESDIR}"/1.69.0-musl-1.2.4-libc-0.2.138.patch
	eapply_crate vendor/libc-0.2.139 "${FILESDIR}"/1.69.0-musl-1.2.4-libc.patch
	eapply_crate vendor/libc "${FILESDIR}"/1.69.0-musl-1.2.4-libc.patch

	if ! use system-bootstrap; then
		has_version sys-devel/gcc || esetup_unwind_hack
		local rust_stage0_root="${WORKDIR}"/rust-stage0
		local rust_stage0="rust-${RUST_STAGE0_VERSION}-$(rust_abi)"

		if use elibc_musl; then
			LIBSTD="${WORKDIR}/${rust_stage0}/rust-std-$(rust_abi)/lib/rustlib/$(rust_abi)/lib/libstd-"*".rlib"

			"$(tc-getOBJCOPY)" \
				--redefine-sym=stat64=stat \
				--redefine-sym=fstat64=fstat \
				--redefine-sym=lstat64=lstat \
				--redefine-sym=open64=open \
				--redefine-sym=readdir64=readdir \
				--redefine-sym=fstatat64=fstatat \
				--redefine-sym=lseek64=lseek \
				--redefine-sym=ftruncate64=ftruncate \
				"${LIBSTD}" \
				"${LIBSTD}.out" || die

			mv "${LIBSTD}.out" "${LIBSTD}" || die
		fi

		"${WORKDIR}/${rust_stage0}"/install.sh --disable-ldconfig \
			--without=rust-docs-json-preview,rust-docs --destdir="${rust_stage0_root}" --prefix=/ || die
	fi

	default
}

@orbea
Copy link
Contributor Author

orbea commented Jul 13, 2023

Would that be compatible with both gcc and clang? Also < musl-1.2.4?

@vimproved
Copy link
Contributor

vimproved commented Jul 13, 2023

Would that be compatible with both gcc and clang? Also < musl-1.2.4?

Yes. All functions on >=musl-1.2 are automatically 64-bit, and this works with both LLVM and GNU binutils.

@orbea
Copy link
Contributor Author

orbea commented Jul 16, 2023

@vimproved I pushed your suggestion with minor changes.

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-07-16 17:10 UTC
Newest commit scanned: 1851598
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/80181023df/output.html

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-07-17 00:45 UTC
Newest commit scanned: b1378ad
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/1ab525cc05/output.html

@richfelker
Copy link

Yes. All functions on >=musl-1.2 are automatically 64-bit, and this works with both LLVM and GNU binutils.

You mean >=musl-0.5.0.

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-07-20 19:40 UTC
Newest commit scanned: 11b7aed
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/beb13639d8/output.html

@thesamesam thesamesam requested a review from xen0n July 20, 2023 23:23
@vimproved
Copy link
Contributor

Yes. All functions on >=musl-1.2 are automatically 64-bit, and this works with both LLVM and GNU binutils.

You mean >=musl-0.5.0.

Didn't know that, thanks for the correction. Was thinking of 64-bit time_t probably.

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-07-21 22:11 UTC
Newest commit scanned: 14da7e8
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/7bd5a4027a/output.html

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-07-24 19:40 UTC
Newest commit scanned: d13271b
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/3e2c3ccb2b/output.html

@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-08-04 16:20 UTC
Newest commit scanned: 81fc190
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/4d1e6d3f2b/output.html

@orbea
Copy link
Contributor Author

orbea commented Aug 4, 2023

@xen0n Can you please review this PR?

This fixes the build with musl-1.2.4, may need -system-bootstrap after
updating musl.

Closes: https://bugs.gentoo.org/903607
Upstream-PR: rust-lang/rust#106246
Upstream-Issue: rust-lang/libc#2934
Upstream-PR: rust-lang/libc#2935
Upstream-Commit: rust-lang/libc@1e8c55c
Upstream-PR: rust-random/getrandom#326
Upstream-Commit: rust-random/getrandom@7f73e3c
Signed-off-by: orbea <orbea@riseup.net>
@gentoo-repo-qa-bot
Copy link
Collaborator

Pull request CI report

Report generated at: 2023-08-07 01:05 UTC
Newest commit scanned: 5033d91
Status: ✅ good

There are existing issues already. Please look into the report to make sure none of them affect the packages in question:
https://qa-reports.gentoo.org/output/gentoo-ci/e9ecb86905/output.html

@orbea orbea closed this Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assigned PR successfully assigned to the package maintainer(s). bug linked Bug/Closes found in footer, and cross-linked with the PR.
Projects
None yet
7 participants