This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Implement execute-only support in CodeGen

Authored by prakhar on Dec 6 2016, 2:59 AM.



[ARM] Implement execute-only support in CodeGen

This implements execute-only support for ARM code generation, which
prevents the compiler from generating data accesses to code sections.
The following changes are involved:

  • Add the SubtargetFeature "execute-only" to the ARM code generator.
  • Add the clang flag "-mexecute-only" as well as the GCC-compatible alias "-mpure-code" to enable this feature.
  • When enabled, literal pools are replaced with MOVW/MOVT instructions, with VMOV used in addition for floating-point literals. As the MOVT instruction is required, execute-only support is only available in Thumb mode for targets supporting ARMv8-M baseline or Thumb2.
  • Jump tables are placed in data sections when in execute-only mode.
  • The execute-only text section is assigned section ID 0, and is marked as unreadable with the SHF_ARM_PURECODE flag with symbol 'y'. This also overrides selection of ELF sections for globals.

Diff Detail


Event Timeline

prakhar updated this revision to Diff 80399.Dec 6 2016, 2:59 AM
prakhar retitled this revision from to [ARM] Implement execute-only support in CodeGen.
prakhar updated this object.
prakhar added reviewers: t.p.northover, rengolin.
prakhar added a subscriber: llvm-commits.
rengolin added inline comments.Dec 8 2016, 5:53 AM
1145 ↗(On Diff #80399)

In theory, ARMv6T2+ supports it. I just want to make sure we're blocking it for a reason.

1149 ↗(On Diff #80399)

Please, add curly brackets, for clarity.

63 ↗(On Diff #80399)

Why not long-calls? Where is this being disabled / guaranteed?

prakhar marked 2 inline comments as done.Dec 13 2016, 4:02 AM
prakhar added inline comments.
1145 ↗(On Diff #80399)

Yes, there's no real reason to arbitrarily block ARMv6T2 here, so I'll explicitly allow it here.

63 ↗(On Diff #80399)

Long calls generates constant pool entries in several cases, and the work required to make long calls play nicely with execute-only has not yet been done. I'll add in a diagnostic to prevent the two being used together for now.

prakhar updated this revision to Diff 81216.Dec 13 2016, 5:19 AM
prakhar marked an inline comment as done.

Allow ARMv6T2, and provide diagnostics if combined with -mno-movt or -mlong-calls

prakhar updated this object.Dec 13 2016, 5:25 AM
prakhar set the repository for this revision to rL LLVM.
prakhar updated this revision to Diff 81222.Dec 13 2016, 6:05 AM

Fixes for test and commit message

rengolin accepted this revision.Dec 14 2016, 5:14 AM
rengolin edited edge metadata.

Allow ARMv6T2, and provide diagnostics if combined with -mno-movt or -mlong-calls

Can you add a comment to the long-calls if block saying why they're not compatible yet?

Otherwise, LGTM. Thanks!

This revision is now accepted and ready to land.Dec 14 2016, 5:14 AM

Just to be clear, this should be committed after the LLVM change, once it's approved.

prakhar updated this revision to Diff 81399.Dec 14 2016, 9:10 AM
prakhar edited edge metadata.

Make execute-only a codegen option instead of a subtarget feature

prakhar updated this revision to Diff 81401.Dec 14 2016, 9:17 AM

Message about why long calls are not supported in execute-only

This revision was automatically updated to reflect the committed changes.