Skip to content

Commit fdc41aa

Browse files
schultetwin1MaskRay
authored andcommitted
[lld][ELF] Mark empty NOLOAD output sections SHT_NOBITS instead of SHT_PROGBITS
This fixes PR# 45336. Output sections described in a linker script as NOLOAD with no input sections would be marked as SHT_PROGBITS. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D76981
1 parent 03bc311 commit fdc41aa

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lld/ELF/ScriptParser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok1, Stri
746746
expect("(");
747747
if (consume("NOLOAD")) {
748748
cmd->noload = true;
749+
cmd->type = SHT_NOBITS;
749750
} else {
750751
skip(); // This is "COPY", "INFO" or "OVERLAY".
751752
cmd->nonAlloc = true;

lld/test/ELF/linkerscript/noload.s

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
# RUN: echo "SECTIONS { \
44
# RUN: .data_noload_a (NOLOAD) : { *(.data_noload_a) } \
55
# RUN: .data_noload_b (0x10000) (NOLOAD) : { *(.data_noload_b) } \
6+
# RUN: .no_input_sec_noload (NOLOAD) : { . += 1; } \
67
# RUN: .text (0x20000) : { *(.text) } };" > %t.script
78
# RUN: ld.lld -o %t --script %t.script %t.o
89
# RUN: llvm-readelf -S -l %t | FileCheck %s
910

10-
# CHECK: Name Type Address Off Size
11-
# CHECK: .data_noload_a NOBITS 0000000000000000 [[OFF:[0-9a-f]+]] 001000
12-
# CHECK-NEXT: .data_noload_b NOBITS 0000000000010000 [[OFF]] 001000
11+
# CHECK: Name Type Address Off Size
12+
# CHECK: .data_noload_a NOBITS 0000000000000000 [[OFF:[0-9a-f]+]] 001000
13+
# CHECK-NEXT: .data_noload_b NOBITS 0000000000010000 [[OFF]] 001000
14+
# CHECK-NEXT: .no_input_sec_noload NOBITS 0000000000011000 [[OFF]] 000001
1315

1416
# CHECK: Type Offset VirtAddr PhysAddr
1517
# CHECK-NEXT: LOAD 0x001000 0x0000000000020000 0x0000000000020000

0 commit comments

Comments
 (0)