This is an archive of the discontinued LLVM Phabricator instance.

[mips] Don't emit redundant mask instructions if the mask is already present.
AbandonedPublic

Authored by sstankovic on Dec 18 2014, 3:14 AM.

Details

Reviewers
mseaborn
Summary

The situation where masks are already present can only happen for sandboxed inline assembly. Since PNaCl currently doesn't allow inline assembly, this patch is only useful for tests that contain inline assembly.

Diff Detail

Repository
rL LLVM

Event Timeline

sstankovic updated this revision to Diff 17426.Dec 18 2014, 3:14 AM
sstankovic retitled this revision from to [mips] Don't emit redundant mask instructions if the mask is already present..
sstankovic updated this object.
sstankovic edited the test plan for this revision. (Show Details)
sstankovic added a reviewer: mseaborn.
sstankovic set the repository for this revision to rL LLVM.
sstankovic added subscribers: Unknown Object (MLST), petarj.
mseaborn edited edge metadata.Dec 18 2014, 8:54 AM

This would need test cases.

Can you explain the use case for this, please? Is this for assembly code that has already had NaCl sandboxing added to it manually?

Yes. Currently two tests fail because of the redundant sandboxing - syscall_return_sandboxing_test and exception_test. For syscall_return_sandboxing_test, to make the test pass we can either remove sandboxing from the assembly, or apply this patch. For exception test, neither removing the sandboxing nor applying the patch will work. Here is the problematic inline assembly from exception_test.c file:

crash_at_known_address:
and $zero, $zero, $t7
prog_ctr_at_crash:
sw $t0, 0($zero)

exception_test works by crashing when executing instruction labeled by "prog_ctr_at_crash", and then checking whether the saved program counter is identical to the value of "prog_ctr_at_crash". Test currently fails because sandboxing will add mask before "sw", moving the "sw" to the address prog_ctr_at_crash + 4. Removing the mask in the assembly obviously wouldn't make the test pass. But even with the patch applied this test would still fail. That's because patch is implemented so that it first saves the mask, and then emits it when emitting next instruction, surrounded by BundleLock() and BundleUnlock(). So patch would first save mask, then emit label "prog_ctr_at_crash", and then emit mask and "sw", placing "sw" at address prog_ctr_at_crash + 4.

The only way to make exception_test pass is either to add #ifdef for MIPS that would check that program counter has value prog_ctr_at_crash + 4, or find instruction that doesn't require masking and that can cause program to crash.

Is there a MIPS breakpoint/trap instruction that would work here?

"break" works - test passes when sw is replaced with break.

So I suppose all this means that this patch should be abandoned, and the tests modified.

Regards,
Sasa

sstankovic abandoned this revision.Dec 26 2014, 5:08 AM