Issue 58101
Summary [lld] Cannot pad ELF32 to 4GB
Labels
Assignees
Reporter crawfxrd
    `entry.S`:

```asm
    .code16
    .section .reset, "ax", %progbits
    .code16
    .global reset_vector
reset_vector:
    hlt
    jmp reset_vector

    .align 0x10, 0xFF
```

`link.ld`:

```
OUTPUT_FORMAT("elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(reset_vector)

SECTIONS
{
    /* Reset vector on IA32 starts at 16 bytes below 4 GiB */
    . = 0xFFFFFFF0;
    .reset : {
        *(.reset)
    }

    /* NOTE: LLD requires shstrtab */
    .shstrtab : { *(.shstrtab) }
    .strtab : { *(.strtab) }
    .symtab : { *(.symtab) }

    /* Discard everything else */
    /DISCARD/ : { *(*) }
}
```

Compiled with:

```
clang -fuse-ld=lld -m16 -ffreestanding -nostdlib -Wl,-Tlink.ld -Wl,--nmagic -Wl,--build-id=none -o entry.o entry.S
```

Error:

```
ld.lld: error: section .reset at 0xFFFFFFF0 of size 0x10 exceeds available address space
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
```

Section starting at 0xFFFF_FFF0 with a length of 16 bytes will have its last byte at 0xFFFF_FFFF. lld just adds the length to the start so it thinks it ends at 0x1_0000_0000, making it outside of the 4GB limit.

Caused by: 1fc9f39bd544dc757323d2ee8830134275e382ec
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to