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.