[Mesa-dev] [PATCH] radeon/llvm: Use LLVM C API for compiling LLVM IR to ISA.

Mathias Fröhlich Mathias.Froehlich at gmx.net
Thu Apr 25 03:17:55 PDT 2013


Jose,

On Thursday, April 25, 2013 01:38:46 Jose Fonseca wrote:
> What I'm suggesting doesn't require huge effort.
> 
> In detail, I'm suggesting:
> 
> (1) have a custom build of LLVM libraries with -fvisibility=hidden
> 
> (2) have a src/mesallvm/mesallvm.c containing wrappers
> 
>   #include <llvm-c/Core.h>
> 
> __attribute__((visibility("default")))
>   LLVMValueRef
>   MesaLLVMBuildAdd(LLVMBuilderRef Builder, LLVMValueRef LHS, LLVMValueRef
> RHS, const char *Name) { return LLVMBuildAdd(Builder, LHS, RHS, Name);
>   }
> 
>   ...
> 
>   plus a src/mesallvm/mesallvm.cpp with whatever custom C wrappers to C++
> functionality we need (e.g, the stuff in lp_build_misc.cpp).
> 
>   These two modules would be statically linked against the custom LLVM
> libraries from (1), producing a shared library libMESALLVM.so, which would
> be consumed by any Mesa driver that needs it. Because all symbols have the
> unique MESALLVM prefix, these should not collide with user stuff.
> 
> (3) have a src/mesallvm/mesallvm.h
> 
>    // Mange LLVM symbols before including them
>    #define LLVMBuildAdd MesaLLVMBuildAdd
> 
>    ...
> 
>    #include <llvm-c/Core.h>
>    ...
> 
>    All gallium code would include src/mesallvm/mesallvm.h instead. It can
> still use the LLVMFoo as befor.
> 
> And that's all there is to it.

Technically this will work.

But I fear that this build procedure is too non standard to be really picked 
up by the distribution builders. They would need to build a seperate llvm 
version inside of the mesa package. Doable, but do you think we can convince 
them all?

The technical problem you try to solve is that we need to force the llvm build 
to have the default hidden visibility.
I think we could achieve the same result by using a default built llvm static 
lib and explicitly mention the to be exported symbols in a linker script. IIRC 
we could even use wildcards there. That is only export everything starting 
with MesaLLVM*.

Remains that we need to write out all the wrappers, which I called 'huge 
effort'.

May be this could equally well done by looking with scripts at the llvm 
libraries and create an apropriate version script. Hide all symbols, except 
the ones starting with MesaLLVM and for each LLVM c symbol create an alias 
with the apropriate MesaLLVM symbol. Requires some shell or python hackery to 
generate the version script given the llvm c binding library.

> > Is it possible to hide all llvm calls behind the lp_bld_* interface or
> > similar
> > and put this layer into a single shared object statically linked with all
> > of llvm?
> 
> No, gallivm was not intended a full abstration to LLVM C bindings,
> furthermore it is not self-contained (it depends on lots of stuff from
> other auxiliary modules).
Ok.

> > Again OTOH, the dlopen flags are really made for this kind of module use I
> > think ...

I was referencing the patches that i just packed into the mail yesterday. This 
RTLD_LOCAL|RTLD_DEEPBIND flag already does what we need regarding isolation. 
This does not even require more changes than changing a bunch of dlopen flags - 
no wrappers to program.
What I am not sure about is if we isolate too much for mesa/dri internal needs 
with this.

> Nevertheless, I must insist that the problem of hiding LLVM symbols is
> handled in a layer underneath gallivm.  Severing gallivm module from the
> rest auxiliary gallium modules, or making gallivm a full wrapper for all
> LLVM symbols, seems unsustainable / too limiting IMO.
Huch, then I probably do not get you right.
Aren't you proposing a full wrapper of all the llvm c symbols by MesaLLVM* 
symbols above? Here you are calling exactly the same too limiting?

Greetings

Mathias



More information about the mesa-dev mailing list