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.