mold
mold copied to clipboard
mold: fatal: ftruncate failed: Invalid argument
I'm currently looking forward replacing gold with mold from the toolchain used to build my operating system. Currently I managed to create a string of flags that should replace the linker script: ld.mold <object files go here> -m elf_x86_64 -zmax-page-size=0x1000 -nostdlib --static --Ttext=0xffffffff80000000 -o ../out/kernel.elf. At the moment the output of this command is mold: fatal: ftruncate failed: Invalid argument. I'm on mint 21 with linux 6.0.0-1011-oem. mold was built today.
Can you re-link your kernel with --repro and upload a generated kernel.elf.tar? That tar file will contain all input files so that I can build it on my local machine to reproduce the issue.
kernel.elf.repro.tar.gz linker.ld.txt
This is the output of the command but without the last zero for the text section address. It's interesting that it works if I remove it even tho the original address is cannonical. With the original command it still gives the same error about the ftruncate function. I attached the original linker script for reference. The phdrs' permissions can be omited.
I ran mold with your input files and it just passed. It indeed called ftruncate(2) but with a reasonable argument as follows (this is an strace log):
ftruncate(3, 284136) = 0
Can you debug it a little bit to figure out why it's failing on your system?
For me it runs ftruncate(3, -2149302528). Weird isn't it?
I used these gdb commands to find it out: (gdb --args mold obj/cpu/fpu.o obj/cpu/gdt.o obj/cpu/idt.o obj/cpu/pic.o obj/cpu/smp.o obj/drv/drv.o obj/drv/framebuffer.o obj/drv/initrd.o obj/drv/input.o obj/drv/serial.o obj/elf/elf.o obj/fs/vfs.o obj/fw/acpi.o obj/fw/bootloader.o obj/main/init.o obj/main/kernel.o obj/misc/utils.o obj/mm/blk.o obj/mm/pmm.o obj/mm/vmm.o obj/sched/pit.o obj/sched/scheduler.o obj/subsys/socket.o obj/subsys/vt.o obj/sys/syscall.o obj/cpu/atomic_asm.o obj/cpu/fpuInit_asm.o obj/cpu/gdtLoad_asm.o obj/cpu/isr_asm.o obj/cpu/tssLoad_asm.o obj/cpu/userspace_asm.o -zmax-page-size=0x1000 -nostdlib --static --Ttext=0xffffffff80000000 -o ../out/kernel.elf)
b output-file-unix.h:42
lay spl
set follow-fork-mode child
I will try on a different linux pc with older software versions and I will see if it is the newer software.
It's a similar issue on a rpi 4 with raspberry pi os
Are you building your kernel on a 32-bit machine?
No, in both cases I'm running a 64 bit CPU and a 64 bit OS