[lld] [lld][ELF] Exclude SHT_NOBITS sections from LMA overlap checks (PR #196423)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue May 26 18:29:28 PDT 2026
================
@@ -0,0 +1,91 @@
+# REQUIRES: x86
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
+
+## Check we can overlap a NOLOAD output section containing a NOBITS input section.
+# RUN: ld.lld --script lds-nobits a.o -o out
+# RUN: llvm-readelf -S -l out | FileCheck %s -check-prefix OVERLAP-NOBITS
+# OVERLAP-NOBITS: Name Type Address Off Size
+# OVERLAP-NOBITS: .bss NOBITS 0000000000101000 [[OFF:[0-9a-f]+]] 001000
+# OVERLAP-NOBITS-NEXT: .overlap PROGBITS 0000000000200000 [[OFF]] 000001
+
+# OVERLAP-NOBITS: Type Offset VirtAddr PhysAddr FileSiz MemSiz
+# OVERLAP-NOBITS: LOAD 0x002000 0x0000000000101000 0x0000000000101000 0x000000 0x001000
+# OVERLAP-NOBITS-NEXT: LOAD 0x002000 0x0000000000200000 0x0000000000101000 0x000001 0x000001
+
+# OVERLAP-NOBITS: Section to Segment mapping:
+# OVERLAP-NOBITS: 01 .bss
+# OVERLAP-NOBITS: 02 .overlap
+
+## Check we can overlap a NOLOAD output section containing a PROGBITS input section.
+# RUN: ld.lld --script lds-noload a.o -o out
+# RUN: llvm-readelf -S -l out | FileCheck %s -check-prefix OVERLAP-NOLOAD
+
+# OVERLAP-NOLOAD: Name Type Address Off Size
+# OVERLAP-NOLOAD: .data NOBITS 0000000000101000 [[OFF:[0-9a-f]+]] 001000
+# OVERLAP-NOLOAD-NEXT: .overlap PROGBITS 0000000000200000 [[OFF]] 000001
+
+# OVERLAP-NOLOAD: Type Offset VirtAddr PhysAddr FileSiz MemSiz
+# OVERLAP-NOLOAD: LOAD 0x002000 0x0000000000101000 0x0000000000101000 0x000000 0x001000
+# OVERLAP-NOLOAD-NEXT: LOAD 0x002000 0x0000000000200000 0x0000000000101000 0x000001 0x000001
+
+# OVERLAP-NOLOAD: Section to Segment mapping:
+# OVERLAP-NOLOAD: 01 .data
+# OVERLAP-NOLOAD-NEXT: 02 .overlap
+
+## Check that we cannot overlap the memory occupied by a NOBITS input section
+## that is assigned to a PROGBITS output section.
+# RUN: not ld.lld --script lds-progbits a.o -o /dev/null 2>&1 | FileCheck %s -check-prefix ERR-PROGBITS-TYPE
+# ERR-PROGBITS-TYPE: error: section .progbits load address range overlaps with .overlap
+
+#--- a.s
+.section .text,"ax", at progbits
+ nop
+.org 4096
+
+.section .data,"aw", at progbits
+.fill 4096, 1, 0xFF
+
+.section .bss,"aw", at nobits
+.zero 4096
+
+.section .overlap,"aw", at progbits
+.byte 1
+
+#--- lds-nobits
----------------
MaskRay wrote:
We typically use `nobits.lds` instead of `lds-nobits`
https://github.com/llvm/llvm-project/pull/196423
More information about the llvm-commits
mailing list