[lld] [ELF,test] Extend nobits-offset.s to cover sections following .bss (PR #224201)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 23:11:36 PDT 2026


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/224201

None

>From be4f77de2867827e49f1ad7f8a772044e946a4fc Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Wed, 16 Sep 2026 22:57:46 -0700
Subject: [PATCH] [ELF,test] Extend nobits-offset.s to cover sections following
 .bss

---
 lld/test/ELF/linkerscript/nobits-offset.s | 61 ++++++++++++++++++++---
 1 file changed, 54 insertions(+), 7 deletions(-)

diff --git a/lld/test/ELF/linkerscript/nobits-offset.s b/lld/test/ELF/linkerscript/nobits-offset.s
index 387eaed4cb1468..a725a06389fe34 100644
--- a/lld/test/ELF/linkerscript/nobits-offset.s
+++ b/lld/test/ELF/linkerscript/nobits-offset.s
@@ -1,16 +1,17 @@
 # REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: echo "SECTIONS { \
-# RUN:         .sec1 (NOLOAD) : { . += 1; } \
-# RUN:         .bss           : { *(.bss) } \
-# RUN:       };" > %t.script
-# RUN: ld.lld %t.o -T %t.script -o %t
-# RUN: llvm-readelf -S -l %t | FileCheck %s
+## Test file offsets of SHT_NOBITS sections and of the sections following them
+## in the same PT_LOAD.
+
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
 
 ## If a SHT_NOBITS section is the only section of a PT_LOAD segment,
 ## p_offset will be set to the sh_offset field of the section. Check we align
 ## sh_offset to sh_addr modulo max-page-size, so that p_vaddr=p_offset (mod
 ## p_align).
+# RUN: ld.lld a.o -T a.lds -o a
+# RUN: llvm-readelf -S -l a | FileCheck %s
 
 # CHECK:      Name  Type     Address          Off     Size
 # CHECK-NEXT:       NULL     0000000000000000 000000  000000
@@ -25,6 +26,52 @@
 # CHECK:      00 .sec1 {{$}}
 # CHECK:      01 .bss {{$}}
 
+# RUN: ld.lld b.o -T b.lds -o b
+# RUN: llvm-readelf -S -l b | FileCheck %s --check-prefix=EMPTY
+# RUN: ld.lld b.o -T c.lds -o c
+# RUN: llvm-readelf -S -l c | FileCheck %s --check-prefix=NONEMPTY
+
+# EMPTY:         .bss    NOBITS   0000000000000002 001002 000100
+# EMPTY-NEXT:    .empty1 PROGBITS 0000000000000102 001102 000000
+# EMPTY-NEXT:    .empty2 PROGBITS 0000000000000102 001102 000000
+# EMPTY:         LOAD 0x001001 0x0000000000000001 0x0000000000000001 0x000101 0x000101 RW 0x1000
+
+# NONEMPTY:      .bss    NOBITS   0000000000000002 001002 000100
+# NONEMPTY-NEXT: .empty1 PROGBITS 0000000000000102 001102 000000
+# NONEMPTY-NEXT: .data2  PROGBITS 0000000000000102 001102 000001
+# NONEMPTY:      LOAD 0x001001 0x0000000000000001 0x0000000000000001 0x000102 0x000102 RW 0x1000
+
+#--- a.s
 .bss
 .p2align 10
 .byte 0
+
+#--- a.lds
+SECTIONS {
+  .sec1 (NOLOAD) : { . += 1; }
+  .bss : { *(.bss) }
+}
+
+#--- b.s
+.globl _start
+_start: ret
+.data
+.byte 1
+.bss
+.space 0x100
+
+#--- b.lds
+SECTIONS {
+  .data : {}
+  .bss : {}
+  .empty1 : { empty1 = .; }
+  .empty2 : { empty2 = .; }
+}
+
+#--- c.lds
+SECTIONS {
+  .data : {}
+  .bss : {}
+  .empty1 : { empty1 = .; }
+  .data2 : { BYTE(2) }
+}



More information about the llvm-commits mailing list