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

Repository
rL LLVM

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
352

changed as suggestion

392

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
355

Minor nit: Extra space after TODO

478

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?

489

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

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
355

changed

478

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
299

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

392

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
75

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
518

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
299

Added new function to support it.

392

delete extras space.

518

added a comment

llvm/test/CodeGen/PowerPC/aix-xcoff-common.ll
75

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

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.

518

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
87

Remove this field (see comments on later lines).

100

Remove this field (see comments on later lines).

491

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.

505

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
361

@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
361

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
87

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.

100

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.

491

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);
}
505

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
297

Suggestion: CurrentAddressLocation

300

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

303

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

if (uint32_t PaddingSize = Csect.Address - CurrentAddressLocation)
309

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.

311
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)
313

Same comment about the write to PaddingSize.

493

There's two spaces after the +.

505

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.

518

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.

llvm/test/CodeGen/PowerPC/aix-xcoff-lcomm.ll
47

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
297

changed as suggestion

300

deleted the comment.

309

changed comment as suggestion

311

changed as suggestion.

313

changed as suggestion.

493

deleted, thanks

505

changed as suggestion

518

changed , thanks

llvm/test/CodeGen/PowerPC/aix-xcoff-lcomm.ll
47

changed , thanks

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

llvm/lib/MC/XCOFFObjectWriter.cpp
150

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

348

Maybe check for overflow here.

459

Please remove the excess parentheses.

llvm/test/CodeGen/PowerPC/aix-xcoff-common.ll
75

Can this be merged with the previous line?

SYMS:        Symbol {{[{][[:space:]] *}}Index: [[#Index:]]{{[[:space:]] *}}Name: a{{$}}
llvm/test/CodeGen/PowerPC/aix-xcoff-lcomm.ll
35

Same comment re: merging with the previous line.

47

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

thanks for your suggestion.

348

added

459

deleted

llvm/test/CodeGen/PowerPC/aix-xcoff-common.ll
75

yes ,your suggestion is more reasonable.

llvm/test/CodeGen/PowerPC/aix-xcoff-lcomm.ll
35

changed

47

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
347

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
75

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
47

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.