demangle icon indicating copy to clipboard operation
demangle copied to clipboard

Handle double leading underscores on Mac

Open kalyanac opened this issue 5 years ago • 3 comments

Filter() cannot handle double leading underscore on Mac OS X.

Here is a sample code and output:

package main

import (
"github.com/ianlancetaylor/demangle"
"fmt"
)


func main(){
	name := "__ZNSt3__111char_traitsIcE11eq_int_typeEii"
	options := []demangle.Option{demangle.NoParams, demangle.NoTemplateParams}
	fmt.Println(demangle.Filter(name, options...))
	fmt.Println(demangle.Filter(name[1:], options...))

}

Output:

$> go run test.go
__ZNSt3__111char_traitsIcE11eq_int_typeEii
std::__1::char_traits::eq_int_type

kalyanac avatar May 06 '20 07:05 kalyanac

it's because macOS prefix every symbol with an extra underscore. I think it's the caller's responsibility to remove it before passing it to Filter.

For example, c++filt on macOS also doesn't handle the example unless the leading underscore is stripped.

minux avatar May 06 '20 08:05 minux

Yes, stripping it easy but it's fairly straight forward to detect the platform and handle the leading underscore. It makes the use of the package easier and returns the expected results.

kalyanac avatar May 07 '20 04:05 kalyanac

I guess adding a StripLeadingUnderscore Option might be OK, but stripping it unconditionally might be undesirable as the underscored version really is not C++ mangled name defined by the IA64 ABI (what if there is another platform that adds another prefix or even suffix to standard mangled name?)

minux avatar May 07 '20 04:05 minux