This is an archive of the discontinued LLVM Phabricator instance.

[AIX][TLS] Generate TLS variables in assembly files
ClosedPublic

Authored by NeHuang on Feb 5 2021, 2:51 PM.

Details

Summary

This patch allows generating TLS variables in assembly files on AIX.
Initialized and external uninitialized variables are generated with the
.csect pseudo-op and local uninitialized variables are generated with
the .comm/.lcomm pseudo-ops. The patch also adds a check to
explicitly say that TLS is not yet supported on AIX.

Diff Detail

Event Timeline

bsaleil created this revision.Feb 5 2021, 2:51 PM
bsaleil requested review of this revision.Feb 5 2021, 2:51 PM
bsaleil updated this revision to Diff 322203.Feb 8 2021, 1:30 PM

Add support for variables with internal linkage.

jsji added a reviewer: Restricted Project.Feb 8 2021, 1:54 PM
jasonliu accepted this revision.Feb 9 2021, 7:26 AM

LGTM with minor nit.

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
2224

nit: reformat as the suggestion.

llvm/lib/MC/MCSectionXCOFF.cpp
41

nit:

This revision is now accepted and ready to land.Feb 9 2021, 7:26 AM
amyk added a subscriber: amyk.Feb 9 2021, 7:51 AM
amyk added inline comments.
llvm/lib/MC/MCSectionXCOFF.cpp
41

Would it be helpful to mention in the comment that the initialized data are generated with the .csect pseudo-op?

daltenty added inline comments.Feb 9 2021, 6:28 PM
llvm/test/CodeGen/PowerPC/aix-tls-variables.ll
14 ↗(On Diff #322203)

nit: technically we emit into separate csects. not XCOFF sections.

15 ↗(On Diff #322203)

same as above

daltenty added inline comments.Feb 9 2021, 7:12 PM
llvm/test/CodeGen/PowerPC/aix-tls-variables.ll
21 ↗(On Diff #322203)

It's out of scope for this patch, but there is definitely a delta here between how we emit thread-local (to .tbss) and non-thread local uninitialized data (i.e. to regular data section instead of bss) beyond just the thread-local part. Not sure if that's something we should address.

daltenty accepted this revision.Feb 9 2021, 7:30 PM

LGTM, with minor nit

daltenty requested changes to this revision.Feb 9 2021, 8:06 PM
daltenty added inline comments.
llvm/test/CodeGen/PowerPC/aix-tls-variables.ll
21 ↗(On Diff #322203)

As a follow on, as discussed offline, using common for uninitialized data may have linkage considerations. We should consider if this applies to .tbss data as well before using .comm directives.

This revision now requires changes to proceed.Feb 9 2021, 8:06 PM
bsaleil updated this revision to Diff 322834.Feb 10 2021, 3:06 PM

Generate uninitialized external TLS data with the .csect directive instead of .comm

bsaleil edited the summary of this revision. (Show Details)Feb 10 2021, 3:07 PM
sfertile accepted this revision as: sfertile.Feb 12 2021, 10:39 AM

LGTM. Please wait until David has given it the OK too though.

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
2216

Maybe if you add a comment before : XCOFF::XMC_UL; clang-format will end up keeping a similar layout to what you already have. If not we should follow clang-format even though its inferior in this instance 😦 .

daltenty added inline comments.Feb 12 2021, 3:07 PM
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
2105

!GV->hasExternalLinkage() doesn't actually imply the symbol is local, we probably want something more like isLocalLinkage()

We should add some testcases for other non-local linkages like weak.

NeHuang commandeered this revision.Feb 16 2021, 8:24 AM
NeHuang added a reviewer: bsaleil.
NeHuang updated this revision to Diff 324783.EditedFeb 18 2021, 2:57 PM

@daltenty As per discussion offline

  • Update the code to check isLocalLinkage
  • More test coverage for weak linkage and update test case
  • clangformat the patch
NeHuang marked 2 inline comments as done.Feb 18 2021, 2:58 PM
daltenty added inline comments.Feb 18 2021, 3:27 PM
llvm/test/CodeGen/PowerPC/aix-tls-variables.ll
53 ↗(On Diff #324783)

We're missing the csect directives here

122 ↗(On Diff #324783)

Was this supposed to be initialized?

NeHuang updated this revision to Diff 325422.Feb 22 2021, 5:36 AM
  • Fix the missing directives printing for weak linkage.
  • Update the test case accordingly.
NeHuang marked 2 inline comments as done.Feb 22 2021, 5:37 AM
NeHuang added inline comments.
llvm/test/CodeGen/PowerPC/aix-tls-variables.ll
122 ↗(On Diff #324783)

Yes, updated.

lei added a subscriber: lei.Feb 22 2021, 1:25 PM
lei added inline comments.
llvm/test/CodeGen/PowerPC/aix-tls-variables.ll
111 ↗(On Diff #325422)

it would be easier to verify these checks if they were placed right before the declaration of the variable they are checking. Similar to what is done when we write checks for multiple functions.

daltenty added inline comments.Feb 22 2021, 3:47 PM
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
2215

Remove the second sentence here. Where other things get mapped depends on data-sections and other factors that aren't relevant to this block.

2217

I'm thinking this condition is important enough for us to provide a convince function. Something like isEligibleForCommonCsect and use it in the other three places where this exact condition should appear.

llvm/lib/MC/MCObjectFileInfo.cpp
890

We should initialize and use the TLSBSSSection where appropriate.

llvm/test/CodeGen/PowerPC/aix-tls-variables.ll
52 ↗(On Diff #325422)

Should probably be UL, since this is uninitialized

daltenty added inline comments.Feb 22 2021, 3:49 PM
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
2280

We should have another case for Kind.isThreadBSS, where we should probably use either a csect with XMC_UL or TLSBSSSection depending on TM.getDataSections()

NeHuang marked an inline comment as done.Feb 22 2021, 4:20 PM
NeHuang added inline comments.
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
2280

Agree, we should add the coverage for non-initialized cases using Kind.isThreadBSS()
Should we use Kind.isThreadData() check instead of Kind.isThreadLocal() for the initialized cases?

llvm/lib/MC/MCSectionXCOFF.cpp
70

We would also need isEligibleForCommonCsect check to be aligned here.

96

We need to cover the other TLS scenario here which is not eligible for commonCsect - to print CsectDirective.

llvm/test/CodeGen/PowerPC/aix-tls-variables.ll
111 ↗(On Diff #325422)

Sure. Will also alternate the test cases as below
non-tls variable
tls variable
...
...

NeHuang updated this revision to Diff 325802.Feb 23 2021, 8:14 AM

Rebased the patch to be aligned with interface change of function getXCOFFSection

NeHuang added inline comments.Feb 23 2021, 1:22 PM
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
2105

Update the comments to explain all the scenarios.

2112

check if "GV->hasInternalLinkage()" and "GVKind.isThreadBSS() && GlobalValue::isLocalLinkage(GV->getLinkage())" are equivalent

NeHuang updated this revision to Diff 327424.Mar 2 2021, 5:52 AM
daltenty accepted this revision.Mar 2 2021, 7:32 AM

LGTM with minor comment and naming fixes

llvm/test/CodeGen/PowerPC/aix-tls-variables-ppc32.ll
24

As discussed offline, we should rename these from TL/UL to something a bit more descriptive

This revision is now accepted and ready to land.Mar 2 2021, 7:32 AM
daltenty added inline comments.Mar 2 2021, 10:22 AM
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
2289

As we recently found out XCOFF::XMC_UL implies XCOFF::XTY_CM in the assembler.

Since we may have external linkage symbols inside this section, we cannot use XCOFF::XTY_CM, so we must use XMC_TL here.

2292

Same as earlier, we cannot emit this to TLSBSSSection. Any external linkage symbols inside it will make the assembler unhappy.

llvm/lib/MC/MCObjectFileInfo.cpp
898

Based on testing XMC_UL implies XMC_CM so this isn't actually a legal combination. We should probably add an assert to that extent in a follow on patch.

Also, we can't actually use this section as is in this patch anymore, so I suggest we leave out the initialization and move it to a follow on patch.

NeHuang marked an inline comment as not done.Mar 2 2021, 2:20 PM
NeHuang added inline comments.
llvm/lib/MC/MCSectionXCOFF.cpp
41

here should be initialized TLS data

NeHuang updated this revision to Diff 327612.Mar 2 2021, 4:13 PM

Addressed the review comments to

  • Fix the storaging map class for zero-initialized TLS data with external/weak linkage and update the test cases.
  • Renaming the test cases with proper description (zero-initialized, val-initialized and uninitialized
  • Add more comments for the implementation and correct some minors.
This revision was landed with ongoing or failed builds.Mar 2 2021, 4:23 PM
This revision was automatically updated to reflect the committed changes.