Suppose that in a bare-metal(arm-none-eabi-gcc) arm v5 environment where functions are stored at fixed locations and the underlying 'application' can only access the functions through absolute address. So, a function is defined as:
.type name, %function; \
.extern name; \
.equ name,0x400099
which can be invoked from the C code like this name(args);
however,due to the nature of the shared binary(compiled as -fPIE), the resulting veneer produced is the following:
00012294 <name_veneer>:
00012294 ldr r12,[DAT_0001229c]
00012298 add pc=>LAB_412331,pc,r12
0001229c .word 400099h
Where the linker adds the current location of PC to the final destination which is incorrect and instead something like following is preferred:
00012294 <name_veneer>:
00012294 ldr r12,[DAT_0001229c]
00012298 mov pc,r12
0001229c .word 400099h
System information
- The underlying application has an unknown entry point during run time, hence the need for PIE.
- The application is loaded from network for debugging purposes.
- The SOC containing the CPU is a proprietary design.