This is an archive of the discontinued LLVM Phabricator instance.

[XCOFF][AIX] Emit TOC entries for object file generation
ClosedPublic

Authored by jasonliu on Nov 27 2019, 2:53 PM.

Details

Summary

Implement emitTCEntry for PPCTargetXCOFFStreamer.
Add TC csects to TOCCsects for object file writing.

Note:

  1. I did not include any raw data testing for this object file generation because TC entries raw data will all be 0 without relocation implemented. I will add raw data testing as part of relocation testing later.
  2. I removed "Symbol->setFragment(F);" for common symbols because we don't need it, and if we have it then we would hit assertions below:

Assertion `(SymbolContents == SymContentsUnset || SymbolContents == SymContentsOffset) && "Cannot get offset for a common/variable symbol"' failed.

  1. Fixed incorrect TOC-base alignment.

Diff Detail

Event Timeline

jasonliu created this revision.Nov 27 2019, 2:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 27 2019, 2:53 PM
jasonliu updated this revision to Diff 231446.Nov 28 2019, 8:50 AM
jasonliu edited the summary of this revision. (Show Details)

Fixed incorrect TOC-base alignment.

daltenty added inline comments.Nov 29 2019, 1:29 PM
llvm/lib/MC/XCOFFObjectWriter.cpp
281

A bit of a question: This assumes an ordering of CSects in the MCAssembler. This works because we always create the TOC base first. Is it OK to impose ordering requirements on the MCAssembler?

llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
254

Wouldn't a use of MAI->getCodePointerSize() be more appropriate here

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

nit: s/TOC-base/The TOC-base will/

DiggerLin added inline comments.Nov 29 2019, 5:13 PM
llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
247

I am prefer not to added a new Is64Bit here.
PPCTargetStreamer has a data member (MCStreamer). MCStreamer->getContext()->getAsmInfo()->getCodePointerSize().

254

PPCTargetStreamer has a data member (MCStreamer). MCStreamer->getContext()->getAsmInfo()->getCodePointerSize().

Can we use getCodePointerSize() instead of Is64Bit?

jasonliu marked 4 inline comments as done.Dec 3 2019, 8:52 AM
jasonliu added inline comments.
llvm/lib/MC/XCOFFObjectWriter.cpp
281

If we take AIX system assembler as the reference assembler, TOC-base has to come first even in assembly parsing. Otherwise, assembly code got rejected.
For example,
I got this when .toc is not before .tc:

...
LC..0:
        .tc a[TC],a
        .toc
...

Assembler:
toc.s: line 10: 1252-018 Use a .tc inside a .toc scope only.
        Precede the .tc statements with a .toc statement.
llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp
247

Thanks. Good idea.

254

Got it.

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

I will add "The", but I don't think we need "will" here (we are stating something that's always the case, not something that's going to happen in the future).

jasonliu updated this revision to Diff 231923.Dec 3 2019, 8:57 AM

Address David and Digger's comment.

daltenty accepted this revision.Dec 3 2019, 1:27 PM

LGTM

This revision is now accepted and ready to land.Dec 3 2019, 1:27 PM
This revision was automatically updated to reflect the committed changes.