i cannot start binary file compiled via GAS assembler... I want to link my program with libc. It is not necessary, I just want to link with libc...
Makefile:
LFLAGS= -m elf_x86_64
BUILD_DIR= build
CRT_PATH= /usr/lib/x86_64-linux-gnu
all: create_build_directory hello_world
create_build_directory:
@mkdir -p $(BUILD_DIR)
hello_world: hello_world.o
ld $(LFLAGS) -o ${BUILD_DIR}/hello_world ${CRT_PATH}/crt1.o ${CRT_PATH}/crti.o \
-lc ${BUILD_DIR}/hello_world.o ${CRT_PATH}/crtn.o
hello_world.o: hello_world.s
as --64 hello_world.s -o ${BUILD_DIR}/hello_world.o
@echo "Create object file"
clean:
@rm -f ${BUILD_DIR}/hello_world.o ${BUILD_DIR}/hello_world
@echo "Remove binary and object files"
.INTERMEDIATE: hello_world.o
hello_world.s:
.section .rodata
info: .asciz "my first program"
.text
.global main
main:
# write(1, message, 17)
movl $1, %eax
movq $1, %rdi # file handle 1 is stdout
mov $message, %rsi # address of string to output
mov $17, %rdx # number of bytes
syscall # invoke operating system to do the write
# exit(0)
movl $60, %eax # system call 60 is exit
xor %rdi, %rdi # we want return code 0
syscall # invoke operating system to exit
data:
message: .string "Hello world!!!\r\n"
Then i try to build and run executable file:
make && ./build/hello_world
bash: ./build/hello_world: No such file or directory
What is the reason? The compiled executable file actually exists on disk
Edit1: ldd output:
linux-vdso.so.1 (0x00007fffceb81000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7e234db000)
/lib/ld64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007f7e2387a000)
Edit2: file ./build/hello_world:
./build/hello_world: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld64.so.1, for GNU/Linux 2.6.32, not stripped