This is an archive of the discontinued LLVM Phabricator instance.

CFI-icall on Thumb
ClosedPublic

Authored by eugenis on Dec 6 2016, 6:37 PM.

Details

Summary

Replace @progbits in the section directive with %progbits, because "@" starts a comment on arm/thumb.
Use b.w branch instruction.
Use .thumb_function and .thumb_set for proper arm/thumb interwork. This way jumptable entry addresses on thumb have bit 0 set (correctly). This does not affect CFI check math, because the address of the jumptable start also has that bit set.

This does not work on thumbv5, because it does not support b.w, and the linker would not insert a veneer (trampoline?) to extend the range of b.n. We may need to do full-range plt-style jumptables on thumbv54, which are 12 bytes per entry. Another option is "push lr; bl; pop pc" (4 bytes) but that needs unwinding instructions, etc.

Diff Detail

Repository
rL LLVM

Event Timeline

eugenis updated this revision to Diff 80528.Dec 6 2016, 6:37 PM
eugenis retitled this revision from to CFI-icall on Thumb.
eugenis updated this object.
eugenis added a reviewer: pcc.
eugenis set the repository for this revision to rL LLVM.
eugenis added a subscriber: llvm-commits.
rengolin added inline comments.Dec 7 2016, 3:03 AM
test/Transforms/LowerTypeTests/function.ll
2 ↗(On Diff #80528)

Native?

eugenis added inline comments.Dec 7 2016, 12:58 PM
test/Transforms/LowerTypeTests/function.ll
2 ↗(On Diff #80528)

as opposed to WASM, which is kind of bitcode.
We use the same terminology in LowerTypeTests.cpp.
Naming is hard. :)

rengolin added inline comments.Dec 7 2016, 1:39 PM
test/Transforms/LowerTypeTests/function.ll
2 ↗(On Diff #80528)

Right! :)

pcc added inline comments.Dec 7 2016, 2:08 PM
lib/Transforms/IPO/LowerTypeTests.cpp
654 ↗(On Diff #80528)

I suspect that we will want to land here for thumbv5, at least until/unless we have an implementation of jump tables for that architecture.

test/Transforms/LowerTypeTests/function.ll
86 ↗(On Diff #80528)

ARM: here?

eugenis added inline comments.Dec 7 2016, 3:41 PM
lib/Transforms/IPO/LowerTypeTests.cpp
654 ↗(On Diff #80528)

How do I detect thumb2 (that's what this code actually depends on)?
I don't see a way to access TargetMachine from here, and the triple alone is not enough (e.g. -mcpu=cortex-a8 enables thumb2).

eugenis updated this revision to Diff 80679.Dec 7 2016, 3:50 PM
eugenis marked an inline comment as done.
pcc accepted this revision.Dec 7 2016, 4:25 PM
pcc edited edge metadata.

LGTM

lib/Transforms/IPO/LowerTypeTests.cpp
654 ↗(On Diff #80528)

It does appear to be complicated.

Basically it looks like we will want to look up the "target-cpu" function attribute on each function in the jump table, and make sure that each target-cpu inherits the "thumb2" target feature. The backend implements some of that, but it isn't being exposed to the midend.

For the moment I think we will have to rely on the assembler rejecting the "b.w" instruction on thumb1 targets.

This revision is now accepted and ready to land.Dec 7 2016, 4:25 PM
This revision was automatically updated to reflect the committed changes.