[swift-dev] swift (ABI) and Windows

Sangjin Han tinysun.net at gmail.com
Tue May 10 17:31:58 CDT 2016


Yes, I ran 'swift Hello.swift'. I didn't know there is MCJIT in that.
I'll ask and find the answer for it.

-Han Sangjin

2016-05-11 7:14 GMT+09:00 Joe Groff <jgroff at apple.com>:

>
> > On May 10, 2016, at 3:11 PM, Sangjin Han <tinysun.net at gmail.com> wrote:
> >
> > Joe,
> >
> > LLVM's MCJIT? Did you mean the REPL mode?
>
> By immediate mode, do you mean "swift foo.swift", where the script is
> immediately compiled and executed? That also uses MCJIT.
>
> >
> > I'm not ready to ask a question or understand the answer about them.
> Maybe it takes some time for me to handle them.
> > Currently, I want to concentrate on the immediate mode, dynamic/static
> linking on Windows (MSVC).
>
> I suspect that this is because of an LLVM bug in handling dllimport/export
> in JIT mode. Asking the LLVM list, you should at least be able to confirm
> this, and maybe get help from other LLVM users who've run into similar
> issues.
>
> -Joe
>
> >
> > By the way, in Cygwin (although it uses similar ABI and the COFF
> format), immediate mode and dynamic linking worked without the dll
> import/export consideration, it was 'ld''s magic. The immediate mode in
> Cygwin does not work if dllimport is applied. (same to Windows(MSVC) )
> >
> > I think we may consider for only MSVC, if the REPL in Cygwin works
> without dllimport consideration.
> >
> > -Han Sangjin
> >
> > 2016-05-10 2:06 GMT+09:00 Joe Groff <jgroff at apple.com>:
> >
> > > On May 7, 2016, at 4:01 PM, Sangjin Han <tinysun.net at gmail.com> wrote:
> > >
> > > Hi all,
> > >
> > > I merged Saleem's #2080 to my working branch, and did some experiment.
> > >
> > > I could compile easily Hello.swift with #2080 merged one.
> > >
> > >   swiftc -c -o Hello.obj Hello.swift
> > >   clang -o Hello.exe Hello.obj -llibswiftCore
> -llibswiftSwiftOnoneSupport -Wl,<some link options>
> > >
> > > Without #2080, I should use the *.ll-modifying-trick. It is perfect in
> this example.
> > >
> > > But, we need the way to disable dllimport. The immediate mode did not
> work.
> >
> > If it only affects immediate mode, this might be a problem with LLVM's
> MCJIT. I would recommend asking llvm-dev, cc-ing Lang Hames (
> lhames at apple.com), to see what the right thing to do to reference DLL
> exports from JIT code is.
> >
> > -Joe
> >
> > >   swift Hello.swift
> > >   LLVM ERROR: Program used external function
> '__imp_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func3' which could
> not be resolved!
> > >
> > >   swift -O Hello.swift
> > >   LLVM ERROR: Program used external function
> '__imp__swift_getExistentialTypeMetadata' which could not be resolved!
> > >
> > > It seems swift.exe call directly the function in the DLL without
> import library.
> > >
> > > The feature also needed when we link to static library.
> > >
> > > I don't know about the SIL, IR, so it is thankful someone tell me how
> to approach this problem.
> >
> >
> >
> > >
> > > 2016-05-07 5:01 GMT+09:00 Saleem Abdulrasool <compnerd at compnerd.org>:
> > > On Thu, May 5, 2016 at 5:26 PM, Joe Groff via swift-dev <
> swift-dev at swift.org> wrote:
> > >
> > > > On May 5, 2016, at 4:18 PM, Sangjin Han via swift-dev <
> swift-dev at swift.org> wrote:
> > > >
> > > > Hi,
> > > >
> > > > I made an experimental MSVC port. Of cause, dllimport/dllexport and
> the driver for linking and many other part is not implemented. But dynamic
> linking was possible with some trick.
> > > >
> > > > I think it is useful for designing, my observation about the
> experimental building of libswiftCore.dll, libswiftSwiftOnoneSupport.dll
> and linking of Hello.exe - its source has only 'print("Hello")'.
> > > >
> > > > 1) SWIFT_RUNTIME_EXPORT was not enough for dllexport.
> > > >   Hello.obj needed defined in libswift*.dll
> > > >     _swift_getExistentialTypeMetadata,
> > > >     _TFs5printFTGSaP__9separatorSS10terminatorSS_T_,
> > > >     _TMSS,
> > > >     _TZvOs7Process5_argcVs5Int32,
> > > >     swift_bufferAllocate, ....
> > > >   Some of above are dllexported by the macro, but _T* are not.
> Maybe, it generated by swiftc.exe.
> > > >   I used the utility 'dlltool.exe' from Cygwin/MinGW world. It
> extracts all symbols and generates 'allsymbol.def'.
> > > >   With that .def, I could build the all-symbol-dllexported
> libswiftCore.dll.
> > > >   (I'm hoping we can build it without this trick.)
> > >
> > > The _T symbols are emitted by the Swift compiler. You should modify
> swiftc's IRGen to generate public symbols with LLVM's "dllexport" storage
> class when targeting Windows.
> > >
> > > https://github.com/apple/swift/pull/2080 is a first cut attempt to do
> this.
> > >
> > >
> > > -Joe
> > > _______________________________________________
> > > swift-dev mailing list
> > > swift-dev at swift.org
> > > https://lists.swift.org/mailman/listinfo/swift-dev
> > >
> > >
> > >
> > > --
> > > Saleem Abdulrasool
> > > compnerd (at) compnerd (dot) org
> > >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160511/262b86ba/attachment.html>


More information about the swift-dev mailing list