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

Kyrill Tkachov kyrylo.tkachov@foss.arm.com
Fri Feb 12 09:30:00 GMT 2016


Hi,

On 12/02/16 09:19, Umesh Kalappa wrote:
> Hi Guys ,
>
> we  do have a issue with below code ,When we enabled the pie (-fpie/pie)  option
>   i.e
>
> main.c
> extern int *my_ptr ;
>
> int main()
> {
>     return *my_ptr;
> }
>
> foo.s
>   .syntax unified
>   .cpu cortex-m0
>   .fpu softvfp
>    .thumb
>    .global my_ptr
>     .global my_var
>      .data
>      .align  2
>     .type   my_ptr, %object
>     .size   my_ptr, 4
> my_ptr:
>    .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
>        4
>        5 arm-none-eabi-gcc -c -fPIC foo.S -mthumb -mcpu=cortex-m0
>        6 arm-none-eabi-gcc -c -fPIC
> /home/egoumal/Downloads/gcc-arm-none-eabi-5_2-2015q4/share/gcc-arm-none-eabi/samples/startup/startu
>         p_ARMCM0.S -mthumb -mcpu=cortex-m0 -D__STARTUP_CLEAR_BSS
> -D__START=main
>        7
>        8 arm-none-eabi-ld -pie main.o  foo.o startup_ARMCM0.o -L.
> -L/home/egoumal/Downloads/gcc-arm-none-eabi-5_2-2015q4/share/gcc-ar
>      m-none-eabi/samples/ldscripts -T nokeep.ld -Map=test.map -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)

note that gcc-bugs is the list where the automatic bug tracker sends all the emails
logging almost all activity, so your email would be lost there...
Please file a bug report in bugzilla according to https://gcc.gnu.org/bugs/

Thanks,
Kyrill

>
> Thank you and appreciate any lights on this
> ~Umesh
>



More information about the Gcc mailing list