linker - Mac OSX ld report 32-bit RIP relative reference out of range error for Absolute symbol -
i'm trying combine objcopy
clang toolchain. because objcopy
of binutils 2.25 generates broken mach-o object file, edit generated object file using my shell script.
$ objcopy-comp.sh -i binary -o mach-o-x86-64 test test.o $ nm test.o 000000000000000b d _binary_test_end 000000000000000b _binary_test_size 0000000000000000 d _binary_test_start
however, link against c code fails error message.
$ clang main.c test.o ld: 32-bit rip relative reference out of range (-4294971146 max +/-4gb): _main (0x100000ea0) _binary_test_size (0x0000000b) in '_main' main.o architecture x86_64
(newlines inserted readbility)
here main.c.
#include <stdio.h> #include <stdlib.h> #include <string.h> extern const unsigned char binary_test_start[]; extern const unsigned char binary_test_end[]; extern const unsigned char binary_test_size[]; int main(int argc, char *argv[]) { size_t len = binary_test_end - binary_test_start; char *data = calloc(len + 1, sizeof(char)); memcpy(data, binary_test_start, len); data[len] = 0; printf("%s %ld %d\n", data, len, (int)binary_test_size); return 0; }
n_abs (0x2)—the symbol absolute. linker not change value of absolute symbol.
but error message suggests linker try change value.
how protect absolute value linker?
the mach-o
abi utilizes relative addressing x86_64
. compiler interprets address you've used 32-bit
out range, nor absolute. try compiling code i386
, might have better chance of success.
specifically how you're changing symbol types unknown since haven't shown commands you've used objcopy
.
Comments
Post a Comment