<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">We used to have a callback in the standard library that would set the process arguments, but that approach was fragile and would still have broken here. Instead, we load the Swift standard library (a step we would have had to do anyway) before entering main and call out to platform-specific functions that grab command line arguments. Because you’re running on Linux, we’re asking <span style="background-color: rgb(255, 255, 255);" class=""><font color="#183691" face="SFMono-Regular, Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="white-space: pre;" class="">/proc/self/cmdline, </span></font></span>but I’m not sure how exactly that interacts with the JIT. If you’re going to JIT, you should at least follow our lead here by loading the standard library which will in turn load the stubs. You can override the platform-specific getters by calling out to <a href="https://github.com/apple/swift/blob/adc54c8a4d13fbebfeb68244bac401ef2528d6d0/stdlib/public/SwiftShims/RuntimeStubs.h#L40" class="">_swift_stdlib_overrideUnsafeArgvArgc</a><span style="color: rgb(121, 93, 163); font-family: SFMono-Regular, Consolas, 'Liberation Mono', Menlo, Courier, monospace; white-space: pre; background-color: rgb(255, 255, 255);" class="">.</span></div><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 6, 2017, at 3:14 PM, Alex Denisov <<a href="mailto:1101.debian@gmail.com" class="">1101.debian@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><blockquote type="cite" class="">The `main` entry point ought to be a standard C "main" function. The argv argument is an UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>, which ought to be ABI-compatible with a char** in C.<br class=""></blockquote><br class=""><br class="">That was my assumption when I started, thank you for confirmation :)<br class=""><br class=""><blockquote type="cite" class="">When JIT'ing Swift, the value of argv doesn't matter because we replace the process' arguments dynamically <a href="https://github.com/apple/swift/blob/master/lib/Immediate/Immediate.cpp#L318" class="">https://github.com/apple/swift/blob/master/lib/Immediate/Immediate.cpp#L318</a>.<br class=""></blockquote><br class="">Hm, can you tell a bit more about this? I do not load the runtime, my crash may be caused by something not being initialized.<br class="">Here is my simplified use-case: I compile a swift project with tests into bitcode, then I load the bitcode into memory, and then compile and execute a program using ORC JIT.<br class=""><br class=""><blockquote type="cite" class="">Do you have a trace for the crash?<br class=""></blockquote><br class="">Sure, here it is: <a href="https://gist.github.com/AlexDenisov/2a8d9b0d391de73a97bce9e33a650f0f#file-trace-txt-L22-L42" class="">https://gist.github.com/AlexDenisov/2a8d9b0d391de73a97bce9e33a650f0f#file-trace-txt-L22-L42</a><br class=""><br class=""><br class=""><blockquote type="cite" class="">On 6 Mar 2017, at 20:14, Robert Widmann <<a href="mailto:devteam.codafi@gmail.com" class="">devteam.codafi@gmail.com</a>> wrote:<br class=""><br class="">%Sp is not an argument, it is the space necessary to hold a reference to the CommandLine enumeration's static argv member. <br class=""><br class="">When JIT'ing Swift, the value of argv doesn't matter because we replace the process' arguments dynamically <a href="https://github.com/apple/swift/blob/master/lib/Immediate/Immediate.cpp#L318" class="">https://github.com/apple/swift/blob/master/lib/Immediate/Immediate.cpp#L318</a>. Do you have a trace for the crash?<br class=""><br class="">~Robert Widmann<br class=""><br class="">2017/03/06 12:33、Alex Denisov via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> のメッセージ:<br class=""><br class=""><blockquote type="cite" class="">Hi there,<br class=""><br class="">I could not find a list for swift-corelibs-xctest so I am posting it here.<br class=""><br class="">I am trying to run tests based on XCTest (<a href="https://github.com/apple/swift-corelibs-xctest" class="">https://github.com/apple/swift-corelibs-xctest</a>) using LLVM's JIT.<br class="">Everything is working good so far. However, I am getting a crash.<br class="">Based on a shallow investigation I can see that this is somehow related to the way Swift treats the command line arguments. Or, to be more precise, to the way I pass the arguments to the swift's 'main' function.<br class=""><br class="">What I did so far is not different from what I do to run C or C++ using JIT:<br class=""><br class="">auto main = ((int (*)(int, const char **))(intptr_t)mainPointer);<br class="">const int argc = 1;<br class="">const char *argv[] = { "some-name", NULL };<br class="">auto result = main(argc, argv);<br class=""><br class="">Based on what I see in the IR[1] the 'argv' has type "%Sp = type <{ i8* }>", which seems to be a struct with a pointer to something.<br class=""><br class="">So the question is: what is being passed as a second argument to the 'main' function of a swift program?<br class=""><br class="">Any other advice on JIT-ting Swift are more than welcome :)<br class=""><br class="">[1] <a href="https://gist.github.com/AlexDenisov/3c10540b544e82cfb6e58e1452491904" class="">https://gist.github.com/AlexDenisov/3c10540b544e82cfb6e58e1452491904</a><br class="">-- <br class="">AlexDenisov<br class="">Software Engineer, <a href="https://lowlevelbits.org" class="">https://lowlevelbits.org</a><br class=""><br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></blockquote></blockquote><br class="">-- <br class="">AlexDenisov<br class="">Software Engineer, <a href="https://lowlevelbits.org" class="">https://lowlevelbits.org</a><br class=""><br class=""></div></div></blockquote></div><br class=""></body></html>