文档章节

Position independent code and data (ROPI and RWPI)

Jr小王子
 Jr小王子
发布于 2016/08/17 17:24
字数 465
阅读 47
收藏 0

Introduction

IAR Embedded Workbench for ARM version 5.50 and later can optionally generate position-independent code and/or position-independent data.

Definition

  • ROPI = Read-Only Position Independence. This concerns everything that is readonly in the ELF output from the linker. Note that this includes const data and data initializers, i.e. typically everything that is put in FLASH.
  • RWPI = Read-Write Position Independence. This concerns everything that is readwrite in the ELF output from the linker.
  • In the present version there is also an option --pi_veneers (position independent veneers, see the Development Guide for further information)

Compiler options

The following description is an excerpt from the Development Guide:

  • Option: --ropi

    Use this option to make the compiler generate code that uses PC-relative references to address code and read-only data.

    When this option is used, these limitations apply:
    * C++ constructions cannot be used
    * The object attribute __ramfunc cannot be used
    * Pointer constants cannot be initialized with the address of another constant, a string literal, or a function. However, writable variables can be initialized to constant addresses at runtime.

    See also --no_rw_dynamic_init (below) and preprocessor symbol __ROPI__
     
  • Option: --rwpi

    Use this option to make the compiler generate code that uses the offset from the static base register (R9) to address-writable data.

    When this option is used, these limitations apply:
    * The object attribute __ramfunc cannot be used
    * Pointer constants cannot be initialized with the address of a writable variable.

    However, static writable variables can be initialized to writable variable addresses at runtime.
    See also --no_rw_dynamic_init (below) and preprocessor symbol __RWPI__
     
  • Option: --no_rw_dynamic_init

    Use this option to disable runtime initialization of static C variables. C source code that is compiled with --ropi or --rwpi cannot have static pointer variables and constants initialized to addresses of objects that do not have a known address at link time. To solve this for writable static variables, the compiler generates code that performs the initialization at program startup (in the same way as dynamic initialization in C++).

Example

In each project where ROPI/RWPI is needed, the application design and development and debugging environment will be unique. The number of different possible use cases and needs of position independent code/data are probably not possible to foresee.

It's difficult to create an exhaustive example that covers all aspects - anyway here is an example trying to show some basics of ROPI and RWPI.

Download the example and follow the instructions in readme.pdf about how to build and run. There is also a STM32F4 Discovery board example.

Note:

You will probably get build errors with newer version of IAR Embedded Workbench for ARM. The solution is to replace

static __global_reg char* rwpi_data @ "R9";

with

#if (__VER__ < 6020000)
static __global_reg char* rwpi_data @ "R9";
#else
static __no_init char* rwpi_data @ R9;
#endif

本文转载自:https://www.iar.com/support/tech-notes/compiler/ewarm-position-independent-code-and-data-ropi-and-rw

上一篇: Git 使用细节补充
下一篇: 三轴加速计
Jr小王子
粉丝 11
博文 119
码字总数 18368
作品 0
深圳
程序员
私信 提问
Go Execution Modes

Go Execution Modes Ian Lance Taylor August, 2014 Currently the gc compiler supports three execution modes: A statically linked Go binary. Default for a Go program that does not ......

LsDimplex
2015/12/31
26
0
(转) Linux下生成动态链接库是否必须使用 -fPIC 的问题

在 Linux 下制作动态链接库,“标准” 的做法是编译成位置无关代码(Position Independent Code,PIC),然后链接成一个动态链接库。经常遇到的一个问题是 -fPIC 是不是必需,因为好像不加经...

一直不灵活
2012/09/30
90
0
为什么招一个c/c++ 并且有pos项目背景的人那么难呢?

C/C++开发工程师 待遇:10k(很急,希望可以去海外出差) 工作地址:上海市金沙江 有意者可发送简历至qshi@judge.com 或加qq1933734823咨询详情。 C++ Developer Purpose – Job Summary: P...

cathy86
2012/06/06
1K
11
[RK3288][Android6.0] 调试笔记 --- X264测试程序无法使用

Platform: RK3288 OS: Android 6.0 Kernel: 3.10.92 现象: 在系统上执行example测试x264编码,提示: error: only position independent executables (PIE) are supported. 解决方法: conf......

kris_fei
2017/11/08
0
0
Android之解决java.lang.UnsatisfiedLinkError: dlopen failed: ××××.so: has text relocations

1、问题 项目导入别人的so,有个项目没问题,但是这个有问题,运行提示这个错误 java.lang.UnsatisfiedLinkError: dlopen failed: ××××.so: has text relocations 2、临时规避的解决办法 ...

u011068702
2018/03/23
0
0

没有更多内容

加载失败,请刷新页面

加载更多

uni app 零基础小白到项目实战

$emit 子组件传给父组件$ref 父组件操作子组件 公用模板 uni-app全局变量的几种实现方法 const websiteUrl = 'http'const now = Date.now || function() { return new Date().getTime......

达达前端小酒馆
33分钟前
7
0
Tomcat是如何实现异步Servlet的

前言 通过我之前的Tomcat系列文章,相信看我博客的同学对Tomcat应该有一个比较清晰的了解了,在前几篇博客我们讨论了Tomcat在SpringBoot框架中是如何启动的,讨论了Tomcat的内部组件是如何设...

木木匠
57分钟前
31
0
mysql中间件分享(Mysql-prxoy,Atlas,DBProxy,Amoeba,cobar,TDDL)

hello 各位小伙伴大家好,我是小栈君,这期我们分享关于mysql中间件的研究,也就是数据层的读写分离和负载均衡,希望能够在实际的应用中能够帮助到各位小伙伴。 下期我们将继续分享go语言的系...

IT干货栈
今天
15
0
OSChina 周一乱弹 —— 人生,还真是到处是意外

Osc乱弹歌单(2019)请戳(这里) 【今日歌曲】 @这次装个文艺青年吧 :#今日歌曲推荐# 分享lil peep的单曲《High School》 《High School》- lil peep 手机党少年们想听歌,请使劲儿戳(这里...

小小编辑
今天
1K
13
Spring使用ThreadPoolTaskExecutor自定义线程池及实现异步调用

多线程一直是工作或面试过程中的高频知识点,今天给大家分享一下使用 ThreadPoolTaskExecutor 来自定义线程池和实现异步调用多线程。 一、ThreadPoolTaskExecutor 本文采用 Executors 的工厂...

CREATE_17
今天
12
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部