[llvm-branch-commits] [ARM, MC] Support FDPIC relocations (PR #82187)

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 21 09:40:47 PST 2024


MaskRay wrote:

> Thanks for the update, I'm happy with the changes. I would like to see more options for position independent code in embedded systems.
> 
> The other related embedded position independent option for microcontrollers that I'm aware of is `-fropi` and `-frwpi` which is already implemented in clang. This is relocation free with just one static data area accessed as an offset from r9. It works quite well for C code, but doesn't support C++ (vtables and RTTI need relocations) and some forms of static initialisation.

Thanks for the comment. [ROPI/RWPI](https://lists.llvm.org/pipermail/llvm-dev/2015-December/093022.html) seems similar to -mno-pic-data-is-text-relative.

In 2013, -mno-pic-data-is-text-relative, generalized from the ARM [VxWorks RTP](https://gcc.gnu.org/pipermail/gcc-patches/2007-May/217111.html) port, was [added](https://inbox.sourceware.org/gcc-patches/000001cedf74$bd1bf710$3753e530$@arm.com/) to assume that text and data segments don't have a fixed displacement. On non-VxWorks-RTP targets, -mno-pic-data-is-text-relative implies [-msingle-pic-base](https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html#index-msingle-pic-base):

Treat the register used for PIC addressing as read-only, rather than loading it in the prologue for each function. The runtime system is responsible for initializing this register with an appropriate value before execution begins.

r9 is used as the static base (`arm_pic_register) in the position-independent data model to access the data segment. Since r9 is not changed, dynamic linking seems unsupported as a DSO needs a different data segment.

https://github.com/llvm/llvm-project/pull/82187


More information about the llvm-branch-commits mailing list