[LLVMdev] LLVM porting Plan9 (probably stupid question)

John Criswell criswell at uiuc.edu
Tue Feb 23 07:44:08 PST 2010


Jens Staal wrote:
>
> I am not sure whether this would work or if there are other 
> limitations that would block this very simplistic porting strategy to 
> work. Since it looks so easy on paper, I expect it to be more 
> complicated otherwise it would probably already have been done.
>

A Plan 9 user.  Very cool.  I tried out Plan 9 about 10 or so years ago; 
I really like the private namespace feature, and ACME is cool.
>
>
> According to the LLVM FAQ the important dependencies for LLVM are a 
> unix-type shell and sed [1], but those dependencies are provided by 
> APE [4]. (according the the Plan9 mailing list there are issues with 
> C++ and how that has to be handled by the kernel, but I do not 
> understand exactly what the problem is). (I have not tried yet because 
> the only plan9 environment I have right now is 9vx, which is not ideal).
>

You might want to investigate exactly what C++ features don't work on 
Plan 9.  LLVM doesn't use some features (e.g., RTTI), so you might get 
lucky and have a C++ compiler that is sufficient for compiling LLVM.

Note that LLVM is heavily dependent on GCC and its version of 
libstdc++.  I'm assuming the C++ compiler on Plan 9 is based on GCC.  If 
it's not, all bets are off.
>
>
> Since LLVM is able to convert C++ to C [2] (with “ugly” result), 
> perhaps it would be possible to first convert the LLVM/Clang code to C 
> on a different host (BSD or Linux) and then compile the resulting code 
> (after some compatibility changes in header libraries or other code?) 
> with Pcc under APE on Plan9. Since LLVM/Clang now can compile itself 
> [3], if this would work, the following iterations of compiling 
> LLVM/Clang under Plan9/APE could be done directly from the C++ code?
>
I don't believe that this is a good approach because:

1) The LLVM C Backend (CBE) may not be working as well as it used to.  
Native code generation is much better now, so the CBE gets used less often.

2) Even if it does work, the generated C code will pull in all the 
structure definitions from the C and C++ header files (e.g., the 
definition for FILE *).  LLVM bitcode isn't portable, so if you compile 
against the Linux/BSD header files, you'll get an LLVM bitcode file that 
won't work on Plan 9.

You may want to consider a cross-compiling approach.  What you want to 
do is to set up a C++ compiler on a BSD/Linux machine that generates 
native code that runs on a Plan 9 system.  You can use either GCC or 
LLVM as the cross-compiler; the real trick will be a) Getting the Plan 9 
C header files on to the BSD/Linux system and arranged for use in 
cross-compiling and b) Getting libstdc++ cross-compiled for Plan 9.  I'm 
assuming that Plan 9 provides ANSI C header files (I believe, by 
default, Plan 9 uses an enhanced version of C that is not ANSI complaint).


-- John T.

>
>
>
> [1]
>
> “How portable is LLVM?” - depends on unix shell + sed
>
> http://llvm.org/releases/2.0/docs/FAQ.html
>
>
> [2]
>
> LLVM translate C++ to C
>
> http://llvm.org/releases/2.0/docs/FAQ.html#translatec++
>
>
> [3]
>
> Clang can now compile LLVM/Clang
>
> http://blog.llvm.org/2010/02/clang-successfully-self-hosts.html
>
>
> [4]
>
> APE/Psh : provides a Ksh-compatible shell + sed, Pcc POSIX compatible 
> C compiler.
>
> http://plan9.bell-labs.com/sys/doc/ape.html
>
>
>




More information about the llvm-dev mailing list