Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22176

What flags should I pass to objcopy to relocate a PIE (relocatable position-independent executable) ELF to a specific memory address?

$
0
0

The embedded project I'm working on uses the ld linker flag -pie to create a position-independent executable ELF. As part of the testing, I want to use objcopy to create a binary from the PIE ELF where the .text and .data sections have been relocated to a specific address in memory, e.g.

objcopy -v -O binary [extra-flags-go-here] relocatablefile.elf staticaddressfile.bin

However, none of the plausible-looking objcopy option flags I've tried seem to achieve this relocation:

--change-addresses 0x20000--image-base 0x20000--change-section-vma     .text=0x20000--change-section-address .text=0x20000

So, is objcopy able to relocate sections of a relocatable ELF to a given address? And if so, how? Thanks very much!

PS: I'm compiling with -fpie, linking with -pie -n -shared, and all the sections in the elf file seem to be as you'd expect. I'm examining the output binary with HxD.


Viewing all articles
Browse latest Browse all 22176