This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PIE/PIC issue ...w.r.t linker variable

Hi Guys ,

we  do have a issue with below code ,When we enabled the pie (-fpie/pie)  option

extern int *my_ptr ;

int main()
   return *my_ptr;

 .syntax unified
 .cpu cortex-m0
 .fpu softvfp
  .global my_ptr
   .global my_var
    .align  2
   .type   my_ptr, %object
   .size   my_ptr, 4
  .word   my_var   //where my_var is the linker variable

custom.ld  (linker script)
/* Set stack top to end of RAM, and stack limit move down by
    190      * size of stack_dummy section */
    191     my_var = 20;
    192     __StackTop = ORIGIN(RAM) + LENGTH(RAM);
    193     __StackLimit = __StackTop - SIZEOF(.stack_dummy);
    194     PROVIDE(__stack = __StackTop);

command used

      3  arm-none-eabi-gcc -c -fPIC main.c -mthumb -mcpu=cortex-m0
      5 arm-none-eabi-gcc -c -fPIC foo.S -mthumb -mcpu=cortex-m0
      6 arm-none-eabi-gcc -c -fPIC
       p_ARMCM0.S -mthumb -mcpu=cortex-m0 -D__STARTUP_CLEAR_BSS
      8 arm-none-eabi-ld -pie main.o  foo.o startup_ARMCM0.o -L.
    m-none-eabi/samples/ldscripts -T nokeep.ld -o test

we expect my_ptr value to be 20 ,but we do see the value 0 and without
pie option ,the my_ptr has the value 20 .

do we missing something here  or value 0 expected (which is incorrect)

Thank you and appreciate any lights on this

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]