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

Which Clang/GCC linker flag should be used to produce offsets in code that stay within the binary range?

$
0
0

I'm trying to link my code with an external static library, that has this piece of code in the binary:

0000000000000000 <some_method>:   0:         48 8d 05 00 00 00 00      lea    0x0(%rip),%rax        # 7 <some_method+0x7>   7:         c3                        retq  

After linking with my code, the linker writes an actual offset instead of the zeroes:

00000000000175c0 <some_method>:   175c0:       48 8d 05 39 aa 20 00    lea    0x20aa39(%rip),%rax        # 222000 <some_method.method>   175c7:       c3                      retq 

Offset 222000 is supposed to be in the .data section according to the readelf output, which is supposed to be OK, but the problem is that I need to copy my binary code "as is" into some memory space and make it run from there, without using any OS loaders that know how to relocate different sections of the binary in the process address space. The memory address to which I load my binary can change too, so I can't use static non-relative offsets in my code either.

I want all my RIP-relative offsets in the code to be only within the binary file size range, so for example if my binary is 0x10000 bytes size, and I load it at address 0x200000, I don't want any offsets to go beyond the address 0x210000. Is there a way to tell the linker to do that somehow?


Viewing all articles
Browse latest Browse all 22077

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>