ianlancetaylor / demangle

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

demangle Swift support #16

Open blacktop opened 2 years ago

blacktop commented 2 years ago

Would it be possible to add pure Go Swift demangle support?

ianlancetaylor commented 2 years ago

Where is SWIFT mangling documented? Thanks.

blacktop commented 2 years ago

https://github.com/apple/swift/blob/main/tools/swift-demangle/swift-demangle.cpp https://github.com/apple/swift/tree/main/include/swift/Demangling https://github.com/apple/swift/tree/main/lib/Demangling

blacktop commented 2 years ago
❯ cat greet.swift
func greet() {
  print("Hello World!")
}

greet()
❯ swiftc greet.swift # compile
❯ nm greet
0000000100003db4 t _$s5greetAAyyF
                 U _$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
                 U _$sSSN
0000000100003f34 t _$sSa12_endMutationyyF
                 U _$sSaMa
                 U _$ss27_allocateUninitializedArrayySayxG_BptBwlF
0000000100003e80 t _$ss27_finalizeUninitializedArrayySayxGABnlF
                 U _$ss5print_9separator10terminatoryypd_S2StF
0000000100003edc t _$ss5print_9separator10terminatoryypd_S2StFfA0_
0000000100003f08 t _$ss5print_9separator10terminatoryypd_S2StFfA1_
                 U _$sypN
0000000100003fa0 s ___swift_reflection_version
0000000100000000 T __mh_execute_header
0000000100003d9c T _main
                 U _swift_bridgeObjectRelease
                 U _swift_bridgeObjectRetain
❯ nm greet | xcrun swift-demangle
0000000100003db4 t greet.greet() -> ()
                 U Swift.String.init(_builtinStringLiteral: Builtin.RawPointer, utf8CodeUnitCount: Builtin.Word, isASCII: Builtin.Int1) -> Swift.String
                 U type metadata for Swift.String
0000000100003f34 t Swift.Array._endMutation() -> ()
                 U type metadata accessor for Swift.Array
                 U Swift._allocateUninitializedArray<A>(Builtin.Word) -> ([A], Builtin.RawPointer)
0000000100003e80 t Swift._finalizeUninitializedArray<A>(__owned [A]) -> [A]
                 U Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> ()
0000000100003edc t default argument 1 of Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> ()
0000000100003f08 t default argument 2 of Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> ()
                 U type metadata for Any
0000000100003fa0 s ___swift_reflection_version
0000000100000000 T __mh_execute_header
0000000100003d9c T _main
                 U _swift_bridgeObjectRelease
                 U _swift_bridgeObjectRetain
ianlancetaylor commented 2 years ago

Thanks. That appears to be code that implements demangling. Is there any written documentation separate from code? For example, C++ mangling is defined at https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling.

blacktop commented 2 years ago

https://github.com/apple/swift/blob/main/docs/ABI/Mangling.rst

blacktop commented 2 years ago

Do you need any more info? Thanks!

ianlancetaylor commented 2 years ago

I'm sorry, I don't know when I'll have time to work on this.