This is an archive of the discontinued LLVM Phabricator instance.

Implement NaCl sandboxing of function calls
ClosedPublic

Authored by sstankovic on Mar 10 2014, 2:00 PM.

Details

Summary

[mips] Implement NaCl sandboxing of function calls:

  • Add masking instructions before indirect calls (in MC layer).
  • Align call + branch delay to the bundle end (in MC layer).

Diff Detail

Event Timeline

mseaborn added inline comments.Mar 10 2014, 2:19 PM
lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp
45 ↗(On Diff #7713)

Please comment these three fields. "Call" and "IsIndirectCall" are only defined if SandboxingCall is true -- so please comment that, and put SandboxingCall first.

46 ↗(On Diff #7713)

Maybe something like "Pending" or "Saved" rather than "Sandboxing" would better suggest what's going on here?

166 ↗(On Diff #7713)

Nit: drop the "else" to be consistent with the rest of the function -- it isn't needed if the "if" block returns.

167 ↗(On Diff #7713)

Maybe comment this block: "Save up the call to emit after we see the branch delay instruction that follows"?

test/MC/Mips/nacl-mask.s
12 ↗(On Diff #7713)

Is the reason for adding this that EmitBundleLock(true) complains if an alignment hasn't been set already? Or does the test work without adding this .align?

sstankovic updated this revision to Unknown Object (????).Mar 11 2014, 7:58 AM

Patch is updated.

sstankovic added inline comments.Mar 11 2014, 8:01 AM
test/MC/Mips/nacl-mask.s
12 ↗(On Diff #7713)

No, I added this because llvm-mc doesn't call AsmPrinter::runOnMachineFunction, which means that functions are not bundle-aligned. Test expects that function start is bundle-aligned.

LGTM, thanks

lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp
135 ↗(On Diff #7744)

You could check PendingCall here (and for isIndirectJump above and isCall below) and report_fatal_error if it's set, since this would be an invalid instruction in the branch delay slot. Otherwise you might silently emit a mismatched bundle lock/unlock.

152 ↗(On Diff #7744)

Nice simplification from the previous version.

sstankovic updated this revision to Unknown Object (????).Mar 11 2014, 10:52 AM

Patch is updated.

sstankovic closed this revision.Mar 11 2014, 2:30 PM

Closed by commit rL203606 (authored by @sstankovic).