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

Segmentation fault on 32-bit arm when built with -mthumb #1

Closed
fornwall opened this issue Feb 9, 2017 · 1 comment
Closed

Segmentation fault on 32-bit arm when built with -mthumb #1

fornwall opened this issue Feb 9, 2017 · 1 comment

Comments

@fornwall
Copy link
Member

fornwall commented Feb 9, 2017

@michalbednarski In termux/termux-packages#761 it was noticed that proot segfaults when built with -mthumb on 32-bit arm (which Termux&Android does by default to save binary size, as Thumb-2 seems to be recommended for most).

I worked around it by avoiding building proot with -mthumb in termux/termux-packages@28c436b, so it's not really that important, and I guess 32-bit arm is slowly being deprecated as more and more new devices are 64-bit.

So not worth spending a lot of time on, but still interesting to see if you have an idea what could cause this :).

@michalbednarski
Copy link
Collaborator

It's caused by r7 register conflict in loader (which is used as syscall number and when thumb mode is in use then also a frame pointer).

Problematic line is:
register word_t number asm("r7") = number_;

According to GCC documentation this is supposed to set register used for this variable in asm block (and that works, however r7 (as frame pointer) value is clobbered).

I'd say that it's clang bug that this compiled but clobbered frame pointer (gcc fails compilation in this case)

Anyway, only loader does need to be compiled without -mthumb.

michalbednarski added a commit to michalbednarski/termux-packages that referenced this issue Apr 10, 2017
Also revert to thumb mode as termux/proot#1 is fixed
fornwall pushed a commit to termux/termux-packages that referenced this issue Apr 10, 2017
Also revert to thumb mode as termux/proot#1 is fixed
its-pointless pushed a commit to its-pointless/termux-packages that referenced this issue May 7, 2017
Also revert to thumb mode as termux/proot#1 is fixed
@ghost ghost mentioned this issue Oct 24, 2019
Grimler91 pushed a commit that referenced this issue Jul 25, 2022
First, r7 register used as syscall number, however in thumb mode
it is also used as frame pointer so it needs to be saved and restored

Second, use "bx" instead of "mov pc", so thumb mode state will
be correct when branching from loader to loaded program

Fixes #1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants