Skip to content

[NVPTX] Use .common linkage for common globals #84416

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

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

AlexMaclean
Copy link
Member

Switch from .weak to .common linkage for common global variables where possible. The .common linkage is described in PTX ISA 11.6.4. Linking Directives: .common

Declares identifier to be globally visible but “common”.

Common symbols are similar to globally visible symbols. However multiple object files may declare the same common symbol and they may have different types and sizes and references to a symbol get resolved against a common symbol with the largest size.

Only one object file can initialize a common symbol and that must have the largest size among all other definitions of that common symbol from different object files.

.common linking directive can be used only on variables with .global storage. It cannot be used on function symbols or on symbols with opaque type.

@AlexMaclean AlexMaclean requested review from Artem-B and AaronBallman and removed request for AaronBallman March 8, 2024 01:55
@Artem-B Artem-B requested a review from MaskRay March 8, 2024 18:35
@Artem-B
Copy link
Member

Artem-B commented Mar 8, 2024

@MaskRay can you double check that PTX's idea of common matches what LLVM promises for GVar->hasCommonLinkage()?

The patch LGTM otherwise.

@MaskRay
Copy link
Member

MaskRay commented Mar 12, 2024

I am not familiar with NVPTX. Is the common symbol behavior similar to things described on https://maskray.me/blog/2022-02-06-all-about-common-symbols ?

@Artem-B
Copy link
Member

Artem-B commented Mar 12, 2024

My understanding is that we should follow the "standard" linking rules for C++ and ELF objects.

The quote in the PR description is all NVIDIA docs say about the .common directive. On the surface it does seem to match the standard behavior of common data, but I'm not very familiar with it. I mostly dealt with the problems it caused when some things were made common when they should not have been.

@AlexMaclean AlexMaclean merged commit 8f0012d into llvm:main Mar 14, 2024
@Artem-B
Copy link
Member

Artem-B commented Mar 15, 2024

Looks like with this patch we're generating .common even when we're compiling for older PTX version.

The common-linkage.ll test actually fails if you happen to run it with ptxas enabled.

Sterling-Augustine added a commit that referenced this pull request Mar 15, 2024
This reverts commit 8f0012d.

The common-linkage.ll test fails with ptxas enabled.
@Sterling-Augustine
Copy link
Contributor

I went ahead and reverted this in d4a8e97 due to the breakage under ptxas.

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.

4 participants