Bug 201138 - testmasm: save r6 in JIT'ed code on ARM_THUMB2
Summary: testmasm: save r6 in JIT'ed code on ARM_THUMB2
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: Other Linux
: P2 Normal
Assignee: Guillaume Emont
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-08-26 06:50 PDT by Guillaume Emont
Modified: 2019-09-06 09:57 PDT (History)
9 users (show)

See Also:


Attachments
Patch (20.91 KB, patch)
2019-08-26 07:15 PDT, Guillaume Emont
no flags Details | Formatted Diff | Diff
Patch (21.09 KB, patch)
2019-08-28 16:15 PDT, Guillaume Emont
no flags Details | Formatted Diff | Diff
Patch (21.09 KB, patch)
2019-08-29 04:00 PDT, Guillaume Emont
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Guillaume Emont 2019-08-26 06:50:59 PDT
MacroAssemblerArmv7 uses r6 as a temporary register, and it is a callee-saved register. The JITs use AssemblyHelpers::emitSaveCalleeSaves() and friends to save callee-saved registers, but there is no such mechanism in testmasm, which seems to make the assumption that the macroassembler does not use callee-saved registers (which I guess is true for all other architectures, but not for Armv7).

This issue means that testmasm crashes on Armv7 since code generated by gcc uses r6, and it gets modified by JIT'ed code.
Comment 1 Guillaume Emont 2019-08-26 07:15:02 PDT
Created attachment 377243 [details]
Patch

Patch.
Comment 2 Caio Lima 2019-08-26 07:24:01 PDT
Comment on attachment 377243 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=377243&action=review

LGTM. I left some comments.

> Source/JavaScriptCore/ChangeLog:17
> +        by gcc uses r6, and it gets modified by JIT'ed code.

It would be good point to the source where you've found this information. Also, is it a problem if we use a different version of GCC or even Clang?
Comment 3 Guillaume Emont 2019-08-26 07:31:26 PDT
(In reply to Caio Lima from comment #2)
> Comment on attachment 377243 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=377243&action=review
> 
> LGTM. I left some comments.
> 
> > Source/JavaScriptCore/ChangeLog:17
> > +        by gcc uses r6, and it gets modified by JIT'ed code.
> 
> It would be good point to the source where you've found this information.
> Also, is it a problem if we use a different version of GCC or even Clang?

gcc, or any compiler, can use r6 and expect it not to change during a call to masm-compiled code because arm EABI says it is a callee-saved register.

Do you think I should add a comment saying where we use it in MacroAssemblerARMv7? (answer: a bunch of methods, and more will likely be added in the future).
Comment 4 Caio Lima 2019-08-26 09:45:15 PDT
(In reply to Guillaume Emont from comment #3)
> gcc, or any compiler, can use r6 and expect it not to change during a call
> to masm-compiled code because arm EABI says it is a callee-saved register.

In this case, I think this info is available into ARMv7 manual, right? Maybe it is worth it point to the section where this is stated.

> Do you think I should add a comment saying where we use it in
> MacroAssemblerARMv7? (answer: a bunch of methods, and more will likely be
> added in the future).

I'm not sure if this is necessary.Maybe a comment into `emitFunctionPrologue` is already sufficient.
Comment 5 Guillaume Emont 2019-08-28 16:15:35 PDT
Created attachment 377505 [details]
Patch

New patch.
Comment 6 Caio Lima 2019-08-28 19:02:02 PDT
Comment on attachment 377505 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=377505&action=review

LGTM. I'm wondering if we should add a FIXME to add the concept of callee-saved register into macroassembler.

> Source/JavaScriptCore/assembler/testmasm.cpp:187
> +    // http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042f/IHI0042F_aapcs.pdf

Nice. I think there are some strange characters there.
Comment 7 Guillaume Emont 2019-08-29 04:00:35 PDT
Created attachment 377566 [details]
Patch

New patch with only ASCII chars.
Comment 8 Guillaume Emont 2019-09-06 03:47:38 PDT
Ping reviewer.
Comment 9 Mark Lam 2019-09-06 09:11:06 PDT
Comment on attachment 377566 [details]
Patch

r=me
Comment 10 WebKit Commit Bot 2019-09-06 09:56:27 PDT
Comment on attachment 377566 [details]
Patch

Clearing flags on attachment: 377566

Committed r249576: <https://trac.webkit.org/changeset/249576>
Comment 11 WebKit Commit Bot 2019-09-06 09:56:29 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Radar WebKit Bug Importer 2019-09-06 09:57:15 PDT
<rdar://problem/55115864>
Comment 13 Radar WebKit Bug Importer 2019-09-06 09:57:16 PDT
<rdar://problem/55115866>