[LLVMdev] ValueMapper question: no type mapping for GlobalValue?

Michael Muller mmuller at enduden.com
Tue Jan 17 05:45:51 PST 2012


So it looks like the verifier doesn't catch this condition - I think it
should.  The attached program reproduces the problem - verification succeeds,
but the linker fails with a type assertion.

BTW, if no one has the bandwidth to work on this I'm willing to attempt a fix,
assuming that you agree that the verifier should discover this condition.

Michael Muller wrote:
> 
> =?ISO-8859-1?Q?Rafael_=C1vila_de_Esp=EDndola?= wrote:
> > > I can reproduce this consistently, but only under an extremely large pile of
> > > code :-)  I haven't tried to strip it down to minimal a test case yet, but I
> > > will.  One salient difference with the code you've provided is that in my
> > > code, @a is a struct type.  However, changing the example to use a minimal
> > > structure doesn't trigger the assertion failure.
> > 
> > Is the example something you can share even in unreduced for?
> 
> As it turns out, the root cause was that I had a GlobalVariable that wasn't
> being copied to an extern in the new module under some circumstances, but was
> being used directly.  I would have expected the verifier pass to catch this,
> but it looks like we're probably not using the verifier except when running
> non-optimized + debug, which I never tried.
> 
> I'll recreate this situation just to verify that the verifier pass identifies
> the problem, if it doesn't I'll proceed from there but I'm currently assuming
> the problem is entirely ours :-)
> 
> If you think the behavior of the ValueMapper is incorrect in this situation,
> I'd prefer to furnish you with a minimal test case - the unreduced form
> involves checking out and building a specific revision of the Crack compiler
> and running one of the tests in "native" (AOT compile) mode.
> 
> Thank you for looking into this :-)
> 
> > 
> > > But I'm still curious: why doesn't the value mapper do type mapping on global
> > > variables?
> > 
> > I am not sure. I would probably have to look at a failing example to
> > know what is going on.
> > 
> > Cheers,
> > Rafael
> > 
> 
> 
> =============================================================================
> michaelMuller = mmuller at enduden.com | http://www.mindhog.net/~mmuller
> -----------------------------------------------------------------------------
> We are the music-makers, and we are the dreamers of dreams
>  - Arthur O'Shaughnessy
> =============================================================================
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 


=============================================================================
michaelMuller = mmuller at enduden.com | http://www.mindhog.net/~mmuller
-----------------------------------------------------------------------------
There is no way to find the best design except to try out as many designs as
possible and discard the failures. - Freeman Dyson
=============================================================================
-------------- next part --------------
/* build with:
   g++ `llvm-config --cxxflags --cppflags --ldflags`  \
        ReferencingExternalGlobal.cc \
        `llvm-config --libs core jit native instrumentation bitwriter ipo \
         linker` \
        -o ReferencingExternalGlobal
*/

#include <llvm/Module.h>
#include <llvm/Type.h>
#include <llvm/DerivedTypes.h>
#include <llvm/Linker.h>
#include <llvm/LLVMContext.h>
#include <llvm/PassManager.h>
#include <llvm/Analysis/Verifier.h>
#include <llvm/Constants.h>
#include <iostream>

using namespace std;
using namespace llvm;

int main(int argc, const char **argv) {
    LLVMContext &context = getGlobalContext();
    Module *mod1 = new Module("first", context);

    // create my structure type
    vector<Type *> members(1);
    members[0] = Type::getInt32Ty(context);
    StructType *type = StructType::create(context, members, "MyType");

    // create my initializer
    vector<Constant *> memberVals(1);
    memberVals[0] = Constant::getNullValue(Type::getInt32Ty(context));
    Constant *init = ConstantStruct::get(type, memberVals);

    // create a global in the first module
    GlobalVariable *gvar =
        new GlobalVariable(*mod1, type, false, // isConstant
                           GlobalValue::ExternalLinkage,
                           init,
                           "my_global_var"
                           );


    Linker *linker = new Linker("linker-name", "main-module",
                                context, 0);

    string errMsg;
    linker->LinkInModule(mod1, &errMsg);

    Module *mod2 = new Module("second", context);
    GlobalVariable *refGVar =
        new GlobalVariable(*mod2, type->getPointerTo(), false,
                           GlobalValue::ExternalLinkage,
                           gvar,
                           "referencing_variable"
                           );

    // do the verifier pass (completes successfully)
    PassManager pm;
    pm.add(createVerifierPass());
    pm.run(*mod2);

    // link mod2 (causes assertion failure)
    linker->LinkInModule(mod2, &errMsg);
}


More information about the llvm-dev mailing list