Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @[Linkage("value")] annotation (applies to fun) #15426

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ysbaddaden
Copy link
Contributor

Declares a new compiler annotation, Linkage, that may take one of the following values:

  • "external" —the symbol is referenced in the object file and is visible to all symbols from all object files (this is the default).

  • "internal" —the symbol will be referenced in the object file, but is only visible to symbols within that object only.

The annotation can only be specified on fun definitions (with a body). Incidentally it can also be specified to extern fun in lib declarations (without a body), though the only value accepted by LLVM will be external and a few other values (not implemented).

I chose to limit the possible values, and not expose all values from LLVM::Linkage. We should have a proper discussion about adding more. For example we might consider the weak value in a future development, but we'll need to correctly define what we mean with "weak" linkage (there are multiple definitions).

Related to #921

The annotation can be specified on fun definitions (with a body).
Incidently it can also be specified to extern fun in lib declarations
(without a body) in which case LLVM may only accept a few values
(external, weak).

The linkage is only set during codegen when `--single-module` is set,
since otherwise it would prevent any module from calling funs that are
always declared in the `main` module.
@straight-shoota
Copy link
Member

straight-shoota commented Feb 6, 2025

It would be nice to have a spec for this. This should be quite trivial: Build a binary which includes a fun with Linkage annotation, and check if the symbol exists in the output (via nm --extern-only or similar).

@straight-shoota straight-shoota added this to the 1.16.0 milestone Feb 7, 2025
@ysbaddaden
Copy link
Contributor Author

I added a spec that checks if the linkage as been correctly set on the LLVM bitcode.

That only tests the intended behavior, not that the linked binary behaves as expected, but it avoids having to find alternatives to nm on Windows, or relying on an external tool that might not be installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants