[PATCH] D95518: [Debug-Info][XCOFF] support dwarf for XCOFF for assembly output

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 4 19:04:01 PST 2021


shchenz added inline comments.


================
Comment at: llvm/lib/MC/MCAsmStreamer.cpp:2323
+
+  // FIXME: use section end symbol as end of the Section. We need to consider
+  // the explicit sections and -ffunction-sections when we try to generate or
----------------
jasonliu wrote:
> shchenz wrote:
> > jasonliu wrote:
> > > shchenz wrote:
> > > > jasonliu wrote:
> > > > > I hope this FIXME is not going to stay here for long (and we will quickly have a patch to address this). As this is really a workaround here and it creates different behavior between object file generation and assembly generation which is undesirable.
> > > > I left this as a FIXME because I can not find an easy way to fix this. Why we need this function is because of the difference of the `changeSection` function of `MCAsmStreamer` and `MCObjectStreamer`. `MCObjectStreamer` will change the insert point to the section end, while `MCAsmStreamer` will add a new section start in the assembly output. The `MCAsmStreamer` current behavior is not what we need for debug lines, we can not add another `.text` section when we generate assembly for `.dwline`. 
> > > > So if we want to have the same behavior for `MCAsmStreamer` and `MCObjectStreamer`, we must make sure that we know a function is a section end. So we can add a section end symbol in the function `emitFunctionBodyEnd`. But this seems hard due to explicit sections. When we handle a function in `AsmPrinter` pass, it is hard to know there are other functions(which will be handled later) that also belong to the same section unless a CU level analysis is performed to fetch this info.
> > > I guess one way to do this for assembly would be:
> > > 1. collect all the seen text csects somehow into an array.
> > > 2. After all the text csects are emitted (doFinalization or emitEndOfAsmFile?), traverse (and switch to) each text csect in the array and emit the section end label for it. 
> > > I think in this way, you could make sure that the section end labels are indeed emitted to the section end.
> > hmm, doing this in `doFinalization` for the explicit sections will be too late, just like the case we do this in dwarf line emission. We can not switch back to the previous section at the end of all text sections.
> > 
> > Collecting this info in `doInitialization` is a possible way. Before we run `AsmPrinter::runOnMachineFunction()` for any function, we go through all functions in the module and try to find out which function is the last one of a specific section.
> > 
> > But I am not sure that the function order (when we iterate them in the module ) is the same as the order they exist in the source file. We need more investigation here if we want to fix this later.
> I'm not sure if I understand what you meant by we could not switch back to the previous section at the end of all text sections. 
> Assuming you have csects like this:
> ```
> .csect main[PR]
> xxx
> .csect text[PR]
> xxx
> .csect main[PR]
> xxx
> .csect text[PR]
> xxx
> ```
> Then at finalization, we know no more text csect will be emitted. Then we could start emitting the end label for each of the csect above:
> ```
> .csect main[PR]
> .L..sec_end0
> .csect text[PR]
> .L..sec_end1
> ```
> Then you could refer back to these labels in the dwarf sections. Those labels should give you the address of the end of that particular csect.
> Wouldn't this work?
Please keep in mind that there is no way to change the insert point for the assembly output. See `MCAsmStreamer::changeSection()` -> `MCSectionXCOFF::PrintSwitchToSection(`.

If we are in the position of the text end, for your example:
```
.csect main[PR]
xxx
.csect text[PR]
xxx
```

Assume `.text` is the end of all text sections, now we want to emit end symbol for section main.
Then we call `switchSection(main)`, what we have now is generating another csect directive for main and then add the end label, so it becomes:
```
.csect main[PR]
xxx
.csect text[PR]
xxx
.csect main[PR]
L..sec_end    #for main
```

I think this is not what we expect, right? We expect:
```
.csect main[PR]
xxx
L..sec_end    #for main
.csect text[PR]
xxx
```

So we must do the section end lable adding when we just reach a section end.

FYI, `MCObjectStreamer` has the ability to change the insert point. See `MCObjectStreamer::changeSectionImpl(`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95518/new/

https://reviews.llvm.org/D95518



More information about the llvm-commits mailing list