]> git.lizzy.rs Git - rust.git/commit
Auto merge of #41560 - alevy:rwpi-ropi, r=eddyb
authorbors <bors@rust-lang.org>
Mon, 1 May 2017 17:23:09 +0000 (17:23 +0000)
committerbors <bors@rust-lang.org>
Mon, 1 May 2017 17:23:09 +0000 (17:23 +0000)
commit4cb396c68088f38e517ac8890030d17a969e57ba
treedea3eba114d236e5390140b1e6fd3bbbfa71a3bf
parent526d39948af4004bb60c04dc82d60b7b395966bb
parent0f00f27e0d4743b14f7c0d0fca9731a45eae487a
Auto merge of #41560 - alevy:rwpi-ropi, r=eddyb

Add RWPI/ROPI relocation model support

This PR adds support for using LLVM 4's ROPI and RWPI relocation models for ARM.

ROPI (Read-Only Position Independence) and RWPI (Read-Write Position Independence) are two new relocation models in LLVM for the ARM backend ([LLVM changset](https://reviews.llvm.org/rL278015)). The motivation is that these are the specific strategies we use in userspace [Tock](https://www.tockos.org) apps, so supporting this is an important step (perhaps the final step, but can't confirm yet) in enabling userspace Rust processes.

## Explanation

ROPI makes all code and immutable accesses PC relative, but not assumed to be overriden at runtime (so for example, jumps are always relative).

RWPI uses a base register (`r9`) that stores the addresses of the GOT in memory so the runtime (e.g. a kernel) only adjusts r9 tell running code where the GOT is.

## Complications adding support in Rust

While this landed in LLVM master back in August, the header files in `llvm-c` have not been updated yet to reflect it. Rust replicates that header file's version of the `LLVMRelocMode` enum as the Rust enum `llvm::RelocMode` and uses an implicit cast in the ffi to translate from Rust's notion of the relocation model to the LLVM library's notion.

My workaround for this currently is to replace the `LLVMRelocMode` argument to `LLVMTargetMachineRef` with an int and using the hardcoded int representation of the `RelocMode` enum. This is A Bad Idea(tm), but I think very nearly the right thing.

Would a better alternative be to patch rust-llvm to support these enum variants (also a fairly trivial change)?
src/rustllvm/PassWrapper.cpp