This is an archive of the discontinued LLVM Phabricator instance.

[XCOFF] Don't emit non-external labels in the symbol table and handle MCSA_LGlobal
ClosedPublic

Authored by daltenty on Feb 21 2020, 8:22 AM.

Details

Summary

We need to handle the MCSA_LGlobal case in emitSymbolAttribute for functions marked internal in the IR so that the
appropriate storage class is emitted on the function descriptor csect. As part of this we need to make sure that external
labels are not emitted into the symbol table, so we don't emit the descriptor label in the object writing path.

Diff Detail

Event Timeline

daltenty created this revision.Feb 21 2020, 8:22 AM
daltenty updated this revision to Diff 245874.Feb 21 2020, 8:25 AM
  • Add missing newline
jasonliu added inline comments.
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
688 ↗(On Diff #245874)

I understand this is to make the object writing case and assembly case to be equivalent.
But I think this changes the original design intent. The intent was when it is a static function, we do not need an label in the symbol table at all. (@Xiangling_L Correct me if I'm wrong.) Also I'm not sure if it actually make sense to have a label in the symbol table that is not external.
So in order to not change the design intent, I think the way to fix is the other way around. i.e although we registered a symbol, but if it is a label and is C_HIDEXT, do not add the symbol into csect's symbol list. So that we do not need to emit the internal label in the object file generation.

llvm/lib/MC/MCXCOFFStreamer.cpp
17

Do we need this include at all?

llvm/test/CodeGen/PowerPC/aix-internal.ll
9

Remove #0

21

Without the present of SymbolType, I'm not sure what are we testing here. Are we expecting a label or a csect, or both?

daltenty marked an inline comment as done.Feb 21 2020, 1:09 PM
daltenty added inline comments.
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
688 ↗(On Diff #245874)

Hmm, I do agree this does diverge from the original design intent, though I'm not sure that is avoidable for reasons outlined below.

With regard to whether it actually makes sense to have a label in the symbol table that is not external, this seems to be the entire intent of the the .lgobl directive. The directive seems to be for statics that need to be kept in the symbol table (I'm assuming for relocation and other purposes). For that reason, I don't think it makes sense to eliminate them in the XCOFFObjectWriter as proposed.

Given that we can't just eliminate them in the XCOFFObjectWriter. I think we have two options:

  1. Change the fact that we don't emit the lgobl on the label in the assembly path. Then we will be consistent between the object writing and assembly writing paths. Though it does diverge from the original design and what both xl and gcc do, the extra label in the symbol table should be fairly harmless.
  1. Perhaps it would be less confusing to eliminate this particular label altogether? We ran into difficulties with it with the TOC as well. We already have the csect symbol which we can use in the place of this symbol in most places. This might need some larger refactoring for places we try to get a function's symbol though.
jasonliu added inline comments.Feb 21 2020, 5:27 PM
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
688 ↗(On Diff #245874)

The two options listed are more like a workaround to the problem.
I think the real issue underneath is that, as an
integrated-assembler, we should be able to handle case like

.csect a[xx]
b:
...

Label b does not appear in the symbol table.

.globl/.lglobl/.weak/.extern b
.csect a[xx]
b:
...

b should appear in the symbol table.

But right now, I don't think we could handle that. And we might want to fix this instead.

daltenty planned changes to this revision.Feb 24 2020, 6:27 AM
Xiangling_L added inline comments.Feb 24 2020, 7:30 AM
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
688 ↗(On Diff #245874)

Yes, your understanding is correct. Omitting function descriptor label symbol when it's a static function is an optimization.

daltenty marked an inline comment as done.Feb 24 2020, 8:38 AM
daltenty added inline comments.
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
688 ↗(On Diff #245874)

I agree this is the underlying issue. Ideally, we should be able to handle this with MCSymbol which are Temporary. That seems to be how other targets handle user written assembler temporaries.

In this case the label here would be marked as Temporary and we would not emit it naturally in the symbol table. This would require some major restructuring of how this symbol gets created however, since this property can only be set at creation time currently.

However, we have another bit of an issue with this approach. It looks like other assembly dialects use a prefix to indicate this, and set the attribute when the symbol is created, where we use a directive so we cannot know this at the time the symbol is created. So we'd need a mechanism to set it afterwards anyway.

daltenty marked an inline comment as done.Feb 25 2020, 9:42 AM
daltenty added inline comments.
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
688 ↗(On Diff #245874)

Summarizing offline discussion: We will use the external attribute to determine if the label should be emitted into the symbol table. In a follow on patch we will have to set that appropriately for the assembly parsing case when encountering .lgobl and family directives.

daltenty updated this revision to Diff 246493.Feb 25 2020, 9:43 AM
  • Use external to determine if we should emit the symbol table entry
  • Revert to not emitting linkage on the descriptor if it's a static
  • Update test to refer to csect
daltenty marked an inline comment as done.Feb 25 2020, 9:46 AM
daltenty added inline comments.
llvm/lib/MC/MCXCOFFStreamer.cpp
17

This should probably be here to include what we use.

daltenty planned changes to this revision.Feb 25 2020, 12:14 PM
jasonliu accepted this revision.Feb 25 2020, 12:31 PM

Some nit comments. Otherwise, LGTM.

llvm/lib/MC/MCXCOFFStreamer.cpp
13

Why do we move this "#include" here?

llvm/lib/MC/XCOFFObjectWriter.cpp
351

nit: Maybe avoid double negate?
Suggestion:
Only put label into the symbol table when it is an external label.

daltenty updated this revision to Diff 246572.Feb 25 2020, 2:25 PM
  • Update tests with labels that shouldn't be in the objectfile
This revision is now accepted and ready to land.Feb 25 2020, 2:25 PM
daltenty marked 3 inline comments as done.Feb 25 2020, 2:29 PM
daltenty added inline comments.
llvm/lib/MC/MCXCOFFStreamer.cpp
13

Per the style guide, a "Main Module Header" should come first in the include list. This is where clang-format will place it.

daltenty marked an inline comment as done.Feb 25 2020, 2:32 PM
daltenty updated this revision to Diff 246574.Feb 25 2020, 2:32 PM
  • Update comment
daltenty retitled this revision from [XCOFF] Handle MCSA_LGlobal in emitSymbolAttribute to [XCOFF] Don't emit non-external labels and handle MCSA_LGlobal in emitSymbolAttribute.Feb 25 2020, 2:42 PM
daltenty edited the summary of this revision. (Show Details)
daltenty retitled this revision from [XCOFF] Don't emit non-external labels and handle MCSA_LGlobal in emitSymbolAttribute to [XCOFF] Don't emit non-external labels in the symbol table and handle MCSA_LGlobal.
This revision was automatically updated to reflect the committed changes.