Hi, I am curious to know about LLVM IR as platform independent feature. I have compiler some C and C++ applications that compiled on Linux 64bit machine, now I want to generate bit code file on Windows 64bit machine. 1) Will this execute without any issues? 2) Do I pass any option for making it operating system portable? 3) Can I generate bit code file also on Linux machine and then run on Windows machine? Please give me some pointers? Any help will be highly appreciated. Thanks and Regards, Sandeep -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150707/7e651671/attachment.html>
Some LLVM IR could be portable. But the C/C++ languages are not designed to be portable in that way. Your application will be including system headers with platform specific information in them. For example, platform specific decisions about structure memory layout, or runtime function names for linking against. On Tue, Jul 7, 2015 at 3:43 PM, Sandeep Kumar Singh <deepdondo007 at gmail.com> wrote:> Hi, > > I am curious to know about LLVM IR as platform independent feature. > I have compiler some C and C++ applications that compiled on Linux 64bit > machine, now I want to generate bit code file on Windows 64bit machine. > > 1) Will this execute without any issues? > 2) Do I pass any option for making it operating system portable? > 3) Can I generate bit code file also on Linux machine and then run on > Windows machine? > > Please give me some pointers? > > Any help will be highly appreciated. > > > Thanks and Regards, > Sandeep > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150707/bea900f0/attachment.html>
Hi Sandeep, As far as I know, it depends: If you have portable C/C++ source (e.g. with ifdefs to handle platform specific stuff) you can compile this source with the Linux-defines on Linux to generate a working Linux binary or you can compile the same source on Windows with the Windows-defines to generate a working Windows binary. As LLVM/clang is inherently a cross-compiler you can also generate the windows object files on Linux when you pass the correct target triple and the Windows-defines to your Linux-clang or vice-versa. Note that this will only give you object files which you still need to link to obtain a working executable (usually with your system linker, link.exe on Windows, ld on Linux). What will not work is compiling the source with a Linux target triple and Linux-defines into bitcode and then compile this bitcode into a Windows object file and expect it to link and run correctly. The reason is that the bitcode already encodes target specific information as it represents preprocessed code and was generated to target a specific platform ABI defining stuff like name mangeling, struct and vtable layout, exception handling, calling convention, etc. You might get away compiling a Linux-bitcode file into a working Windows object file when you restrict yourself to platform independent C (the preprocessed source is identical on Windows on Linux) and have only scalar values as function parameters but I would not recommend this approach. Best regards Andreas 2015-07-07 8:13 GMT+02:00 Sandeep Kumar Singh <deepdondo007 at gmail.com>:> Hi, > > I am curious to know about LLVM IR as platform independent feature. > I have compiler some C and C++ applications that compiled on Linux 64bit > machine, now I want to generate bit code file on Windows 64bit machine. > > 1) Will this execute without any issues? > 2) Do I pass any option for making it operating system portable? > 3) Can I generate bit code file also on Linux machine and then run on > Windows machine? > > Please give me some pointers? > > Any help will be highly appreciated. > > > Thanks and Regards, > Sandeep > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150707/8988b76c/attachment.html>
Hi Andreas, Thanks for detailed explanation. Now it is very clear to me that I should write first platform independent code to make it work correct. As I know, Java is platform independent, will I face the same issue with it? Thanks and Regards, Sandeep On Tue, Jul 7, 2015 at 1:14 PM, Andreas Weber <andreas.c.weber at gmail.com> wrote:> Hi Sandeep, > > As far as I know, it depends: If you have portable C/C++ source (e.g. with > ifdefs to handle platform specific stuff) you can compile this source with > the Linux-defines on Linux to generate a working Linux binary or you can > compile the same source on Windows with the Windows-defines to generate a > working Windows binary. > > As LLVM/clang is inherently a cross-compiler you can also generate the > windows object files on Linux when you pass the correct target triple and > the Windows-defines to your Linux-clang or vice-versa. Note that this will > only give you object files which you still need to link to obtain a working > executable (usually with your system linker, link.exe on Windows, ld on > Linux). > > What will not work is compiling the source with a Linux target triple and > Linux-defines into bitcode and then compile this bitcode into a Windows > object file and expect it to link and run correctly. The reason is that the > bitcode already encodes target specific information as it represents > preprocessed code and was generated to target a specific platform ABI > defining stuff like name mangeling, struct and vtable layout, exception > handling, calling convention, etc. > > You might get away compiling a Linux-bitcode file into a working Windows > object file when you restrict yourself to platform independent C (the > preprocessed source is identical on Windows on Linux) and have only scalar > values as function parameters but I would not recommend this approach. > > Best regards > Andreas > > 2015-07-07 8:13 GMT+02:00 Sandeep Kumar Singh <deepdondo007 at gmail.com>: > >> Hi, >> >> I am curious to know about LLVM IR as platform independent feature. >> I have compiler some C and C++ applications that compiled on Linux 64bit >> machine, now I want to generate bit code file on Windows 64bit machine. >> >> 1) Will this execute without any issues? >> 2) Do I pass any option for making it operating system portable? >> 3) Can I generate bit code file also on Linux machine and then run on >> Windows machine? >> >> Please give me some pointers? >> >> Any help will be highly appreciated. >> >> >> Thanks and Regards, >> Sandeep >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >-- Thanks and Regards, Sandeep Kumar Singh -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150707/572b1705/attachment.html>
Hi Jeremy, Thanks for detailed explanation. It is OK for C and C++, but as I know, Java is platform independent, will I face the same issue with it? Thanks and Regards, Sandeep On Tue, Jul 7, 2015 at 1:03 PM, Jeremy Lakeman <Jeremy.Lakeman at gmail.com> wrote:> Some LLVM IR could be portable. > > But the C/C++ languages are not designed to be portable in that way. Your > application will be including system headers with platform specific > information in them. For example, platform specific decisions about > structure memory layout, or runtime function names for linking against. > > On Tue, Jul 7, 2015 at 3:43 PM, Sandeep Kumar Singh < > deepdondo007 at gmail.com> wrote: > >> Hi, >> >> I am curious to know about LLVM IR as platform independent feature. >> I have compiler some C and C++ applications that compiled on Linux 64bit >> machine, now I want to generate bit code file on Windows 64bit machine. >> >> 1) Will this execute without any issues? >> 2) Do I pass any option for making it operating system portable? >> 3) Can I generate bit code file also on Linux machine and then run on >> Windows machine? >> >> Please give me some pointers? >> >> Any help will be highly appreciated. >> >> >> Thanks and Regards, >> Sandeep >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >-- Thanks and Regards, Sandeep Kumar Singh -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150707/f33e53a7/attachment.html>