Skip to content

[linker-script] Failure in OVERLAY linker scripts with VMA/LMA #1748

Description

repro

#!/usr/bin/env bash
set -euo pipefail

cat > "inputs.s" <<'EOF'
.section .vectors, "ax", %progbits
  .space 0x20

.section .vectors.bhb.loop8, "ax", %progbits
  .space 0x20

.section .vectors.bhb.bpiall, "ax", %progbits
  .space 0x20

.section .stubs, "ax", %progbits
  .space 0x350

.section .init.text, "ax", %progbits
.global _start
_start:
  .space 0x1000
EOF

cat > "overlay.lds" <<'EOF'
ENTRY(_start)

SECTIONS
{
  . = 0xc1c00000;
  .text : { *(.text) }
  . = ALIGN(0x1000);

  __vectors_lma = .;
  OVERLAY 0xffff0000 : NOCROSSREFS AT(__vectors_lma)
  {
    .vectors { KEEP(*(.vectors)) }
    .vectors.bhb.loop8 { KEEP(*(.vectors.bhb.loop8)) }
    .vectors.bhb.bpiall { KEEP(*(.vectors.bhb.bpiall)) }
  }

  . = __vectors_lma + SIZEOF(.vectors) +
      SIZEOF(.vectors.bhb.loop8) + SIZEOF(.vectors.bhb.bpiall);

  __stubs_lma = .;
  .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_lma)
  {
    *(.stubs)
  }

  . = __stubs_lma + SIZEOF(.stubs);
  . = ALIGN(8);
  .init.text : AT(ADDR(.init.text)) { *(.init.text) }
}
EOF

clang -c "inputs.s" -o "inputs.o"
ld.eld -T "overlay.lds" "inputs.o" -o "output.elf"
ld.lld -T "overlay.lds" "inputs.o" -o "output.elf"

ELD fails with the following error while LLD links successfully:

Error: section .init.text virtual address range overlaps with .stubs 
         >>> .init.text range is [0xC1C003B0, 0xC1C013AF] 
         >>> .stubs range is [0xC1C01000, 0xC1C0134F]
Fatal: Linking had errors (output.elf)

This pattern is used in the Linux ARM kernel

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions