ianlancetaylor / demangle

C++ symbol name demangler written in Go
BSD 3-Clause "New" or "Revised" License
166 stars 24 forks source link

Handle double leading underscores on Mac #12

Open kalyanac opened 4 years ago

kalyanac commented 4 years ago

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
minux commented 4 years ago

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.

kalyanac commented 4 years ago

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.

minux commented 4 years ago

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?)