[LLVMdev] LLVM linkage flags
Tim Northover
t.p.northover at gmail.com
Fri Jul 24 11:09:27 PDT 2015
On 24 July 2015 at 10:24, Max Ruttenberg <mruttenberg at emutechnology.com> wrote:
>> ExternalLinkage: Externally visible function
That documentation is not ideal. As you've discovered it applies to
things other than functions.
> When I have source code like:
>
> int x = 0;
> int main(){...}
>
> I end up with an ExternalLinkage flag on x. Why would this not have
> CommonLinkage? When I have the same code as above and don't initialize x,
> I end up with the CommonLinkage flag.
It comes down to the requirements of the C specification. You're
allowed to have a simple "int x;" in multiple files and link them
together, but not an "int x = 0;". The rule dates from the bad-old
days of pre-ANSI C, and wouldn't be included in any sensible language
being created now.
But because of that rule, the two situations tend to be treated
differently in object formats so the linker can complain if you get it
wrong, and so LLVM has to have a way to represent it.
Cheers.
Tim.
More information about the llvm-dev
mailing list