Swift mangled function name mapping

4.5k Views Asked by At

How does the Hopper disassembler understand what is the function's name?

For example, I have a simple Swift function named function(), and after disassembling the executable with that function Hopper shows me that it's mangled name is __T04file8functionyy. I can find the location of these symbols in the executable file, but I can't find how does it map the address of the function with it's name.

2

There are 2 best solutions below

0
alexk On BEST ANSWER

I found this Mach-O file format reference: https://github.com/aidansteele/osx-abi-macho-file-format-reference

So the answer to my question is that there is a special struct called nlist_64, which contains the address of the function in the executable and the index of the mangled name of that function in the symbol table.

1
Code Different On

You can read the name mangling specs straight from Apple.

If you only want a quick way to demangle the name, type the following in Terminal:

swift demangle __T04file8functionyy

Output:

_T04file8functionyy ---> filefunction empty-list  empty-list 

(I'm not sure if the mangled name you provided is valid)