This is an archive of the discontinued LLVM Phabricator instance.

[AIX][TLS] Add support for TLS variables to XCOFF object writer
ClosedPublic

Authored by NeHuang on Mar 19 2021, 6:06 AM.

Details

Summary

This patch adds support for TLS variables to the XCOFF object writer:

  • Add new TData and TBSS sections
  • Add new CsectGroups for the mapping classes XCOFF::XMC_TL and XCOFF::XMC_UL
  • Add XMC_UL in the enum entry of CsectStorageMapping class to print the string while reading the symbol properties for TLS variables.
  • Fix the starting address of TData and TBSS sections

Diff Detail

Event Timeline

NeHuang created this revision.Mar 19 2021, 6:06 AM
NeHuang requested review of this revision.Mar 19 2021, 6:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 19 2021, 6:06 AM
DiggerLin added inline comments.Mar 22 2021, 8:02 AM
llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables-data-sect-off.ll
4 ↗(On Diff #331848)

maybe wo do not need to test file-header here , it already test in other patch

we maybe also need to use llvm-objdump to test the data content of .tdata

llvm/lib/MC/XCOFFObjectWriter.cpp
314

should be
XCOFF::XTY_CM == MCSec->getCSectType() ?

DiggerLin added inline comments.Mar 22 2021, 8:52 AM
llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll
105

I am not sure whether we need to test all the symbols again ? ,may be we only need to test the symbosl which effect by the -data-sections=on.

I think we also need to use llvm-objdump to test the content of .tdata ?

DiggerLin added a comment.EditedMar 22 2021, 8:56 AM

and I am slightly prefer to combine the two test files into one. because the only different is data-section is on or off. we can use different --check-prefix for them

NeHuang added inline comments.Mar 22 2021, 9:07 AM
llvm/lib/MC/XCOFFObjectWriter.cpp
314

For the TLS external reference case, we are setting SMC to XCOFF::XMC_UL with the csect type of ER in the function TargetLoweringObjectFileXCOFF::getSectionForExternalReference

DiggerLin added inline comments.Mar 22 2021, 11:58 AM
llvm/lib/MC/XCOFFObjectWriter.cpp
314

the TLS external symbol not put in the .tbss .

NeHuang updated this revision to Diff 332652.Mar 23 2021, 6:18 AM

Address review comments.

NeHuang marked 3 inline comments as done.Mar 23 2021, 6:22 AM
NeHuang added inline comments.
llvm/lib/MC/XCOFFObjectWriter.cpp
314

Yes, you are right. Updated.

NeHuang updated this revision to Diff 332657.EditedMar 23 2021, 6:31 AM
NeHuang marked an inline comment as done.

Address review comment to

  • Remove file header check in the test case
  • Merge data section ON/OFF into one test case
  • Fix the assert check condition
  • Check for llvm-objdump outputs
  • Print XMC_UL in the symbol table
DiggerLin added inline comments.Mar 23 2021, 8:15 AM
llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll
5

change --check-prefix=OBJ to --check-prefix=SECTION ?

10

ditto

12

if do not use --symbol-description , I think llvm-objdump -D for -data-sections=on / off should be same.

15

since we do not support generating 64bits object file. I do not think we need two different not --crash llv for -data-sections on and off.

518

suggest to remove the external from @tls_global_int_external_val_initialized , it is not a external variable.

519

ditto

525

change @tls_global_int_external_uninitialized to @tls_global_int_external ?

527

change @tls_global_double_external_uninitialized to @tls_global_double_external

NeHuang updated this revision to Diff 332986.Mar 24 2021, 7:37 AM
NeHuang marked 8 inline comments as done.

Address review comment to

  • Change prefix name from OBJ to SECTION
  • Only keep one 64 bits object file check for data sections on
  • clang-format
llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll
12

yes, it will be same without adding --symbol-description. As discussed offline, we will keep --symbol-description to check the storaging mapping class in the dump.

518

As discussed offline, we will keep these cases to check for tls variables with external linkage:

  • zero initialized
  • value initialized
  • un-initialized (external reference)
DiggerLin accepted this revision.Mar 24 2021, 10:58 AM

LGTM, please wait for 24 hours before commit . maybe other reviewer still have some comment.

llvm/lib/MC/XCOFFObjectWriter.cpp
316

change to " must be an uninitialized csect." ?

This revision is now accepted and ready to land.Mar 24 2021, 10:58 AM
NeHuang updated this revision to Diff 333078.Mar 24 2021, 11:51 AM

Update the assert message.

llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll
27

I don't like that the .text section here has size zero. This way, the test doesn't check that the thread-local sections are placed in a separate address space starting again at 0.

NeHuang updated this revision to Diff 333368.Mar 25 2021, 11:23 AM

Addressed review comment to

  • Define a constatnt variable in the test case to ensure .text section size not zero.
  • Add a case with an alias to a thread-local variable as discussed offline.
NeHuang marked an inline comment as done.Mar 25 2021, 11:24 AM
llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll
38–39

This doesn't match the behaviour of the AIX assembler (and also of the XL compiler). The .tdata section starts again at address 0x0.

It seems the documentation is wrong one way or the other though. It says (regarding s_paddr):

This field should contain 0 for all sections except the .text , .data , and .bss sections.

but it is not the case that the .tbss starts again at 0x0 (it does follow .tdata).

llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll
253

This needs to be written based on INDX as well. The same comment applies to the other ContainingCsectSymbolIndex lines.

NeHuang added a comment.EditedMar 26 2021, 12:15 PM

Thanks @hubert.reinterpretcast for the good catch! Just confirmed locally the section address and csect addresss for .tdata and .tbss do not match the results generated by AIX system assembler.
Working on computing proper physical/virtual addresses for the two new sections .tdata and .tbss. For .tbss case, I am not sure if it should follow the current documentation. I am starting the implementation following .tdata address to match the behavior of AIX assembler.

NeHuang updated this revision to Diff 333911.Mar 29 2021, 9:42 AM
  • Fix the starting address for .tdata and .tbss sections to match the behaviour of the AIX assembler.
  • Update the CHECK for ContainingCsectSymbolIndex using INDX
NeHuang edited the summary of this revision. (Show Details)Mar 29 2021, 9:43 AM

Gentle ping.