From c1a59fa550818c6d3c229b43918b5045d7df83e6 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 1 Jun 2021 12:48:21 -0700 Subject: [PATCH] [lld][WebAssemlby] Fix for string merging of -dwarf-5 sections We were mistakenly treating `.debug_str_offsets` as a string mergable section when it is not (it contains integers not strings). This is an indication that we really should find a way to store flags for custom sections. Fixes: https://bugs.llvm.org/show_bug.cgi?id=48828 Fixes: https://bugs.chromium.org/p/chromium/issues/detail?id=1172217 Differential Revision: https://reviews.llvm.org/D103486 --- lld/test/wasm/merge-string-debug.s | 9 +++++++++ lld/wasm/InputFiles.cpp | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lld/test/wasm/merge-string-debug.s b/lld/test/wasm/merge-string-debug.s index 961cdab..73e31d5 100644 --- a/lld/test/wasm/merge-string-debug.s +++ b/lld/test/wasm/merge-string-debug.s @@ -11,6 +11,7 @@ # RUN: wasm-ld -O0 %t.o %t2.o -o %tO0.wasm --no-entry # RUN: llvm-readobj -x .debug_str %tO0.wasm | FileCheck %s --check-prefixes CHECK,CHECK-O0 +# RUN: llvm-readobj -x .debug_str_offsets %tO0.wasm | FileCheck %s --check-prefixes CHECK-OFFSETS .section .debug_str,"S",@ .Linfo_string0: @@ -21,6 +22,11 @@ .section .debug_other,"",@ .int32 .Linfo_string0 +.section .debug_str_offsets,"",@ + .int32 .Linfo_string0 + .int32 .Linfo_string0 + .int32 .Linfo_string0 + # CHECK: Hex dump of section '.debug_str': # CHECK-O0: 0x00000000 636c616e 67207665 7273696f 6e203133 clang version 13 @@ -30,3 +36,6 @@ # CHECK-O1: 0x00000000 666f6f62 61720066 6f6f0063 6c616e67 foobar.foo.clang # CHECK-O1: 0x00000010 20766572 73696f6e 2031332e 302e3000 version 13.0.0. + +# CHECK-OFFSETS: Hex dump of section '.debug_str_offsets': +# CHECK-OFFSETS: 0x00000000 00000000 00000000 00000000 ............ diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index faf7bbc..4688590 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -368,8 +368,11 @@ static bool shouldMerge(const WasmSection &sec) { // currently go by the name alone. // TODO(sbc): Add ability for wasm sections to carry flags so we don't // need to use names here. - return sec.Name.startswith(".debug_str") || - sec.Name.startswith(".debug_line_str"); + // For now, keep in sync with uses of wasm::WASM_SEG_FLAG_STRINGS in + // MCObjectFileInfo::initWasmMCObjectFileInfo which creates these custom + // sections. + return sec.Name == ".debug_str" || sec.Name == ".debug_str.dwo" || + sec.Name == ".debug_line_str"; } static bool shouldMerge(const WasmSegment &seg) { -- 2.7.4