ld

How can I link dynamically to glibc in Ubuntu

不羁岁月 提交于 2021-02-10 05:00:10
问题 I am trying to assemble and link this tiny x86 assembly code in Linux (Ubuntu 18.04 LTS): ;hello.asm global _start extern scanf, printf, exit section .data read_name db '%255s', 0 msg db 'Hello, %s', 0 section .text _start: sub esp, 256 push esp push read_name call scanf add esp, 8 push esp push msg call printf add esp, 264 push dword 0 call exit I am using nasm to assemble and ld to link. As you can probably tell, the code uses C functions, so it has to be linked to glibc . Since my code is

How can I link dynamically to glibc in Ubuntu

百般思念 提交于 2021-02-10 04:59:07
问题 I am trying to assemble and link this tiny x86 assembly code in Linux (Ubuntu 18.04 LTS): ;hello.asm global _start extern scanf, printf, exit section .data read_name db '%255s', 0 msg db 'Hello, %s', 0 section .text _start: sub esp, 256 push esp push read_name call scanf add esp, 8 push esp push msg call printf add esp, 264 push dword 0 call exit I am using nasm to assemble and ld to link. As you can probably tell, the code uses C functions, so it has to be linked to glibc . Since my code is

Binutils LD creates huge files

让人想犯罪 __ 提交于 2021-02-09 11:12:46
问题 I'm trying to create as small ELF as possible. I created a test file like this (NASM syntax): SECTION .text dd 0xdeadbeef With this linker script: SECTIONS { .text : { *(.text) } } Then I checked sizes of flat binary and ELFs built two ways: nasm -f bin -o test test.asm It's flat binary, so 4 bytes. nasm -f elf -o test.o test.asm i686-elf-ld -Tlinker.ld test.o -o test I'd expect something like 500 bytes max, but the resulting file is 4396 bytes long! There is an option however, named --strip

Binutils LD creates huge files

不问归期 提交于 2021-02-09 11:12:05
问题 I'm trying to create as small ELF as possible. I created a test file like this (NASM syntax): SECTION .text dd 0xdeadbeef With this linker script: SECTIONS { .text : { *(.text) } } Then I checked sizes of flat binary and ELFs built two ways: nasm -f bin -o test test.asm It's flat binary, so 4 bytes. nasm -f elf -o test.o test.asm i686-elf-ld -Tlinker.ld test.o -o test I'd expect something like 500 bytes max, but the resulting file is 4396 bytes long! There is an option however, named --strip

Binutils LD creates huge files

安稳与你 提交于 2021-02-09 11:11:23
问题 I'm trying to create as small ELF as possible. I created a test file like this (NASM syntax): SECTION .text dd 0xdeadbeef With this linker script: SECTIONS { .text : { *(.text) } } Then I checked sizes of flat binary and ELFs built two ways: nasm -f bin -o test test.asm It's flat binary, so 4 bytes. nasm -f elf -o test.o test.asm i686-elf-ld -Tlinker.ld test.o -o test I'd expect something like 500 bytes max, but the resulting file is 4396 bytes long! There is an option however, named --strip

Instructions appended to end of assembly

孤者浪人 提交于 2021-02-09 09:21:46
问题 I am trying to follow this tutorial for creating a binary file, but the linker appears to be appending additional instructions at the end of the assembly. I assume this is the OS's tear-down process. The tutorial attempts to compile a bare bones 32-bit C program on Linux: int main() { } using these commands: gcc -c test.c ld -o test -Ttext 0x0 -e main test.o objcopy -R .note -R .comment -S -O binary test test.bin ndisasm -b 32 test.bin I am running 64-bit Linux, and hence modified the

Instructions appended to end of assembly

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-09 09:21:25
问题 I am trying to follow this tutorial for creating a binary file, but the linker appears to be appending additional instructions at the end of the assembly. I assume this is the OS's tear-down process. The tutorial attempts to compile a bare bones 32-bit C program on Linux: int main() { } using these commands: gcc -c test.c ld -o test -Ttext 0x0 -e main test.o objcopy -R .note -R .comment -S -O binary test test.bin ndisasm -b 32 test.bin I am running 64-bit Linux, and hence modified the

Instructions appended to end of assembly

吃可爱长大的小学妹 提交于 2021-02-09 09:20:15
问题 I am trying to follow this tutorial for creating a binary file, but the linker appears to be appending additional instructions at the end of the assembly. I assume this is the OS's tear-down process. The tutorial attempts to compile a bare bones 32-bit C program on Linux: int main() { } using these commands: gcc -c test.c ld -o test -Ttext 0x0 -e main test.o objcopy -R .note -R .comment -S -O binary test test.bin ndisasm -b 32 test.bin I am running 64-bit Linux, and hence modified the

CMake: Don't set rpath for a single library used in link

落花浮王杯 提交于 2021-02-07 12:48:22
问题 What I'd like to do is configure my CMakeLists file so that while building my project the linker uses a copy of a shared library (.so) that resides in my build tree to link the executable against but then does not set the rpath in the linked executable so that the system must provide the library when the loader requests it. Specifically, I want to link against libOpenCL.so during build time on a build farm that doesn't have libOpenCL.so installed as a system library. To do this, libOpenCL.so

OS X linker unable to find symbols from a C file which only contains variables

為{幸葍}努か 提交于 2021-02-07 05:32:27
问题 I am having problems with the linker when porting a C library from Linux (Ubuntu) to OS X. The C code is auto-generated from Matlab, so ideally I don't want to change the code itself. The problem seems to be in a C file which contains ONLY uninitialised variable declarations, which are then EXTERNed by other C files to implement the Matlab algorithms. The OS X linker is apparently unable to recognise symbols from this file. The same source code works fine on Linux, so I want to understand how