This is an archive of the discontinued LLVM Phabricator instance.

[AIX] Handle LinkOnceODRLinkage and AppendingLinkage for static init gloabl arrays
ClosedPublic

Authored by Xiangling_L on Feb 27 2020, 2:05 PM.

Details

Summary

(1)LinkOnceODRLinkage:

emit .weak for the symbol;

(2) AppendingLinkage of llvm.global_ctors, llvm.global_dtors:
omit emitting anything from these two global arrays until we support -qtwolink similar behavior on AIX.

Diff Detail

Event Timeline

Xiangling_L created this revision.Feb 27 2020, 2:05 PM
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1952

As it stands, users can pass in IR with such linkage. This should be report_fatal_error because this is indeed reachable without being a clear bug elsewhere.

As for the text, it should say something like "There is no mapping that implements AppendingLinkage for XCOFF."

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1589

This list does not match AsmPrinter::EmitSpecialLLVMGlobal. I do not believe this function as it is named and implemented is okay.

Xiangling_L marked 4 inline comments as done.Mar 2 2020, 7:14 AM
Xiangling_L added inline comments.
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1952

Thank you, I will update it.

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1589

Thank you for pointing this out.

This list does not match AsmPrinter::EmitSpecialLLVMGlobal

This is because I am thinking to limit the scope of current AppendingLinkage work to LNT test, where all AppendingLinkagefailures are related to static init related llvm.global_ctors global array. Do you prefer to cover all AppendingLinkage related global arrays in this patch instead?

I do not believe this function as it is named and implemented is okay.

Yes, you are right. Probably the isSpecialLLVMGlobal is misleading, cuz this function doesn't cover all LLVM global symbols. Would isSpecialStaticInitGlobalArrays or isSpecialAIXStaticInitGlobalArrays be better? Or do you have any other suggestions?

As for the implementation, general LLVM implementation of AsmPrinter::EmitSpecialLLVMGlobal doesn't emit what we want for llvm.global_ctors and llvm.global_dtors on AIX. Since our initial patch of static init doesn't support -qtwolink similar behavior, we don't need to emit anything from these two arrays.

stevewan added inline comments.Mar 2 2020, 8:56 AM
llvm/test/CodeGen/PowerPC/aix-AppendingLinkage.ll
23

As a reminder, if you are to change llvm_unreachable("Should never emit it."); to something else, this check will need to be updated as well.

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1589

I agree that we should limit the cases where we skip generating code for symbols to cases that we are tracking.

Suggestion for the function name: isSpecialLLVMGlobalArrayForStaticInit.

llvm/test/CodeGen/PowerPC/aix-AppendingLinkage.ll
23

The message will cause a non-zero return code. We do not need this check; if we did, we should probably be piping the stderr to FileCheck.

Xiangling_L marked 5 inline comments as done.

Update the func name and the testcase;
Change llvm_unreachable to report_fatal_error;

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1596

Should there be a comment indicating why we are not emitting these? Would this be the place where we would add code to handle these instead of emitting them as arrays? In other words, should the comment be a TODO?

Xiangling_L marked 2 inline comments as done.Mar 5 2020, 7:27 AM
Xiangling_L added inline comments.
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1596

Good point. A TODO is necessary.

Would this be the place where we would add code to handle these instead of emitting them as arrays?

Based on what I have in mind so far, my own answer is yes. But the final implementation is open to be discussed for sure.

So I am thinking when we support .ref directive in the future for static init, based on the llvm.global_ctors/llvm.global_dtors array, this would be the place to add some code to document the relationship (using something like map )between object and the sinit/sterm function. And then later when we emit the .data object[e.g. t], we can easily query do we need to and how do we emit .ref info for t.

Xiangling_L marked an inline comment as done.

Add a TODO comment for global arrays of static init;

LGTM with minor comment.

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1597

Suggestion to add a second sentence:
Otherwise, we can skip these arrays, because the AIX linker collects these functions simply based on their name.

This revision is now accepted and ready to land.Mar 5 2020, 3:26 PM
Xiangling_L retitled this revision from [AIX] Handle LinkOnceODRLinkage and llvm.global_ctors/dtors' AppendingLinkage to [AIX] Handle LinkOnceODRLinkage and AppendingLinkage for static init gloabl arrays.Mar 6 2020, 6:02 AM
This revision was automatically updated to reflect the committed changes.