From 5d1d7cf77b4b06ad71f9888eeddb0df18e739b7e Mon Sep 17 00:00:00 2001 From: narpfel Date: Thu, 14 Aug 2025 17:09:02 +0200 Subject: [PATCH] Fix demangling for symbols with dots in jump instructions (#8028) For example Rust on AArch64: https://godbolt.org/z/e3q9Wv7zj --- lib/demangler/base.ts | 2 +- test/demangler-tests.ts | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/demangler/base.ts b/lib/demangler/base.ts index 20069ead5..6b447645a 100644 --- a/lib/demangler/base.ts +++ b/lib/demangler/base.ts @@ -44,7 +44,7 @@ export class BaseDemangler extends AsmRegex { readonly includeMetadata: boolean; readonly compiler: BaseCompiler; - readonly jumpDef = /(j\w+|b|bl|blx)\s+([$_a-z][\w$@]*|"[$_a-z][\w$@]*")/i; + readonly jumpDef = /(j\w+|b|bl|blx)\s+([$_a-z][\w$.@]*|"[$_a-z][\w$.@]*")/i; readonly callDef = /callq?\s+([$._a-z][\w$.@]*|"[$._a-z][\w$.@]*")/i; readonly callPtrDef1 = /callq?.*ptr\s\[[a-z]*\s\+\s([$._a-z][\w$.@]*|"[$._a-z][\w$.@]*")]/i; readonly callPtrDef2 = /callq?\s+([$*._a-z][\w$.@]*|"[$*._a-z][\w$.@]*")/i; diff --git a/test/demangler-tests.ts b/test/demangler-tests.ts index 634e1b886..453ce2b43 100644 --- a/test/demangler-tests.ts +++ b/test/demangler-tests.ts @@ -198,6 +198,29 @@ describe('Basic demangling', () => { ]); }); + it('AArch64 branch with dotted symbol', () => { + const result = { + asm: [ + { + text: 'b _ZN4core3fmt3num3imp52_$LT$impl$u20$core..fmt..Display$u20$for$u20$i32$GT$3fmt17h0feee90717706137E', + }, + ], + }; + + const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); + + return Promise.all([ + demangler + .process(result) + .then(output => { + expect(output.asm[0].text).toEqual( + 'b core::fmt::num::imp::::fmt::h0feee90717706137', + ); + }) + .catch(catchCppfiltNonexistence), + ]); + }); + it('Two destructors', () => { const result = { asm: [ @@ -251,7 +274,14 @@ describe('Basic demangling', () => { }); it('Should also support ARM branch instructions', () => { - const result = {asm: [{text: ' bl _ZN3FooC1Ev'}]}; + const result = { + asm: [ + {text: ' bl _ZN3FooC1Ev'}, + { + text: 'b _ZN4core3fmt3num3imp52_$LT$impl$u20$core..fmt..Display$u20$for$u20$i32$GT$3fmt17h0feee90717706137E', + }, + ], + }; const demangler = new DummyCppDemangler(cppfiltpath, new DummyCompiler(), ['-n']); @@ -260,7 +290,12 @@ describe('Basic demangling', () => { demangler.collectLabels(); const output = demangler.othersymbols.listSymbols(); - expect(output).toEqual(['_ZN3FooC1Ev']); + expect(output.sort()).toEqual( + [ + '_ZN3FooC1Ev', + '_ZN4core3fmt3num3imp52_$LT$impl$u20$core..fmt..Display$u20$for$u20$i32$GT$3fmt17h0feee90717706137E', + ].sort(), + ); }); it('Should NOT handle undecorated labels', () => {