I’m trying to get a position independent executable (PIE) for simple embedded application (led blinking) that uses SDK. The application runs on EVB equipped with S32K311. I’m using IDE S32DS 3.5 and I’ve set the gcc option -fPIC, -fPIE for compiler and -pie for the linker and I’ve modified the linker script in order to place the got table. However the generated executable doesn’t work as PIE. It means that if I try to load it in an address other than the one for which it was built, it doesn’t work anymore.
In order to investigate the issue, I did some analysis about the generated .elf file with readelf commands. Following I summarize the results:
File Type is “EXEC” (Should be type “DYN”?)
Entry point address is an absolute address while an offset is expected
On the other hand, I’ve found some features related to a PIC/PIE executable:
In the Program Header there is a dynamic interpreter:
INTERP 0x011140 0x00401140 0x00401140 0x00011 0x00011 R 0x1
[Requesting program interpreter: /usr/lib/ld.so.1]
Section FLAGS_1 value: PIE
Section .rel.dyn exists and contains several items (more than 300) type R_ARM_RELATIVE
Section .got present
Can anyone help me to understand what is the problem? Why the executable .elf is not "DYN" although the -fPIC, -fPIE -pie options have been set in the IDE? Is the Type "DYN" really mandatory instead of "EXEC" to be a position independent executable? In attached the .elf file. Furthermore, why I cannot find the options -fPIC -fPIE neither in the makefile (automatically generated) nor in the relative .args file? While -pie is present in .args file I can find -fPIC -fPIE only in .cproject file. So, are those options really applied? In attached you can find my whole project.
I also tried to set the -shared option, but it doesn't affect the .elf file.
Note: I've already had a look at the picExample:
EXAMPLE S32K144 Position Independent Code - NXP Community
but there are some differences: it refers to a previous IDE version, different micro family (S32K1xx)and the used application is without SDK.
Many thanks in advance for supporting.
Hi @FabrikSal
According to the software team, the RTD driver has not been verified with the PIC and is not intended for integration with it. However, if RTDs are not part of your plans, you may find helpful information in the community threads where this topic has been discussed.
What are the Steps after activating Position Independ Code (PIC) for A/B Swaping?
How to create flash driver for S32K3xx as independent position code
Hi @FabrikSal
Based on the information provided by our internal team, the functionality you are requesting will not work without an operating system that supports it. As previously mentioned, this feature is typically related to Linux OS and is generally used in the development of desktop applications running under such an OS environment.
Unfortunately, we do not have any additional information, resources, or documentation available for this specific application. Therefore, the implementation and functionality of the feature will be entirely dependent on your own development and how you choose to implement it within your system.
Hi @FabrikSal
While PIE is commonly used in general-purpose computing environments (e.g., Linux), its application in embedded systems or microcontroller development is less frequent due to the constraints of these environments.
Unfortunately, we do not have a working example for creating a Position-Independent Executable (PIE) in this context.
BR, VaneB