文档章节

Position independent code and data (ROPI and RWPI)

Jr小王子
 Jr小王子
发布于 2016/08/17 17:24
字数 465
阅读 27
收藏 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
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
C++ 异常堆栈跟踪器--libcsdbg

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

红薯
2013/11/06
6.6K
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

没有更多内容

加载失败,请刷新页面

加载更多

下一页

[MicroPython]STM32F407开发板驱动OLED液晶屏

1.实验目的 1.学习在PC机系统中扩展简单I/O 接口的方法。 2.进一步学习编制数据输出程序的设计方法。 3.学习 F407 Micropython开发板控制OLED显示字符。 2.所需元器件 F407 Micropython开发板...

bodasisiter
30分钟前
0
0
php require和include 相对路径一个有趣的坑

以前总是被教育,不要使用相对路径,这样性能比较差,但是相对路径的问题不仅仅是性能哦,看下面这里例子 这是项目结构 .├── main.php├── t│ ├── t1.php│ └── t2.php└─...

anoty
31分钟前
15
0
x64技术之SSDT_Hook

测试环境: 虚拟机: Windows 7 64bit 过PG工具 驱动加载工具 PCHunter64 系统自带的计算器和任务管理器等 实现思路: 实际思路与win32的思路一样.都是替换SSDT表里边的函数地址.不过微软被搞怕...

simpower
32分钟前
0
0
TreeMap源码分析,看了都说好

一、简介 TreeMap最早出现在JDK 1.2中,是 Java 集合框架中比较重要一个的实现。TreeMap 底层基于红黑树实现,可保证在log(n)时间复杂度内完成 containsKey、get、put 和 remove 操作,效率很...

Java小铺
42分钟前
0
0
协变、逆变

概念 假设 A、B表示类型 ≤ 表示继承关系 f<⋅>表示类型转换 若A ≤ B,则 A是B的子类,B是A的超类 协变、逆变 什么是型变?型变(type variance)允许对类型进行子类型转换。 为了下面讲解先...

obaniu
48分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部