Bug 221185 - emulators/qemu-user-static: Crashes building lang/rust: (signal: 11, SIGSEGV: invalid memory reference)
Summary: emulators/qemu-user-static: Crashes building lang/rust: (signal: 11, SIGSEGV:...
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: arm64 Any
: --- Affects Many People
Assignee: Kyle Evans
URL:
Keywords: crash, needs-qa
: 254694 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-08-02 19:14 UTC by Jan Beich
Modified: 2024-07-22 01:47 UTC (History)
20 users (show)

See Also:


Attachments
poudriere log (38.79 KB, text/plain)
2017-08-02 19:14 UTC, Jan Beich
no flags Details
poudriere log (rust-1.21.0) (40.40 KB, text/plain)
2017-10-25 15:44 UTC, Jan Beich
no flags Details
patch (639 bytes, patch)
2019-02-21 11:58 UTC, Mikael Urankar
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2017-08-02 19:14:51 UTC
Created attachment 184965 [details]
poudriere log

$ poudriere jail -cj 111aarch64 -x -a arm64.aarch64 -v 11.1-RELEASE
$ poudriere bulk -Ctj 111aarch64 www/firefox # fails in lang/rust

$ poudriere jail -sj 111aarch64
<configure network in the jail>
$ env -i TERM=$TERM /usr/sbin/jexec 111aarch64-default /bin/sh
$ export ABI=FreeBSD:11:aarch64 UNAME_r=11.1-RELEASE

$ pkg install -qy rust
$ echo 'fn main() {}' >a.rs
$ rustc a.rs
Fatal error 'exception should be rethrown' at line 129 in file /usr/src/lib/libthr/thread/thr_exit.c (errno = 2)
qemu: uncaught target signal 6 (Abort trap) - core dumped
Abort trap
Comment 1 Sean Bruno freebsd_committer freebsd_triage 2017-08-03 15:47:39 UTC
Just for my sanity, does this run on real hardware?
Comment 2 Jan Beich freebsd_committer freebsd_triage 2017-08-03 17:25:22 UTC
Yep, comment 0 test works fine on ref11-aarch64 (base r319064 atm) and ref12-aarch64.
lang/rust uses prebuilt version of rustc during build, and at least 1.18.0 built fine:
http://thunderx1.nyi.freebsd.org/data/latest-per-pkg/rust/1.18.0/
Comment 3 Jan Beich freebsd_committer freebsd_triage 2017-10-24 18:36:52 UTC
rust-1.20.0 seems to build/run fine if one restarts cargo/rustc every time it randomly hangs or crashes. I've even managed to build unpatched Firefox 58 this babysitting way.

$ file rustc-*-aarch64-unknown-freebsd/rustc/bin/rustc
rustc-1.17.0-aarch64-unknown-freebsd/rustc/bin/rustc: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 11.0 (1100122), FreeBSD-style, not stripped
rustc-1.18.0-aarch64-unknown-freebsd/rustc/bin/rustc: ELF 64-bit LSB shared object, ARM aarch64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 11.0 (1100513), FreeBSD-style, not stripped
rustc-1.19.0-aarch64-unknown-freebsd/rustc/bin/rustc: ELF 64-bit LSB shared object, ARM aarch64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 11.0 (1100513), FreeBSD-style, not stripped
rustc-1.20.0-aarch64-unknown-freebsd/rustc/bin/rustc: ELF 64-bit LSB shared object, ARM aarch64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 11.0 (1100513), FreeBSD-style, not stripped

$ rustc-1.17.0-aarch64-unknown-freebsd/rustc/bin/rustc -vV
rustc 1.17.0 (56124baa9 2017-04-24)
binary: rustc
commit-hash: 56124baa9e73f28c0709e59e74783cf234a978cf
commit-date: 2017-04-24
host: aarch64-unknown-freebsd
release: 1.17.0
LLVM version: 3.9
Fatal error 'exception should be rethrown' at line 128 in file /poudriere/jails/head-aarch64/usr/src/lib/libthr/thread/thr_exit.c (errno = 0)
Segmentation fault

$ rustc-1.18.0-aarch64-unknown-freebsd/rustc/bin/rustc -vV
rustc 1.18.0 (03fc9d622 2017-06-06)
binary: rustc
commit-hash: 03fc9d622e0ea26a3d37f5ab030737fcca6928b9
commit-date: 2017-06-06
host: aarch64-unknown-freebsd
release: 1.18.0
LLVM version: 3.9
Fatal error 'exception should be rethrown' at line 128 in file /poudriere/jails/head-aarch64/usr/src/lib/libthr/thread/thr_exit.c (errno = 0)
Segmentation fault

$ rustc-1.19.0-aarch64-unknown-freebsd/rustc/bin/rustc -vV
rustc 1.19.0 (0ade33941 2017-07-17)
binary: rustc
commit-hash: 0ade339411587887bf01bcfa2e9ae4414c8900d4
commit-date: 2017-07-17
host: aarch64-unknown-freebsd
release: 1.19.0
LLVM version: 4.0
Fatal error 'exception should be rethrown' at line 128 in file /poudriere/jails/head-aarch64/usr/src/lib/libthr/thread/thr_exit.c (errno = 0)
Segmentation fault

$ rustc-1.20.0-aarch64-unknown-freebsd/rustc/bin/rustc -vV
rustc 1.20.0 (f3d6973f4 2017-08-27)
binary: rustc
commit-hash: f3d6973f41a7d1fb83029c9c0ceaf0f5d4fd7208
commit-date: 2017-08-27
host: aarch64-unknown-freebsd
release: 1.20.0
LLVM version: 4.0


$ make -C lang/rust
[...]
   Compiling num-traits v0.1.40
     Running `/wrkdirs/usr/ports/lang/rust/work/rustc-1.21.0-src/build/aarch64-unknown-freebsd/stage0/bin/rustc --crate-name num_traits src/vendor/num-traits/src/lib.rs --crate-type lib --emit=dep-info,link -C debug-assertions=off -C overflow-checks=on -C metadata=70b5f35f2a57f99e -C extra-filename=-70b5f35f2a57f99e --out-dir /wrkdirs/usr/ports/lang/rust/work/rustc-1.21.0-src/build/bootstrap/debug/deps -L dependency=/wrkdirs/usr/ports/lang/rust/work/rustc-1.21.0-src/build/bootstrap/debug/deps --cap-lints allow`
qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x6022324e
load: 1.40  cmd: qemu-aarch64-static 23867 [uwait] 109.59r 5.71u 0.03s 0% 254640k
Comment 4 Jan Beich freebsd_committer freebsd_triage 2017-10-25 15:44:46 UTC
Created attachment 187465 [details]
poudriere log (rust-1.21.0)
Comment 5 Jan Beich freebsd_committer freebsd_triage 2017-11-08 10:20:50 UTC
Looks like rust-1.20.0 only worked by luck.

$ pkg install rust
$ rustc -vV
rustc 1.21.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: aarch64-unknown-freebsd
release: 1.21.0
LLVM version: 4.0
Fatal error 'exception should be rethrown' at line 128 in file /poudriere/jails/head-aarch64/usr/src/lib/libthr/thread/thr_exit.c (errno = 0)
Abort trap
Comment 6 Tobias Kortkamp freebsd_committer freebsd_triage 2019-02-20 19:33:07 UTC
This is still a problem and actual since enabling building of
lang/rust on armv6/armv7/aarch64 in ports r493268.

The arvm7+QEMU build of lang/rust failed after taking > 21600 seconds
to compile the cfg-if crate [1].

aarch64+QEMU isn't any better and hangs eventually too.

[1] http://beefy16.nyi.freebsd.org/data/head-armv7-default/p493345_s344269/logs/rust-1.32.0.log
Comment 7 Mikael Urankar freebsd_committer freebsd_triage 2019-02-21 11:58:16 UTC
Created attachment 202230 [details]
patch

It's only a problem on armv6/7, we use real hw for building pkg on aarch64 and ppc64.

The attached patch prevents building rust with qemu-user and try to clarify the situation on aarch64
Comment 8 Tobias Kortkamp freebsd_committer freebsd_triage 2019-02-21 12:25:54 UTC
(In reply to mikael.urankar from comment #7)
+.if ${ARCH} == aarch64
+WARNING+=	"Due to a bug in rtld, rust fails to run on 11.2-RELEASE and 12.0-RELEASE \
+		you can either update /libexec/ld-elf.so.1 from -STABLE or -CURRENT \
+		or run -STABLE or -CURRENT"
+.endif

Which revisions do users need to upgrade to?  We might as well set
IGNORE for older OSVERSIONs on aarch64.

+.ifdef QEMU_EMULATING
+IGNORE=	qemu-user-static isn't able to build lang/rust, but it builds fine on a real hardware
+.endif

Ok.
Comment 9 Mikael Urankar freebsd_committer freebsd_triage 2019-02-21 12:54:54 UTC
(In reply to Tobias Kortkamp from comment #8)
for 12-stable: base r342847
for -current: base r342113

no mfc on 11-stable afaict
Comment 10 commit-hook freebsd_committer freebsd_triage 2019-02-21 19:04:13 UTC
A commit references this bug:

Author: tobik
Date: Thu Feb 21 19:03:17 UTC 2019
New revision: 493523
URL: https://svnweb.freebsd.org/changeset/ports/493523

Log:
  lang/rust: Ignore with qemu-user-static and on aarch64 without fixed ld-elf.so.1

  - Rust will not run without a fixed ld-elf.so.1 on aarch64
  - Builds with qemu-user-static currently hang after a while

  PR:		221185
  Submitted by:	Mika?l Urankar <mikael.urankar@gmail.com>

Changes:
  head/lang/rust/Makefile
Comment 11 Mateusz Piotrowski freebsd_committer freebsd_triage 2020-10-04 20:25:45 UTC
Could this issue be closed? It looks like some patches were committed...
Comment 12 Mikael Urankar freebsd_committer freebsd_triage 2020-10-05 06:23:09 UTC
(In reply to Mateusz Piotrowski from comment #11)
qemu-user-static can't build lang/rust, it's still an issue.
Comment 13 Kyle Evans freebsd_committer freebsd_triage 2020-11-13 21:57:11 UTC
This might be fixed, but I've got a local patch that will almost certainly solve this issue -- _umtx_op handling has been the bane of my existence, and I'm looking to offload it entirely to the kernel going forward.

My local patch allows this by introducing a 32bit flag to _umtx_op commands which qemu-bsd-user can then set to indicate to the kernel that it's looking at 32-bit structures. The new logic is used for any target where the endianness matches the host's, so 64-bit amd64 can natively handle armv7 or aarch64 while it's forced to fallback to the still-slightly-buggy emulation of _umtx_op for, e.g., mips.
Comment 14 Mikael Urankar freebsd_committer freebsd_triage 2021-04-01 13:44:11 UTC
*** Bug 254694 has been marked as a duplicate of this bug. ***
Comment 15 Tobias Kortkamp freebsd_committer freebsd_triage 2021-04-03 10:00:34 UTC
*** Bug 254694 has been marked as a duplicate of this bug. ***
Comment 16 tech-lists 2021-10-27 11:38:43 UTC
Hello,

rust-1.56.0 won't build in a qemu-poudriere for arm64 on amd64 on recent stable/13 with todays portstree. Error is "fails to build with qemu-user-static".

For clarity: 
1. is this the same bug?
2. If it is, is this bug a "won'tfix"

thanks
Comment 17 Raphael Ahrens 2021-12-15 23:45:15 UTC
Hi,

I also ran into this bug under 13.0/amd64 and with rust 1.57.0, trying to build it for armv6.

It would be good to know if this can be fixed and what is missing.

Thank you for an answer.
Comment 18 Dima Panov freebsd_committer freebsd_triage 2022-07-18 23:37:25 UTC
(In reply to Kyle Evans from comment #13)
Kyle, is any progress here?
Comment 19 Enji Cooper freebsd_committer freebsd_triage 2023-05-02 01:44:44 UTC
If I'm correct, this issue is blocking py-cryptography from upgrading to an OpenSSL 3 compatible version because newer versions of py-cryptography require rust: bug 254853.
Comment 20 Jan Beich freebsd_committer freebsd_triage 2023-05-02 02:23:36 UTC
Even if this is fixed running rustc under qemu-user-static will be extremely slow, especially with ports 967022fd812c or lto=true in Cargo.toml. Converting lang/rust into a cross-compiler and hooking into poudriere a la native-xtools may be more practical.
Comment 21 Mikael Urankar freebsd_committer freebsd_triage 2023-05-02 06:51:22 UTC
(In reply to Enji Cooper from comment #19)
This is not a blocker for py-cryptography. We build rust natively on all tier 1 arches.
Comment 22 Mark Millard 2023-08-26 20:31:52 UTC
(In reply to Mikael Urankar from comment #21)

But, for example,

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=254853#c33
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=254853#c49
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=254853#c80

all indicate that this is effectively a blocker based on how
things are actually being handled. That submittal lists this
submittal as something it depends on.

That official builds work on the ampere* aarch64 based builders
(or analogous) without qemu use is not the criteria actually
being used.
Comment 23 Mark Millard 2023-08-27 05:39:34 UTC
This bug report seems over specific when I look at the official
port->package builds done via qemu. These days that is only for
armv6 but it used to be for armv7 as well.

http://beefy8.nyi.freebsd.org/build.html?mastername=main-armv6-default&build=p72871fad39eb_sd1d7a27370 failed to build 275
ports, leading to 22091 skipped ports.

Of those 275 failures, 176 are "core dump" failures. (Rust was
not part of the queued ports.)


(I used to try to use qemu based port builds and I've occasionally
checked what the official qemu results use looked like for armv[67]
since then. Its armv* targeting reliability never seemed good. The
efforts to make it work well for 32-bit on 64-bit never seem to have
caught up with the problems over the years, as evidenced by the
modern armv6 results. It still looks like a huge effort to make
it generally work reliably for building ports into packages.)
Comment 24 Mark Millard 2023-08-27 06:37:56 UTC
(In reply to Mark Millard from comment #23)

Looking around to check on selective memory (plus irregular
sampling):

=>> Building ports-mgmt/pkg
build started at Sun Dec 11 03:55:47 UTC 2022
port directory: /usr/ports/ports-mgmt/pkg
package name: pkg-1.18.4
building for: FreeBSD main-armv6-default-job-01 14.0-CURRENT FreeBSD 14.0-CURRENT 1400074 arm
maintained by: pkg@FreeBSD.org
Makefile ident: 
Poudriere version: 3.2.8-23-ga7f8d188
Host OSVERSION: 1400073
Jail OSVERSION: 1400074

looks to have built 23646 ports into packages, of 33314 queued, failed 208,
and skipped 8725. Only 8 of the failures are listed as "coredump". This
seems to be the most recent of the among-the-best results for armv6 when
30000+ ports were queued.

So things got much worse this year compared to the end of last year. Even
the one started on 22 Dec 2022 skipped 18411 ports.
Comment 25 Nathan Reilly 2024-04-05 21:50:25 UTC
Are there any bugs for this issue 'upstream'? I can't see a reference to it in https://wiki.freebsd.org/QemuUserModeToDo or https://github.com/seanbruno/qemu-bsd-user/issues
Comment 26 Kyle Evans freebsd_committer freebsd_triage 2024-04-06 00:19:02 UTC
(In reply to Nathan Reilly from comment #25)

We shifted the project over to here: https://github.com/qemu-bsd-user/qemu-bsd-user/issues

but I don't think we have anything about this specifically, no.
Comment 27 hesitatej 2024-07-22 01:47:34 UTC
(In reply to Jan Beich from comment #20)

Rustc still fails to run in poudriere (3.4.1_1) arm64.aarch64 14.1-RELEASE jails with qemu-user-static(3.1.0_14), on FreeBSD 14.1-n267679-10e31f0946d8 amd64.


Would you (or someone else)  be able to provided some guidence on how to do this "Converting lang/rust into a cross-compiler and hooking into poudriere a la native-xtools may be more practical" briefly, please?