[llvm-branch-commits] [lld] b980cc1 - [lld][ELF] Mark empty NOLOAD output sections SHT_NOBITS instead of SHT_PROGBITS
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jun 16 19:46:02 PDT 2020
Author: Matt Schulte
Date: 2020-06-16T19:45:27-07:00
New Revision: b980cc1cd3200dbf7603c7dd04335165b7578baa
URL: https://github.com/llvm/llvm-project/commit/b980cc1cd3200dbf7603c7dd04335165b7578baa
DIFF: https://github.com/llvm/llvm-project/commit/b980cc1cd3200dbf7603c7dd04335165b7578baa.diff
LOG: [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
(cherry picked from commit fdc41aa22c60958e6b6df461174b814a4aae3384)
Added:
Modified:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/noload.s
Removed:
################################################################################
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index fd8de3b54bd7..80ec8b655b04 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -737,6 +737,7 @@ bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok1, Stri
expect("(");
if (consume("NOLOAD")) {
cmd->noload = true;
+ cmd->type = SHT_NOBITS;
} else {
skip(); // This is "COPY", "INFO" or "OVERLAY".
cmd->nonAlloc = true;
diff --git a/lld/test/ELF/linkerscript/noload.s b/lld/test/ELF/linkerscript/noload.s
index eb6ace45adcd..2f52b465854e 100644
--- a/lld/test/ELF/linkerscript/noload.s
+++ b/lld/test/ELF/linkerscript/noload.s
@@ -3,13 +3,15 @@
# RUN: echo "SECTIONS { \
# RUN: .data_noload_a (NOLOAD) : { *(.data_noload_a) } \
# RUN: .data_noload_b (0x10000) (NOLOAD) : { *(.data_noload_b) } \
+# RUN: .no_input_sec_noload (NOLOAD) : { . += 1; } \
# RUN: .text (0x20000) : { *(.text) } };" > %t.script
# RUN: ld.lld -o %t --script %t.script %t.o
# RUN: llvm-readelf -S -l %t | FileCheck %s
-# CHECK: Name Type Address Off Size
-# CHECK: .data_noload_a NOBITS 0000000000000000 [[OFF:[0-9a-f]+]] 001000
-# CHECK-NEXT: .data_noload_b NOBITS 0000000000010000 [[OFF]] 001000
+# CHECK: Name Type Address Off Size
+# CHECK: .data_noload_a NOBITS 0000000000000000 [[OFF:[0-9a-f]+]] 001000
+# CHECK-NEXT: .data_noload_b NOBITS 0000000000010000 [[OFF]] 001000
+# CHECK-NEXT: .no_input_sec_noload NOBITS 0000000000011000 [[OFF]] 000001
# CHECK: Type Offset VirtAddr PhysAddr
# CHECK-NEXT: LOAD 0x001000 0x0000000000020000 0x0000000000020000
More information about the llvm-branch-commits
mailing list