[LLVMdev] Linkage Types

Chris Lattner sabre at nondot.org
Fri Nov 21 12:46:01 PST 2003


> 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?

Anything without an initializer gets external linkage...  Try initializing
it with Constant::getNullValue(Type::LongTy).

> 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"?

The thing about LLVM linkage is that linkage types do not apply for
external symbols (not to be confused with 'external linkage symbols').
When you link two translation units together, LLVM changes the external
symbol to work with whatever the linked symbols linkage is.  Thus, if you
want to make it 'linkonce', you should give it an initializer (making it
not be an external symbol).

I should probably add an assertion to this effect.  :)

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/





More information about the llvm-dev mailing list