[LLVMdev] Linkage Types again!

Reid Spencer reid at x10sys.com
Sun Nov 23 14:08:00 PST 2003


The problem I'm experiencing with Stacker has to do with linkage types
(again!).

What I'm trying to do is create a "global appending" array. In
compilation units that don't include "main", I generate it with:

        TheStack = new GlobalVariable(
            /*type=*/ stack_type,
            /*isConstant=*/ false,
            /*Linkage=*/ GlobalValue::AppendingLinkage,
            /*initializer=*/ 0,
            /*name=*/ "_stack_",
            /*parent=*/ TheModule
        );
                                                                                                                                                             
Note that lack of an initializer. I think this makes it external.

When a main program is found, I take that same variable (TheStack)
and add an initializer:

 TheStack->setInitializer( Constant::getNullValue(stack_type) );

This should make it global but not external.

This used to work before some recent changes to LLVM. But, after the
changes, I now get:

Global is external, but doesn't have external linkage!
[1024 x int]* %_stack_

from the verifier. 

I tried changing the initial definition of TheStack to include an
initializer with no  modifications to it when there's a main. The
produces the (somewhat expected):


stkrc -e -f -o testing.bc /proj/work/llvm/projects/Stacker/test/testing.st
llc -f -o testing.s testing.bc
gcc -ggdb -L/proj/work/llvmobj/lib/Debug testing.s -lstkr_runtime -o eq eq.s
/tmp/ccYV2ZHL.o(.bss+0x0):/proj/work/llvmobj/projects/Stacker/test/eq.s:10: multiple definition of `_stack_'
/tmp/ccClZ4Vr.o(.bss+0x0):/proj/work/llvmobj/projects/Stacker/test/testing.s:10: first defined here
collect2: ld returned 1 exit status

I looked at GlobalValue::LinkageTypes hoping that the enumeration was a
set of bitfields that I could OR together to produce:

ExternalLinkage|AppendingLinkage

but, alas, the enumeration values are sequential.

So, how is this supposed to work?

Do I have to reset the linkage type after giving it an initializer? Why?

Reid.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20031123/bad00451/attachment.sig>


More information about the llvm-dev mailing list