[swift-users] Indirectly calling functions through assembly

Krishna Mannem krishnamannem at icloud.com
Sat Nov 26 19:20:49 CST 2016


I’ve been messing around with swift and trying to figure out the internals for fun. I’ve been running into a seg fault while running this gist (https://gist.github.com/krishnamannem/032aa7b568f82297ba2f88041518085d), the seg fault happens in the print(). 

Going through the execution with lldb I know the error is inside print and the only difference between the disassembled versions is some retain release stuff which I don’t think is the issue. I have very little experience with swift so you’ll have to excuse me if I’m totally screwing/mixing something up. Does anyone know what extra magic testing(x: () -> ()) { x() }  does to ensure it doesn’t segfault. 

Side note: I have replaced the print with a plain var _ = 1 + 1 and this worked just fine.

I ran this using :

Llvm-g++ -c func.S -o func.o
Swiftc -g func.swift func.o




More information about the swift-users mailing list