cgccarmldcortex-a8

Why doesn't -fpie work in bare-metal codes and cause wild pointer?


I'm using S5PV210 which based on cortex-A8.It starts with an initialaztion and then jump to 0x20000000 of SDRAM and run my codes. So i just need to put my main function onto 0x20000000.

As far as i know, there're two ways to do it.The first is to use -Ttext=0x20000000 to make .text start at 0x20000000. And the second is to use -fpie -pie to generate position independent codes.And i'm using the latter.

It works most of time, but i got stuck at one of my project. The symptom is that printf("123") will print everlasting messy codes and never return.If i switch back to use -Ttext=0x20000000, then it will work all right.

I've tried some steps to analyst it:

  1. change my main function just call one printf so that my codes don't call any other functions,like this:

    int main(){ printf("123"); while(1); return 0; }

  2. because -fpie -pie work very well the most of time , I started to comment some other functions, and finally found that if i comment enough codes, the printf will work again.

Now i'm confused, are -fpie and -pie really work?


Solution

  • OK. I made a stupid mistake. The the initialization will copy my codes from NAND into SDRAM, and it has a limit size of 5kb.....