Is there a way for gcc to generate %pc relative constant addresses? Even when a line appears in the text segment, arm-elf-gcc generates a constant pointer to the data, loads the pointer address through the relative address %pc , and then plays it out. For various reasons, I need to skip the middle step. For example, this simple function:
const char * filename(void) { static const char _filename[] __attribute__((section(".text"))) = "logfile"; return _filename; }
generates (when compiling with arm-elf-gcc-4.3.2 -nostdlib -c -O3 -W -Wall logfile.c ):
00000000 <filename>: 0: e59f0000 ldr r0, [pc, #0] ; 8 <filename+0x8> 4: e12fff1e bx lr 8: 0000000c .word 0x0000000c 0000000c <_filename.1175>: c: 66676f6c .word 0x66676f6c 10: 00656c69 .word 0x00656c69
I would expect it to generate something more:
filename: add r0, pc, #0 bx lr _filename.1175: .ascii "logfile\000"
This code should be partially position-independent, as it will be moved to memory at boot time, but also integrated with code that was not compiled by -fPIC , so there is no global offset table.
My current job is to call the non-inline function (which will be done using the relative address %pc ) to find the offset from the compiled location in a method similar to how -fPIC code works:
static intptr_t __attribute__((noinline)) find_offset( void ) { uintptr_t pc; asm __volatile__ ( "mov %0, %%pc" : "=&r"(pc) ); return pc - 8 - (uintptr_t) find_offset; }
But this method requires that the links to all data be fixed manually, so the filename() function in the above example will become:
const char * filename(void) { static const char _filename[] __attribute__((section(".text"))) = "logfile"; return _filename + find_offset(); }
gcc arm fpic
Hudson
source share