public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Position-independent code; fixed-address data and bss
@ 2015-07-07 17:45 Christopher Collins
  0 siblings, 0 replies; only message in thread
From: Christopher Collins @ 2015-07-07 17:45 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-07-07 17:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-07 17:45 Position-independent code; fixed-address data and bss Christopher Collins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).