This is the mail archive of the gcc-help@gcc.gnu.org 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]

Position-independent code; fixed-address data and bss


MCU: STM32F4 (ARM Cortex M4)
Build environment: arm-none-eabi-gcc 4.8.4 20140725

My goal is to build an image that can be run from any properly-aligned
offset in internal flash (i.e., position-independent).  I found the
following set of gcc flags that achieves this goal:

    # Generate position independent code.
    -fPIC

    # Access bss via the GOT.
    -mno-pic-data-is-text-relative

    # GOT is not PC-relative; store GOT location in a register.
    -msingle-pic-base

    # Store GOT location in r9.
    -mpic-register=r9

This works, but now I am wondering if there is a way to reduce the size
of the resulting binary.  In particular, the above flags cause all
global variables to be accessed via the global offset table (GOT).
However, I don't need this extra indirection, because the data and bss
sections will always be at fixed offsets in SRAM.  The only part of the
image that needs to be position independent is the code itself.
Ideally, I would like to gcc to treat all accesses to global variables
as though it weren't generating position-independent code.

Any ideas?  All input is greatly appreciated.

Thanks,
Chris


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