首页 > 解决方案 > Nasm ld 重定位被截断以适应:R_X86_64_16

问题描述

我是一个组装新手,我的代码如下所示:

section .text
    global _start

_start:
    call print_string
    .inf_loop:
    hlt
    jmp .inf_loop

print_string:
    cld
    mov si, string
    .loop
    lodsb
    cmp al, BYTE 0
    je .done
    out 0xe9, al
    jmp .loop
.done
    ret

; The stivale header our kernel needs to be booted via limine
section .stivale2hdr
    ; This is set to zero, so the bootloader will use the elf entry point
    entry_point: dq 0
    ; This tells the bootloader where our stack is
    ; Remember the stack grows downwards :)
    stack: dq this_is_the_stack+8192 
    flags: dq 011b
    tags: dq 0


section .bss
    align 16
    this_is_the_stack: resb 8192

section .rodata
    string: db "Hello, world!", 0

然后我正在组装: yasm --arch=x86 --oformat=elf64 --machine=amd64

并与此链接: ld -Tlinker.ld -nosdtlib -zmax-page-size=0x1000 -static --no-dynamic-linker -ztext

Ld 给我以下错误:

./arch/x86_64/boot.o: in function `no symbol':
arch/x86_64/boot.S:(.text+0xb): relocation truncated to fit: R_X86_64_16 against `.rodata'
make: *** [Makefile:29: kernel.elf] Error 1 

我可以改变什么来解决这个问题?您需要查看我的链接器脚本吗?

标签: assemblyx86-64nasmlinker-errors

解决方案


推荐阅读