ld

Linker error when calling printf from _start [duplicate]

浪尽此生 提交于 2020-06-09 04:17:06
问题 This question already has answers here : Assembling 32-bit binaries on a 64-bit system (GNU toolchain) (2 answers) Closed 3 years ago . I tried to write simple program without main segment .data fmt db "test", 0xa, 0 segment .text global _start extern printf _start: lea rdi, [fmt] ; print simple string xor eax, eax call printf mov eax, 60 ; exit successfully xor edi, edi syscall Compile: yasm -f elf64 main.s; ld -o main main.o Got main.o: In function `_start': main.s:(.text+0xb): undefined

ld64 segprot on MacOS Catalina not working?

ⅰ亾dé卋堺 提交于 2020-06-01 04:06:04
问题 I want to create a binary on MacOS Catalina (64 bit) with a data segment that can be made executable (see here for details) but is not executable from the start. I make my binary with gcc -nostdlib -segprot __DATA rwx rw- .... I also created an object file with gcc and then called ld directly. The ld version is $ ld -v @(#)PROGRAM:ld PROJECT:ld64-530 BUILD 18:57:17 Dec 13 2019 configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m

ld64 segprot on MacOS Catalina not working?

感情迁移 提交于 2020-06-01 04:03:07
问题 I want to create a binary on MacOS Catalina (64 bit) with a data segment that can be made executable (see here for details) but is not executable from the start. I make my binary with gcc -nostdlib -segprot __DATA rwx rw- .... I also created an object file with gcc and then called ld directly. The ld version is $ ld -v @(#)PROGRAM:ld PROJECT:ld64-530 BUILD 18:57:17 Dec 13 2019 configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m

unable to compile: unrecognized relocation 0x2a in section text

假装没事ソ 提交于 2020-05-29 03:16:17
问题 I have received an error message when compiled "make" $ make g++ -fopenmp -o lang.test main.o -I../../../include/Lheader -I../../../include -L../../../lib/ -llmi -lblas -lboost_regex -lpthread -lleveldb /usr/bin/ld: ../../../lib//liblmi.a(LMInterface.o): unrecognized relocation (0x2a) in section `.text' /usr/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status I cannot find any solution for above problem. GCC version and ld version are like these: $ gcc --version

unable to compile: unrecognized relocation 0x2a in section text

浪子不回头ぞ 提交于 2020-05-29 03:16:09
问题 I have received an error message when compiled "make" $ make g++ -fopenmp -o lang.test main.o -I../../../include/Lheader -I../../../include -L../../../lib/ -llmi -lblas -lboost_regex -lpthread -lleveldb /usr/bin/ld: ../../../lib//liblmi.a(LMInterface.o): unrecognized relocation (0x2a) in section `.text' /usr/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status I cannot find any solution for above problem. GCC version and ld version are like these: $ gcc --version

Why doesn't a linked binary file's _size symbol work correctly?

橙三吉。 提交于 2020-05-15 17:53:27
问题 I use 'ld -r -b binary -o binary.o foo.jpeg' to embed resources in my program. Works awesomely. I just wonder why the int _binary_size symbol never reads correctly, negative or too large a number, but stays the same between program runs. I always gotta do _binary_end - _binary_start, which works flawlessly. It's seems it works for no one... like here .... why is that? There is no reason not to use end-start as it replaces the size symbol, but it still leaves me curious. edit: code example.

Why doesn't a linked binary file's _size symbol work correctly?

妖精的绣舞 提交于 2020-05-15 17:53:11
问题 I use 'ld -r -b binary -o binary.o foo.jpeg' to embed resources in my program. Works awesomely. I just wonder why the int _binary_size symbol never reads correctly, negative or too large a number, but stays the same between program runs. I always gotta do _binary_end - _binary_start, which works flawlessly. It's seems it works for no one... like here .... why is that? There is no reason not to use end-start as it replaces the size symbol, but it still leaves me curious. edit: code example.

How to prevent “main.o:(.eh_frame+0x1c): relocation truncated to fit: R_AARCH64_PREL32 against `.text'” when creating an aarch64 baremetal program?

三世轮回 提交于 2020-04-07 07:39:53
问题 When playing with creating baremetal executables, I hit this error: main.o:(.eh_frame+0x1c): relocation truncated to fit: R_AARCH64_PREL32 against `.text' collect2: error: ld returned 1 exit status I then managed to create a minimal reproduction example: main.c void _start(void) {} notmain.S .skip 32 link.ld ENTRY(_start) SECTIONS { .text : { */bootloader.o(.text) *(.text) *(.rodata) *(.data) *(COMMON) } .bss : { *(.bss) } heap_low = .; . = . + 0x1000000; heap_top = .; . = . + 0x1000000;

How to prevent “main.o:(.eh_frame+0x1c): relocation truncated to fit: R_AARCH64_PREL32 against `.text'” when creating an aarch64 baremetal program?

那年仲夏 提交于 2020-04-07 07:39:30
问题 When playing with creating baremetal executables, I hit this error: main.o:(.eh_frame+0x1c): relocation truncated to fit: R_AARCH64_PREL32 against `.text' collect2: error: ld returned 1 exit status I then managed to create a minimal reproduction example: main.c void _start(void) {} notmain.S .skip 32 link.ld ENTRY(_start) SECTIONS { .text : { */bootloader.o(.text) *(.text) *(.rodata) *(.data) *(COMMON) } .bss : { *(.bss) } heap_low = .; . = . + 0x1000000; heap_top = .; . = . + 0x1000000;

Can't link a shared library from an x86-64 object from assembly because of PIC

女生的网名这么多〃 提交于 2020-03-14 14:50:35
问题 I'm porting a shared library from 32-bit to 64-bit. It's composed of some assembly (written for NASM) that exports several procedures and a little bit of higher-level C glue code. I'm building on a 64-bit Debian machine with NASM 2.10.01 and GNU ld 2.22. Having fixed all the push/pop issues (pushing 32-bit parts of registers obviously won't work in 64-bit mode), I've got the object to assemble, but now I'm halted by the linking stage. Here are my command lines - assembly: nasm -Ox -dPTC_ARCH