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

HiPE: fix ARM/Thumb interworking #583

Merged
merged 1 commit into from Jan 16, 2015

Conversation

mikpe
Copy link
Contributor

@mikpe mikpe commented Jan 11, 2015

HiPE on ARM is currently severely broken if the rest of the VM is
compiled to run in Thumb mode -- calling native code quickly ends
up executing code in the wrong mode and crashing the VM. This is
a problem on e.g. Ubuntu which configures its system GCC to generate
Thumb by default. It can also be triggered by overriding CC or
CFLAGS when compiling the VM.

There were three issues that caused the breakage:

  1. Assembly-coded functions in hipe_arm_glue.S weren't explicitly
    tagged as functions, preventing the linker from generating the
    correct mode-switching call instructions for calls from C to
    these functions.

    Fixed by tagging those symbols as functions.

  2. A few BIF wrappers were so simple that they performed tailcalls
    to the C BIFs. This fails to switch mode when C is in Thumb.

    Fixed by performing ordinary recursive calls when C is in Thumb.

  3. The assembly-coded source files weren't explicitly tagged as ARM.

Tested with the HiPE testsuite on ARMv7, with the VM built as ARM
and as Thumb. Also manually inspected the object code for the beam
executable and checked that call sites from C to HiPE's ARM runtime
code and vice versa used the correct mode-switching instructions.

HiPE on ARM is currently severely broken if the rest of the VM is
compiled to run in Thumb mode -- calling native code quickly ends
up executing code in the wrong mode and crashing the VM.  This is
a problem on e.g. Ubuntu which configures its system GCC to generate
Thumb by default.  It can also be triggered by overriding CC or
CFLAGS when compiling the VM.

There were three issues that caused the breakage:

1. Assembly-coded functions in hipe_arm_glue.S weren't explicitly
   tagged as functions, preventing the linker from generating the
   correct mode-switching call instructions for calls from C to
   these functions.

   Fixed by tagging those symbols as functions.

2. A few BIF wrappers were so simple that they performed tailcalls
   to the C BIFs.  This fails to switch mode when C is in Thumb.

   Fixed by performing ordinary recursive calls when C is in Thumb.

3. The assembly-coded source files weren't explicitly tagged as ARM.

Tested with the HiPE testsuite on ARMv7, with the VM built as ARM
and as Thumb.  Also manually inspected the object code for the beam
executable and checked that call sites from C to HiPE's ARM runtime
code and vice versa used the correct mode-switching instructions.
@OTP-Maintainer
Copy link

Patch has passed first testings and has been assigned to be reviewed


I am a script, I am not human


@marcusarendt marcusarendt merged commit 132f272 into erlang:maint Jan 16, 2015
@mikpe mikpe deleted the hipe-arm-interworking branch March 15, 2020 13:01
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

Successfully merging this pull request may close these issues.

None yet

3 participants