From d8ed639a6a3b210d7df9a3f77d5a7546fad15f49 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 9 Dec 2020 20:46:37 -0800 Subject: [PATCH] [lld][WebAssembly] Don't emit names for data segments that we omit Followup to https://reviews.llvm.org/D92909 Differential Revision: https://reviews.llvm.org/D92997 --- lld/test/wasm/bss-only.s | 2 ++ lld/wasm/SyntheticSections.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lld/test/wasm/bss-only.s b/lld/test/wasm/bss-only.s index 56963530a0b0..1c0500f172ca 100644 --- a/lld/test/wasm/bss-only.s +++ b/lld/test/wasm/bss-only.s @@ -41,3 +41,5 @@ b: # CHECK-NEXT: - Name: __data_end # CHECK-NEXT: Kind: GLOBAL # CHECK-NEXT: Index: 1 + +# CHECK-NOT: DataSegmentNames: diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp index 95a48528db9e..8e2c7c631f95 100644 --- a/lld/wasm/SyntheticSections.cpp +++ b/lld/wasm/SyntheticSections.cpp @@ -566,7 +566,7 @@ unsigned NameSection::numNamedDataSegments() const { unsigned numNames = 0; for (const OutputSegment *s : segments) - if (!s->name.empty()) + if (!s->name.empty() && !s->isBss) ++numNames; return numNames; @@ -636,8 +636,10 @@ void NameSection::writeBody() { writeUleb128(sub.os, count, "name count"); for (OutputSegment *s : segments) { - writeUleb128(sub.os, s->index, "global index"); - writeStr(sub.os, s->name, "segment name"); + if (!s->name.empty() && !s->isBss) { + writeUleb128(sub.os, s->index, "global index"); + writeStr(sub.os, s->name, "segment name"); + } } sub.writeTo(bodyOutputStream);