summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorOliver Stannard <oliver.stannard@arm.com>2016-08-08 15:28:40 +0000
committerOliver Stannard <oliver.stannard@arm.com>2016-08-08 15:28:40 +0000
commit218c4cbd3d7c72e71bc1c33f16d0a30c9abaa7b6 (patch)
treec6850f6e4afe825d030654659fe5a01fa64082d5 /clang/lib/CodeGen
parent8331aaee8fb9172ddf0cb45c4b04cb76fe224da4 (diff)
downloadbcm5719-llvm-218c4cbd3d7c72e71bc1c33f16d0a30c9abaa7b6.tar.gz
bcm5719-llvm-218c4cbd3d7c72e71bc1c33f16d0a30c9abaa7b6.zip
[ARM] Command-line options for embedded position-independent code
This patch (with the corresponding ARM backend patch) adds support for some new relocation models: * Read-only position independence (ROPI): Code and read-only data is accessed PC-relative. The offsets between all code and RO data sections are known at static link time. * Read-write position independence (RWPI): Read-write data is accessed relative to a static base register. The offsets between all writeable data sections are known at static link time. These two modes are independent (they specify how different objects should be addressed), so they can be used individually or together. These modes are intended for bare-metal systems or systems with small real-time operating systems. They are designed to avoid the need for a dynamic linker, the only initialisation required is setting the static base register to an appropriate value for RWPI code. There is one C construct not currently supported by these modes: global variables initialised to the address of another global variable or function, where that address is not known at static-link time. There are a few possible ways to solve this: * Disallow this, and require the user to write their own initialisation function if they need variables like this. * Emit dynamic initialisers for these variables in the compiler, called from the .init_array section (as is currently done for C++ dynamic initialisers). We have a patch to do this, described in my original RFC email (http://lists.llvm.org/pipermail/llvm-dev/2015-December/093022.html), but the feedback from that RFC thread was that this is not something that belongs in clang. * Use a small dynamic loader to fix up these variables, by adding the difference between the load and execution address of the relevant section. This would require linker co-operation to generate a table of addresses that need fixing up. Differential Revision: https://reviews.llvm.org/D23196 llvm-svn: 278016
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/BackendUtil.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index ca7aec0ba81..7133bda99a1 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -525,6 +525,12 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
RM = llvm::Reloc::Static;
} else if (CodeGenOpts.RelocationModel == "pic") {
RM = llvm::Reloc::PIC_;
+ } else if (CodeGenOpts.RelocationModel == "ropi") {
+ RM = llvm::Reloc::ROPI;
+ } else if (CodeGenOpts.RelocationModel == "rwpi") {
+ RM = llvm::Reloc::RWPI;
+ } else if (CodeGenOpts.RelocationModel == "ropi-rwpi") {
+ RM = llvm::Reloc::ROPI_RWPI;
} else {
assert(CodeGenOpts.RelocationModel == "dynamic-no-pic" &&
"Invalid PIC model!");
OpenPOWER on IntegriCloud