I’m trying to compile and link an assembly program. This is the environment I’m using:
let
pkgs = import <nixpkgs> {};
in
pkgs.mkShell {
buildInputs = with pkgs; [
gcc
glibc.static
];
}
assembly file (main.asm):
.section .text
.global main
main:
mov $msg, %rdi
call printf
xor %rax, %rax
mov $80, %rdi
syscall
msg:
.ascii "hello world\n\0"
ldscript:
ENTRY(main)
SEARCH_DIR(/nix/store/9xjk9wgkdqkh5vw9f8brjg3bx6k8r02f-glibc-2.31-static/lib)
SECTIONS
{
. = 0x10000;
.text : {
*(.text)
}
}
Compilation command (exits successfully):
as -c main.asm -o main.o
Linking command:
ld main.o -o main -Tbin.ld -lc
The last command fails with undefined reference errors for *printf*
and other related symbols. How do I link and run this program successfully?