[llvm-dev] What is the default linkage type?

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 13 07:03:31 PST 2022


On Thu, 13 Jan 2022 at 04:18, Russell Wallace via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> For a global variable, external linkage type seems to mean the same thing as extern in C: this is /not/ a definition, but a mere declaration of something that must be defined elsewhere.

That's what the `external` keyword on a global means, but the thing
being declared if that's used still has external linkage.

> But when a linkage type is not specified, the system doesn't seem to behave that way; instead, such a global variable seems to be treated as a definition.

Yes. A definition of a variable with external linkage.

I think the syntax is rather quirky in that area, I expect it dates
from the earliest days of the LLVM project. If I was redesigning it
I'd probably make the `external` mandatory with an optional definition
(and maybe turn `extern_weak` into `weak` too).

The LangRef could almost certainly be improved, I think it conflates
the keywords used in the textual IR with the conceptual linkage that
every global has, because they are the same thing or near enough for
all except "external".

Cheers.

Tim.


More information about the llvm-dev mailing list