Loading...
 
Skip to main content

System Workbench for STM32


generating position independent code problem on STM32F4

Dear Bernard,

thanks for your quick reply, I did not see the post (did not receive the email).

I have in my project a part I'd like to compile with the fPIC option.
I made a call to a test_function from a function in the code compiled with the fPIC option. The test_function also resides in a file compiled with the fPIC option.

Here is an excerpt of the generated assembly (copied from the disassembly view in the eclipse plugin) when using -fPIC option:

135 int ret = test_function(4);
08050802: movs r0, #4
08050804: bl 0x8050964

It appears the generated fPIC code does NOT use relative call inside the fPIC compiled module.

But maybe I have been tricked by the assembly display or do I miss something?

Thanks for your help,
Best regards,
Sylvain

France

Hi Sylvain,

As I said in my previous post, BL is ALWAYS using relative addressing; to use absolute adressing you would have to use code like this:
LD R12,=test_function
BLX R12
where the first instruction will in turn be displayed in disassembly as two instruction: a MOVW #xxxx to load the 16 lsb (setting the msb to 0) and a MOVT #xxxx to load the 16 msb

Thus the code you show is indeed using relative addressing, so is perfectly valid in PIC mode.

Bernard (Ac6)