An ARM ELF binary with an odd entry point should start the binary in Thumb mode. However, this does not seem to be the case, forcing the entry point to be in ARM mode. To reproduce, copy the following code to a file named test.s: .arch armv7a .syntax unified .thumb .thumb_func .globl _start _start: movs r0, #0 movs r7, #1 svc #0 Then assemble and link: as -o test.o test.s ld -o test test.o And observe the program crashing on start with a segmentation fault or invalid instruction exception. Expected behaviour is that the program terminates with exit status 0.
Can't reproduce on 14-CURRENT here (on armv7). On what version of FreeBSD are you seeing this ?
Hi, I'm trying this on 13.0-RELEASE. If this is fixed in 14-CURRENT, that's great news! Perhaps consider merging the fix for this into 13-STABLE for 13.1.
I'm not sure that any patches fixed that. On what hardware was this tested ? Do you build yourself or are you using the release tarball/image ?
(In reply to Emmanuel Vadot from comment #3) I installed from release tarballs. uname says: FreeBSD tau.fuz.su 13.0-RELEASE FreeBSD 13.0-RELEASE #0 releng/13.0-n244733-ea31abc261f: Fri Apr 9 03:54:53 UTC 2021 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/arm64.aarch64/sys/GENERIC arm64
(In reply to Robert Clausecker from comment #4) Ah so it's arm64 not arm. This wasn't clear. So yeah this isn't fixed in main.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=712c060c94fd447c91b0e6218c12a431206b487a commit 712c060c94fd447c91b0e6218c12a431206b487a Author: Olivier Houchard <cognet@FreeBSD.org> AuthorDate: 2021-06-30 12:50:47 +0000 Commit: Olivier Houchard <cognet@FreeBSD.org> CommitDate: 2021-06-30 12:55:18 +0000 arm64: Make sure COMPAT_FREEBSD32 handles thumb entry point. If the entry point for the binary executed is a thumb 2 entry point, make sure we set the PSR_T bit, or the CPU will interpret it as arm32 code and bad things will happen. PR: 256899 MFC after: 1 week sys/arm64/arm64/elf32_machdep.c | 2 ++ 1 file changed, 2 insertions(+)
Hi Robert, Any chance you can test that patch ? (712c060c94fd447c91b0e6218c12a431206b487a). I believe it may fix the issue. Thanks !
(In reply to Emmanuel Vadot from comment #5) Oh sorry, I was also able to reproduce this on armv7 on a machine with this uname: FreeBSD mochi 12.2-RELEASE-p4 FreeBSD 12.2-RELEASE-p4 142f0d36d909(releng/12.2) GENERIC arm It's a bit hard to update this machine (insufficient RAM to make world, no freebsd-update) so it's stuck on this slightly outdated version. But yeah, perhaps it only affects armv7 binaries on arm64.
(In reply to Olivier Houchard from comment #7) Hi Olivier, if the patch applies to 13.0-RELEASE, I can try to test it. Unfortunately my only arm64 machine is in production use, so I would like to avoid installing CURRENT. And I think bhyve for arm64 isn't a thing yet.
(In reply to Robert Clausecker from comment #9) I think it should apply on 13.0 fine.
Patch confirmed to work on FreeBSD 13.0-RELEASE.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=8c3bd133dd52824e427e350c65eae1fd9eb5a3cd commit 8c3bd133dd52824e427e350c65eae1fd9eb5a3cd Author: Olivier Houchard <cognet@FreeBSD.org> AuthorDate: 2021-06-30 20:56:50 +0000 Commit: Olivier Houchard <cognet@FreeBSD.org> CommitDate: 2021-06-30 20:56:50 +0000 arm: Make sure we can handle a thumb entry point. Similarly to what's been done on arm64 with commit 712c060c94fd447c91b0e6218c12a431206b487a, when executing a binary, if the entry point is a thumb symbol, then make sure we set the PSL_T flag, otherwise the CPU will interpret it in ARM mode, and that will likely leads to an undefined instruction. PR: 256899 MFC after: 1 week sys/arm/arm/machdep.c | 2 ++ 1 file changed, 2 insertions(+)
(In reply to Olivier Houchard from comment #10) Is there any work left to do on this one?
(In reply to Robert Clausecker from comment #13) Just backporting the patches to stable branchs
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=82a1d67f018c7178485166ae3e06f29bff292263 commit 82a1d67f018c7178485166ae3e06f29bff292263 Author: Olivier Houchard <cognet@FreeBSD.org> AuthorDate: 2021-06-30 20:56:50 +0000 Commit: Olivier Houchard <cognet@FreeBSD.org> CommitDate: 2021-07-07 20:22:41 +0000 arm: Make sure we can handle a thumb entry point. Similarly to what's been done on arm64 with commit 712c060c94fd447c91b0e6218c12a431206b487a, when executing a binary, if the entry point is a thumb symbol, then make sure we set the PSL_T flag, otherwise the CPU will interpret it in ARM mode, and that will likely leads to an undefined instruction. PR: 256899 MFC after: 1 week (cherry picked from commit 8c3bd133dd52824e427e350c65eae1fd9eb5a3cd) Signed-off-by: Olivier Houchard <cognet@FreeBSD.org> sys/arm/arm/machdep.c | 2 ++ 1 file changed, 2 insertions(+)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=d2e48ad87d3e0f63f4ac73c524fb18afce4a2d53 commit d2e48ad87d3e0f63f4ac73c524fb18afce4a2d53 Author: Olivier Houchard <cognet@FreeBSD.org> AuthorDate: 2021-06-30 12:50:47 +0000 Commit: Olivier Houchard <cognet@FreeBSD.org> CommitDate: 2021-07-07 20:22:18 +0000 arm64: Make sure COMPAT_FREEBSD32 handles thumb entry point. If the entry point for the binary executed is a thumb 2 entry point, make sure we set the PSR_T bit, or the CPU will interpret it as arm32 code and bad things will happen. PR: 256899 MFC after: 1 week (cherry picked from commit 712c060c94fd447c91b0e6218c12a431206b487a) Signed-off-by: Olivier Houchard <cognet@FreeBSD.org> sys/arm64/arm64/elf32_machdep.c | 2 ++ 1 file changed, 2 insertions(+)
A commit in branch stable/12 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=9bc7bbcf214b9e15b67e42706cef770ede541913 commit 9bc7bbcf214b9e15b67e42706cef770ede541913 Author: Olivier Houchard <cognet@FreeBSD.org> AuthorDate: 2021-06-30 20:56:50 +0000 Commit: Olivier Houchard <cognet@FreeBSD.org> CommitDate: 2021-07-07 20:24:56 +0000 arm: Make sure we can handle a thumb entry point. Similarly to what's been done on arm64 with commit 712c060c94fd447c91b0e6218c12a431206b487a, when executing a binary, if the entry point is a thumb symbol, then make sure we set the PSL_T flag, otherwise the CPU will interpret it in ARM mode, and that will likely leads to an undefined instruction. PR: 256899 MFC after: 1 week (cherry picked from commit 8c3bd133dd52824e427e350c65eae1fd9eb5a3cd) Signed-off-by: Olivier Houchard <cognet@FreeBSD.org> sys/arm/arm/machdep.c | 2 ++ 1 file changed, 2 insertions(+)