Building a position independent binary with position independent data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I'm trying to build a position independent binary with position
independent data for an embedded system (ARM). And with binary I mean
a flat binary, not an ELF file. There is no dynamic linker or elf
loader that can do reloactions and the binary must work no matter
where it gets loaded.

That means I can't have a GOT with absolute addresses or PLT stubs
with absolute jumps or a dyn.rel section which the elf loader is
supposed to use to fix up a binary to its real loaction. The binary
has to work as is when mapped to different virtual addresses in
different processes.

On the plus side I'm fine with using whole-program or LTO optimization
and all sections can be at fixed offsets from each other (preferably
page aligned one after the other actually). So all data access and
jumps can be PC relative without problems and I had some success using
-pie -flto.

But how do I get gcc to store static data in a PC relative form? For
example this structure:

void foo(void);
typedef void fn(void);
struct Bar {
  fn * baz;
};

struct Bar bar = { foo };

This causes the absolute address of foo to be stored in the .data
section, which then has to be relocated dynamically at load time. Is
there a gcc option to store a realtive offset (e.g. relative to the
address where the struct is or relative to the .text section) for such
pointers?

Or do I have to avoid storing any such structures as static data and
build them dynamically at runtime?

MfG
	Goswin




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux