文档章节

Position independent code and data (ROPI and RWPI)

Jr小王子
 Jr小王子
发布于 2016/08/17 17:24
字数 465
阅读 30
收藏 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
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/c++ 并且有pos项目背景的人那么难呢?

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

cathy86
2012/06/06
1K
11
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

没有更多内容

加载失败,请刷新页面

加载更多

Cookie 显示用户上次访问的时间

import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServlet;import javax.serv......

gwl_
今天
1
0
网络编程

第14天 网络编程 今日内容介绍  网络通信协议  UDP通信  TCP通信 今日学习目标  能够辨别UDP和TCP协议特点  能够说出UDP协议下两个常用类名称  能够说出TCP协议下两个常用类名称...

stars永恒
今天
1
0
二进制相关

二进制 众所周知计算机使用的是二进制,数字的二进制是如何表示的呢? 实际就是逢二进一。比如 2 用二进制就是 10。那么根据此可以推算出 5的二进制等于 10*10+1 即为 101。 在计算机中,负数以...

NotFound403
昨天
3
0
day22:

1、写一个getinterface.sh 脚本可以接受选项[i,I],完成下面任务: 1)使用格式:getinterface.sh [-i interface | -I ip] 2)当用户使用-i选项时,显示指定网卡的IP地址;当用户使用-I选项...

芬野de博客
昨天
2
0
Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现

自Spring Cloud Alibaba发布第一个Release以来,就备受国内开发者的高度关注。虽然Spring Cloud Alibaba还没能纳入Spring Cloud的主版本管理中,但是凭借阿里中间件团队的背景,还是得到不少...

程序猿DD
昨天
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部