文档章节

Position independent code and data (ROPI and RWPI)

Jr小王子
 Jr小王子
发布于 2016/08/17 17:24
字数 465
阅读 28
收藏 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

共有 人打赏支持
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
8
0
(转) Linux下生成动态链接库是否必须使用 -fPIC 的问题

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

一直不灵活
2012/09/30
0
0
[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
C++ 异常堆栈跟踪器--libcsdbg

libcsdbg 是一个 C++ 异常堆栈跟踪器。当异常被抛出、捕获和处理时,libcsdbg 提供可工具来创建和处理异常堆栈的跟踪,并通过调用堆栈来传播异常路径。跟踪器提供异常发生的函数以及额外的 ...

红薯
2013/11/06
6.6K
0
Android之解决java.lang.UnsatisfiedLinkError: dlopen failed: ××××.so: has text relocations

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

u011068702
03/23
0
0

没有更多内容

加载失败,请刷新页面

加载更多

linux使用ntfs-3g操作ntfs格式硬盘

Linux内核目前只支持对微软NTFS文件系统的读取。 NTFS-3G 是微软 NTFS 文件系统的一个开源实现,同时支持读和写。NTFS-3G 开发者使用 FUSE 文件系统来辅助开发,同时对可移植性有益。 安装 ...

linuxprobe16
51分钟前
1
0
kubeadm部署kubernetes集群

一、环境要求 这里使用RHEL7.5 master、etcd:192.168.10.101,主机名:master node1:192.168.10.103,主机名:node1 node2:192.168.10.104,主机名:node2 所有机子能基于主机名通信,编辑...

人在艹木中
今天
7
0
Shell特殊符号总结以及cut,sort,wc,uniq,tee,tr,split命令

特殊符号总结一 * 任意个任意字符 ? 任意一个字符 # 注释字符 \ 脱义字符 | 管道符 # #号后的备注被忽略[root@centos01 ~]# ls a.txt # 备注 a.txt[root@centos01 ~]# a=1[root@centos01...

野雪球
今天
2
0
OSChina 周二乱弹 —— 程序员圣衣

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @达尔文:分享Skeeter Davis的单曲《The End of the World》 《The End of the World》- Skeeter Davis 手机党少年们想听歌,请使劲儿戳(这里...

小小编辑
今天
17
0
[ python import module ] 导入模块

import moudle_name ----> import module_name.py ---> import module_name.py文件路径 -----> sys.path (这里进行查找文件) # from app.web import Personimport app.web.Person as Pe......

_______-
昨天
5
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部