This is an archive of the discontinued LLVM Phabricator instance.

[XCOFF] set fragment for XMC_PR csects.
ClosedPublic

Authored by Esme on Nov 2 2022, 12:53 AM.

Details

Summary

-xcoff-traceback-table is a default option on AIX regardless of optimization and debug levels. An error of relocation for paired relocatable term is not yet supported in XCOFFObjectWriter::recordRelocation occurred when both of the -xcoff-traceback-table and -function-sections are enabled.
The root cause is that we missed to calculate the symbols difference as absolute value before adding fixups when symbol_A without the fragment set is the csect itself and symbol_B is in it.
This patch only sets the fragment for XMC_PR csects because we don't have other cases that hit this problem yet.

Diff Detail

Event Timeline

Esme created this revision.Nov 2 2022, 12:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 12:53 AM
Esme requested review of this revision.Nov 2 2022, 12:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2022, 12:53 AM
Esme updated this revision to Diff 472873.Nov 3 2022, 2:00 AM

Clean test failure.

hubert.reinterpretcast added inline comments.
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
2223

Can we address this where the MCExpr is handled instead? There may be more ways a similar expression involving a csect as an operand is involved in the future (e.g., assembly parsing).

DiggerLin added inline comments.Nov 4 2022, 10:55 AM
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
2223

I do not think we should set setFragment of FuncSectSym in the function emitTracebackTable.
Reason as :

  1. because of both Asm path and "integrated-as" enter into the function emitTracebackTable. Asm path do not have Fragment concept.
  2. the emitTracebackTable only do emit trace back table related thing. we should not put other functionality here.

I think we may need to set the

The fragment value to CurrentFnSym of AsmPrinter in somewhere when "integrated-as"
otherwise the CurrentFnSym.isUndefined() is true.

it will cause the function MCExpr::evaluateAsRelocatableImpl() return "false" when evaluation the fixup of CurrentFnSym-FuncEnd

DiggerLin added inline comments.Nov 5 2022, 8:04 PM
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
2223

maybe you can try to set the fragment of QualName in the function MCSectionXCOFF *MCContext::getXCOFFSection.

   if (Begin)
     Begin->setFragment(F);

+ if (!IsDwarfSec && CsectProp->MappingClass ==XCOFF::XMC_PR){
+    QualName->setFragment(F);
+    QualName->setOffset(0);
+  }

not sure whether it work or not.

Esme updated this revision to Diff 473554.Nov 6 2022, 9:24 PM
DiggerLin added inline comments.Nov 8 2022, 6:55 AM
llvm/lib/MC/MCContext.cpp
833 ↗(On Diff #473554)

sorry that symbol offset is default by 0 . So we do not need to do

QualName->setOffset(0);
DiggerLin added inline comments.Nov 8 2022, 6:14 PM
llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll
8

do we want to test the 32bit too ?

Esme updated this revision to Diff 474696.Nov 11 2022, 2:05 AM

Addressed comments.
Thx @DiggerLin

DiggerLin accepted this revision.Nov 11 2022, 11:56 AM

LGTM, please wait for several days and Hubert maybe has comment on it. I do not think we need to check so many symbol items and relocation items in the test case, but I can not give any suggestion on it.

llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll
15

nit: change %t64.o

16

nit: change %t64.o

This revision is now accepted and ready to land.Nov 11 2022, 11:56 AM
llvm/lib/MC/MCContext.cpp
831 ↗(On Diff #474696)

The change looks reasonable, but I don't think it should be restricted to XMC_PR csects.

If we are being conservative about making changes, then let's leave a comment to say that the check for XMC_PR is here just because we don't have other cases that hit this problem yet.

We will probably find more to do if we can get the assembly parsing to resolve qualnames.

llvm/test/CodeGen/PowerPC/aix-xcoff-funcsect.ll
11

Please use --symbol-description and update the checks to expect the storage mapping class.

16

Same comment: Please use --symbol-description and update the checks to expect the storage mapping class.

Esme updated this revision to Diff 475061.Nov 13 2022, 11:29 PM

Addressed comments.
Thx @hubert.reinterpretcast and @DiggerLin

Addressed comments.

Thanks. Can you update the title and description?

The title should indicate "what" (set fragment). The description can further explain the "why".

I am a bit torn over not actually checking that the calculated function sizes are correct, but I guess that we can infer from there being no relocations generated for it that we are going through the right MCExpr processing.

Esme retitled this revision from [XCOFF] avoid unnecessary Fixups when -function-sections is enabled. to [XCOFF] set fragment for XMC_PR csects..Nov 15 2022, 6:30 PM
Esme edited the summary of this revision. (Show Details)

LGTM; no objection if we're planning to move ahead without checking the calculated size field in the traceback table.

This revision was landed with ongoing or failed builds.Nov 22 2022, 4:18 AM
This revision was automatically updated to reflect the committed changes.