Page MenuHomePhabricator

Output XCOFF object text section header and symbol entry for program code
ClosedPublic

Authored by DiggerLin on Aug 29 2019, 11:44 AM.

Details

Summary

Original form of this patch is provided by Stefan Pintillie.

  1. The patch try to output program code section header , symbol entry for program code (PR) and Instruction into the raw text section.
  2. The patch include how to alignment and layout the CSection in the text section.
  3. The patch also reorganize the code , put some codes into a function(XCOFFObjectWriter::writeSymbolTableEntryForControlSection)

Additional: We can not add raw data of text section test in the patch, If want to output raw text section data,it need a function description patch first.

Diff Detail

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
DiggerLin added inline comments.Sep 25 2019, 12:41 PM
llvm/lib/MC/XCOFFObjectWriter.cpp
351 ↗(On Diff #221597)

changed as suggestion

356 ↗(On Diff #221597)

changed as suggestion

391 ↗(On Diff #221597)

changed as suggestion

DiggerLin marked an inline comment as done.Sep 25 2019, 12:42 PM
DiggerLin updated this revision to Diff 221826.Sep 25 2019, 1:25 PM
sfertile added inline comments.Sep 26 2019, 10:39 AM
llvm/lib/MC/XCOFFObjectWriter.cpp
354 ↗(On Diff #221826)

Minor nit: Extra space after TODO

488 ↗(On Diff #219365)

I'm OK with postponing the overflow checking for now, since there is only 3 sections we might be emitting.

490 ↗(On Diff #220573)

I don't see how the change helps readability. Originally we have a single variable that represent the next assignable address in the file. When we assign a section start address it simply starts at that next available address. After the change we now have a variable to track the SectionStartAddress, which doesn't seem any different or special compared to any of the other addresses we assign. And we have the extra overhead of creating a local and assigning that with the value of section start address, then modifying that in the loop making sure we have to copy its modified value out to SectionStartAddress at the end of the loop. Why is the sections start address different from any other address we assign in the loop? In what way does having the extra variable increase readability?

llvm/test/CodeGen/PowerPC/aix-return55.ll
8

Still missing the : in the CHECK-LABEL line.

DiggerLin marked 3 inline comments as done.Sep 26 2019, 1:39 PM
DiggerLin added inline comments.
llvm/lib/MC/XCOFFObjectWriter.cpp
354 ↗(On Diff #221826)

changed

490 ↗(On Diff #220573)

changed as suggestion.

llvm/test/CodeGen/PowerPC/aix-return55.ll
8

added

DiggerLin updated this revision to Diff 222022.Sep 26 2019, 1:56 PM
llvm/lib/MC/XCOFFObjectWriter.cpp
298 ↗(On Diff #222022)

We have code that introduces alignment padding, so I suspect we should have code here to write out the padding.

391 ↗(On Diff #221597)

There are some cases here of two consecutive spaces. It is not necessarily wrong, but we should be consistent.

llvm/test/CodeGen/PowerPC/aix-xcoff-common.ll
84 ↗(On Diff #222022)

I think this warrants more explanation. Is the ability of the regex to match non-space characters intended?

we can not generate a raw data of the '.text" XCOFF section.
there are upcoming patch which deal with the DS csect , I think we will add the test in that patch @jasonliu.

I believe that the .text section testing should be separate. The fact that the patch you mention would enable the ability to generate a non-zero size XCOFF .text section does not mean that it should cover testing beyond its own scope.

From the current patch, we have identified a need for follow-up patches to test .text sections that aren't empty, to test the placement of symbol names, and to address the naming of a field that this patch uses for a different purpose. If the second sounds out-of-place, then that is because the current commit message does not actually describe the scope of the patch well. The patch did a refactoring of interfaces, and that portion of the patch is why the second follow-up patch is tied to this one.

Please update the commit message to describe the scope of the current patch (especially that necessary dependencies for there to be non-empty .text sections have not landed) and to indicate a plan for follow-on patches.

llvm/lib/MC/XCOFFObjectWriter.cpp
525 ↗(On Diff #222022)

A comment is necessary here regarding alignment padding between the start of the section and the first item allocated within the section (which might require a stricter alignment). A question is why such padding is done "physically" in within the section as opposed to doing the padding "virtually" by adjusting the section's address in the address space.

DiggerLin retitled this revision from Output XCOFF object text section to Output XCOFF object text section header and symbol entry for program code.Oct 1 2019, 7:09 AM
DiggerLin marked 7 inline comments as done.Oct 1 2019, 8:45 AM
DiggerLin added inline comments.
llvm/lib/MC/XCOFFObjectWriter.cpp
298 ↗(On Diff #222022)

Added new function to support it.

525 ↗(On Diff #222022)

added a comment

391 ↗(On Diff #221597)

delete extras space.

llvm/test/CodeGen/PowerPC/aix-xcoff-common.ll
84 ↗(On Diff #222022)

there is Index: 0

Name: .text

before Symbol {

Index: 2
Name: a

origin test case will match .text symbol first and the value of Index will be zero.

using ; SYMS: Index: #Index:{{[[:space:]].*}}Name: a
can make sure that it match Symbol {

Index: 2
Name: a

not symbol .text and the index value will 2.

DiggerLin updated this revision to Diff 222633.Oct 1 2019, 8:48 AM
DiggerLin marked 2 inline comments as done.
DiggerLin edited the summary of this revision. (Show Details)
DiggerLin updated this revision to Diff 222649.Oct 1 2019, 10:43 AM

added a new padding zero for the section and csection.

DiggerLin updated this revision to Diff 222678.Oct 1 2019, 12:58 PM

updated two test cases.
as
SYMS: Index: #Index:{{[[:space:]]*}}Name: a

We need to verify if we need the storage padding or not before finalizing, but otherwise the patch looks pretty good.

llvm/lib/MC/XCOFFObjectWriter.cpp
69 ↗(On Diff #222678)

We might be able to skip writing the actual zeros for padding, and instead just pad out the virtual addresses assigned to the sections/csects. I believe @hubert.reinterpretcast was following up with one of the AIX system toolchain devs to verify.

537 ↗(On Diff #222678)

I'm sorry Digger, but I am having trouble figuring out what the comment is trying to convey.

Is it that each section is padded out to DefaultSectionAlign so that Address must be properly aligned already?

Is it trying to explain how we don't have to align the sections virtual address anymore then DefaultSectionAlign (even when contained csects may be more strictly aligned then that) becuase the sections alignment is immaterial?

DiggerLin updated this revision to Diff 223085.Oct 3 2019, 1:54 PM

first Csect of each section do not need padding zero. And we also need to adjust section virtual address to first Csect's address.

DiggerLin edited the summary of this revision. (Show Details)Oct 7 2019, 8:40 AM
DiggerLin edited the summary of this revision. (Show Details)Oct 7 2019, 8:42 AM
llvm/lib/MC/XCOFFObjectWriter.cpp
89 ↗(On Diff #223085)

Remove this field (see comments on later lines).

103 ↗(On Diff #223085)

Remove this field (see comments on later lines).

511 ↗(On Diff #223085)

The inter-csect padding is not really a property of the csect requiring alignment. We do not need to store this value here. The amount of padding to write can be determined by tracking the virtual address of the raw section data being written during the serialization into the object file. The next virtual address following the padding should be Csect.Address.

525 ↗(On Diff #223085)

The Size field accounts for the padding. We do not need to store this value here. The amount of padding to write can be determined by tracking the virtual address of the raw section data being written during the serialization into the object file. The next virtual address following the padding should be Text.Address + Text.Size.

llvm/lib/MC/XCOFFObjectWriter.cpp
357 ↗(On Diff #219365)

@DiggerLin, please post such a patch (perhaps going so far as to rename the field to SectionOrLength) so we do not lose track of this.

DiggerLin marked an inline comment as done.Oct 8 2019, 10:42 AM
DiggerLin added inline comments.
llvm/lib/MC/XCOFFObjectWriter.cpp
357 ↗(On Diff #219365)

I created a NFC patch. https://reviews.llvm.org/D68650

DiggerLin marked 5 inline comments as done.Oct 9 2019, 8:56 AM
DiggerLin added inline comments.
llvm/lib/MC/XCOFFObjectWriter.cpp
89 ↗(On Diff #223085)

After I discuss with Sean, We decide to keep variable PaddingSize here. with additional variable, it can make the code more readable and the logic of padding more easy to understand.

103 ↗(On Diff #223085)

After I discuss with Sean, We decide to keep variable PaddingSize here. with additional variable, it can make the code more readable and the logic of padding more easy to understand.

511 ↗(On Diff #223085)

I got what you talk about, But If we do not calculate the padding size here, We have to calculate the padding size in the XCOFFObjectWriter::writeSections , it will make the logic of the function writeSections complicated.

for example
// Write the program code control sections one at a time.

uint32_t PaddingSize = 0;   //additional variable here.
for (auto it= ProgramCodeCsects.begin(); it!=ProgramCodeCsects.end() ;++it ) {
  if (PaddingSize)
    W.OS.write_zeros(Csect.PaddingSize);
 // And I think I also need some comment to explain following code.
 if(std::next(it) != ProgramCodeCsects.end() )
     PaddingSize = std::next(it)->Address - it->Address - it->size;
  Asm.writeSectionData(W.OS, Csect.MCCsect, Layout);
}
525 ↗(On Diff #223085)

some reason as above.

DiggerLin updated this revision to Diff 224128.Oct 9 2019, 12:50 PM

change padding method as hubert 's suggestion.

DiggerLin updated this revision to Diff 224132.Oct 9 2019, 1:00 PM

add if (PaddingSize) protect.

llvm/lib/MC/XCOFFObjectWriter.cpp
296 ↗(On Diff #224132)

Suggestion: CurrentAddressLocation

299 ↗(On Diff #224132)

I think the code can be made sufficiently self-explanatory that we don't need a comment here.

302 ↗(On Diff #224132)

The above write to PaddingSize is only read by the if and the use inside the if.

if (uint32_t PaddingSize = Csect.Address - CurrentAddressLocation)
308 ↗(On Diff #224132)

Suggestion:
The size of the tail padding in a section is the end virtual address of the current section minus the the end virtual address of the last csect in that section.

310 ↗(On Diff #224132)
if (!ProgramCodeCsects.empty())

however, I suggest checking the section and not the group of csects (they aren't the same thing):

if (Text.Index != -1)
312 ↗(On Diff #224132)

Same comment about the write to PaddingSize.

531 ↗(On Diff #224132)

Use "csect" instead of "Csect" when using the term in an English context where the word would not be capitalized.

Suggestion:
The first csect of a section can be aligned by adjusting the virtual address of its containing section instead of writing zeroes into the object file.

544 ↗(On Diff #224132)

The difference in the calculation for the virtual address of the .bss section and that of the .text section might complicate efforts to common up the handling. Note that a change in how the virtual address of .bss is calculated is within the scope of this patch because it changes the value from being always zero.

518 ↗(On Diff #224128)

There's two spaces after the +.

llvm/test/CodeGen/PowerPC/aix-xcoff-lcomm.ll
56 ↗(On Diff #224132)

It seems this file was changed accidentally by today's updates. The (space) character before the * is correct.

DiggerLin marked 9 inline comments as done.Oct 10 2019, 10:40 AM
DiggerLin added inline comments.
llvm/lib/MC/XCOFFObjectWriter.cpp
296 ↗(On Diff #224132)

changed as suggestion

299 ↗(On Diff #224132)

deleted the comment.

308 ↗(On Diff #224132)

changed comment as suggestion

310 ↗(On Diff #224132)

changed as suggestion.

312 ↗(On Diff #224132)

changed as suggestion.

531 ↗(On Diff #224132)

changed as suggestion

544 ↗(On Diff #224132)

changed , thanks

518 ↗(On Diff #224128)

deleted, thanks

llvm/test/CodeGen/PowerPC/aix-xcoff-lcomm.ll
56 ↗(On Diff #224132)

changed , thanks

Just some minor comments. I think this is almost ready.

llvm/lib/MC/XCOFFObjectWriter.cpp
150 ↗(On Diff #224408)

This should be a static member function or a non-member function.

361 ↗(On Diff #224408)

Maybe check for overflow here.

481 ↗(On Diff #224408)

Please remove the excess parentheses.

llvm/test/CodeGen/PowerPC/aix-xcoff-common.ll
84 ↗(On Diff #224408)

Can this be merged with the previous line?

SYMS:        Symbol {{[{][[:space:]] *}}Index: [[#Index:]]{{[[:space:]] *}}Name: a{{$}}
llvm/test/CodeGen/PowerPC/aix-xcoff-lcomm.ll
36 ↗(On Diff #224408)

Same comment re: merging with the previous line.

56 ↗(On Diff #224408)

Same comment re: merging with the previous line.

DiggerLin marked 6 inline comments as done.Oct 11 2019, 8:13 AM
DiggerLin added inline comments.
llvm/lib/MC/XCOFFObjectWriter.cpp
150 ↗(On Diff #224408)

thanks for your suggestion.

361 ↗(On Diff #224408)

added

481 ↗(On Diff #224408)

deleted

llvm/test/CodeGen/PowerPC/aix-xcoff-common.ll
84 ↗(On Diff #224408)

yes ,your suggestion is more reasonable.

llvm/test/CodeGen/PowerPC/aix-xcoff-lcomm.ll
36 ↗(On Diff #224408)

changed

56 ↗(On Diff #224408)

changed as suggestion.

DiggerLin updated this revision to Diff 224604.Oct 11 2019, 8:23 AM

LGTM with minor changes that can be made on the check-in.

llvm/lib/MC/XCOFFObjectWriter.cpp
360 ↗(On Diff #224604)

This would not be sufficient to avoid overflow if SymbolOffset is less than UINT32_MAX away from UINT64_MAX, use: SymbolOffset <= UINT32_MAX - CSectionRef.Address.

llvm/test/CodeGen/PowerPC/aix-xcoff-common.ll
83 ↗(On Diff #224604)

Please use {{[{] instead of {{{ to avoid ambiguity as to where the regular expression starts and, if the regular expression starts with the first {{, to avoid the undefined results indicated by POSIX regarding { as the first character of an ERE.

llvm/test/CodeGen/PowerPC/aix-xcoff-lcomm.ll
54 ↗(On Diff #224604)

Same comment.

This revision is now accepted and ready to land.Oct 11 2019, 10:15 AM
This revision was automatically updated to reflect the committed changes.
DiggerLin marked 3 inline comments as done.