[LLVMdev] Linkage Types

Reid Spencer reid at x10sys.com
Fri Nov 21 12:42:01 PST 2003


Okay, I'm past the GEP "have to dereference pointer first" problem of my
last post.

I now have a linkage error (I get undefined symbol when I try to
assemble the program).

gcc -o test.o test.s   says:
> /tmp/cczhiFk7.o(.text+0x7): In function `a':
> : undefined reference to `_index_'

_index_ is defined like this:
> %_index_ = external global long         ; <long*> [#uses=12]

But, that's not what I expected to get when I defined it in the compiler
like this:
>         TheIndex = new GlobalVariable(
>             /*type=*/Type::LongTy,
>             /*isConstant=*/false,
>             /*Linkage=*/GlobalValue::LinkOnceLinkage,
>             /*initializer=*/0,
>             /*name=*/"_index_",
>             /*parent=*/TheModule
>         );
>                                                                                                                                                              

So, reading the documentation again, I discover that LinkOnceLinkage is
an _internal_ (static) linkage type. Fine, but why does LLVM give it
"external global" linkage? 

Note that the Assembly reference says:
internal: ...
linkonce: ...
weak: ...
appending: ...
externally visible:
        If none of the above identifiers are used, the global is
        externally visible, meaning that it participates in linkage and
        can be used to resolve external symbol references.

But, there's no way to do this in the code. You _must_ supply the third
argument to GlobalVariable's constructor (it doesn't default) and the
only values accepted are GlobalValue::LinkageTypes. If I use
"ExternalLinkage" is this the same as providing nothing in assembly and
getting the default "externally visible"?
 
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/20031121/bd2ca631/attachment.sig>


More information about the llvm-dev mailing list