虚拟地址中的全局构造函数 Space

Global Constructors in Virtual Address Space

linker.ld 中的以下代码:

OUTPUT_FORMAT(elf64-x86-64)
ENTRY(start)

HVMA = 0xFFFFFF0000000000;

SECTIONS
{
    . = 1M;
    _start = . + HVMA;

    .init :
    {
        *(.initl)
    }

    . += HVMA;

    .text ALIGN(0x1000) : AT(ADDR(.text) - HVMA)
    {
        *(.inith)
        *(.text)
    }

    .data ALIGN(0x1000) : AT(ADDR(.data) - HVMA)
    {
        start_ctors = .;
        *(.ctor*)
        end_ctors = .;
        start_dtors = .;
        *(.dtor*)
        end_dtors = .;
        *(.data)
    }

    .rodata ALIGN(0x1000) : AT(ADDR(.rodata) - HVMA)
    {
        *(.rodata)
    }

    .bss ALIGN(0x1000) : AT(ADDR(.bss) - HVMA)
    {
        _sbss = .;
        *(COMMON)
        *(.bss)
        _ebss = .;
    }

    _end = .;
}

现在,当我尝试使用 -mcmodel=large 编译所有内容,然后使用此 linker 脚本 link 编译时,我得到 "relocation truncated to fit: R_X86_64_32S against symbol end_ctors defined in .data section in bin/kernel.elf" 并且 [=12= 也是如此]. 我不知道为什么。我能否以某种方式将其设置为使用 64 位地址? -mcmodel=large 应该包括这个,不是吗?

使用以下方法修复了它:

mov r8, end_ctors
cmp rbx, r8

而不是:

cmp rbx, end_ctors

end_dtors也是如此。