Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DebugInfo] Support for -gpubnames option in flang #1033

Merged
merged 1 commit into from
Jul 7, 2021

Conversation

SouraVX
Copy link
Collaborator

@SouraVX SouraVX commented Apr 16, 2021

This option is used to generate extra debug information.
i.e
DWARFv4
flang -gdwarf-4 -gpubnames test.c will generate .debug_pubnames and
.debug_pubtypes in the executable.
DWARFv5
flang -gdwarf-5 -gpubnames test.c will generate .debug_names in
the executable.

Prior to this change these sections were getting generated by default.

These sections were extra and may or maynot be used by the debugger. Hence
generation of these sections are bind to this -gpubnames option.
This behavior is analogous to clang, gcc, gfortran.

@michalpasztamobica
Copy link
Collaborator

Hi @SouraVX , I recently realized that our CI might not be exactly following the official building guidelines (or that the guidelines might have an error).
The flang build in the CI is using a native gcc/clang.
According to the official guidelines we should instead be using our own llvm/clang build, downloaded as an artifact from the previous step. Would you check if this makes a difference in your case?
@bryanpkc , @kiranchandramohan , would you be able to comment on this, please? I can provide a fix within minutes...

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 16, 2021

Thanks @michalpasztamobica for clarifying.

According to the official guidelines we should instead be using our own llvm/clang build, downloaded as an artifact from the previous step. Would you check if this makes a difference in your case?

Once driver CI completes the build, then I'll take those artifacts and use them to build/validate flang again locally. I hope this is what you meant ?

@michalpasztamobica
Copy link
Collaborator

Hi Sourabh,
Please see #1034 for what I mean - we might be using the wrong compiler in our CI.
No need to download the artifacts, would you please try to build and test locally but using the native compiler of your machine (whichever you previously used to build llvm and clang)?

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 16, 2021

Hi Sourabh,
Please see #1034 for what I mean - we might be using the wrong compiler in our CI.

Yea, Though not much of CI/yaml person, but I noticed the same :)

No need to download the artifacts, would you please try to build and test locally but using the native compiler of your machine (whichever you previously used to build llvm and clang)?

Thanks for clarifying again :) This is what we used locally for building/validating i.e, First build the Driver/CLANG once that completes used the artifact to build the flang then run make check-flang.

@pawosm-arm
Copy link
Collaborator

According to the official guidelines we should instead be using our own llvm/clang build, downloaded as an artifact from the previous step. Would you check if this makes a difference in your case? @bryanpkc , @kiranchandramohan , would you be able to comment on this, please? I can provide a fix within minutes...

@michalpasztamobica the only role of the guidelines is to provide you with a guidance, not a list of strict requirements. With this guidance some baseline was established. If someone was able to build flang its own way and it works for them, then fine. But when one runs into trouble (e.g. the resulting flang compiler is haunted by ICEs), then conformance to the guidelines is verified first. Also, these guidelines are not set in stone: if you observe that they result in a suboptimal or faulty product, they need to be revisited. They were not revisited for a very long time, apparently no one was in any immediate need for discussing them.

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 18, 2021

Once #1034 is merged, is there a way to re-trigger the CI builds ? That should make these CI bots green(Happy).
Re-triggering should happen in such a way that flang-compiler/classic-flang-llvm-project#32 should build first and rest things follow.

@michalpasztamobica
Copy link
Collaborator

@SouraVX , yes - it should be sufficient for you to rebase your branch on top of master, after #1034 is merged and then force-push the branch to github. This will trigger all the checks to run again with the CI fix in place.

@michalpasztamobica
Copy link
Collaborator

@SouraVX - now the CI is using the right compiler:

Run mkdir -p build && cd build
-- The C compiler identification is Clang 12.0.0
-- The CXX compiler identification is Clang 12.0.0

But the failure is still there... Do you see any difference between how the CI builds and runs tests and how you do it locally?

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 19, 2021

My test case is passing I think(Summary not listed in https://github.com/flang-compiler/flang/pull/1033/checks?check_run_id=2378342786) ?
This failure is different: At least NOT related to this change.

FAIL: Flang :: debug_info/debug_module_import.f90

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 19, 2021

@SouraVX - now the CI is using the right compiler:

Run mkdir -p build && cd build
-- The C compiler identification is Clang 12.0.0
-- The CXX compiler identification is Clang 12.0.0

But the failure is still there... Do you see any difference between how the CI builds and runs tests and how you do it locally?

Yes. but as a more intrusive check, how should one confirm the HEAD of the flang-driver is pointing at ? Which should be flang-compiler/classic-flang-llvm-project#32 - so that driver pass the appropriate bits to flag mapping to flang(flang1 & flang2)

@michalpasztamobica
Copy link
Collaborator

@SouraVX - you have a point, yes. What I can do is tweak my local fork to build your changes flang-compiler/classic-flang-llvm-project#32 and this PR, as I did previously and then I should be able to see that everything is passing. This will take a while, because the classic-flang-llvm-project on Github builds for more thatn 2 hours, but we should have the results available soon. If the failure is there - we can debug the CI configuration.

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 19, 2021

@michalpasztamobica, The process we follow internally, when such dependent changes are to be merged. We merge the parent change first (flang-driver). Once that is done we merge the child one. This may seems sequential but doesn't break things, since CI would automatically pick up the latest flang-driver.
flang-driver changes are less frequent compared to flang - hence above process seems reasonable to me :)

@michalpasztamobica
Copy link
Collaborator

Sure, we this would save me some hassle, indeed :) The failure looks like it could be caused by the missing changes from the dependent PR.

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 19, 2021

lowered strictness of a check in debug_module_import.f90, This should help.
Let's wait for, what CI bots has to say :)

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 19, 2021

Huh 💯 it worked, CI is in good shape. Thanks @michalpasztamobica :)

@michalpasztamobica
Copy link
Collaborator

lowered strictness of a check in debug_module_import.f90, This should help.

Is this a fix of the test or just a temporary workaround until we have the dependent PR available?

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 19, 2021

Is this a fix of the test or just a temporary workaround until we have the dependent PR available?

This PR is extending DICompileUnit metadata and the check for quite strict i.e

distinct !DICompileUnit({{.*}}, imports: ![[DBG_IMPORTS:[0-9]+]])

Notice last closing brace ), this is quite strict IMHO because this will cause this test to fail for every extension that may occur to DICompileUnit metadata.
After this PR:

distinct !DICompileUnit({{.*}}, imports: ![[DBG_IMPORTS:[0-9]+]], nameTableKind: None)

Usually we follow, not so strict style such that no test should be upgraded randomly since they failed due to there strict nature.
Argument supporting this proposition is that, most extensions LLVMM-IR/Metadata are incrementally version specific(i.e some metadata got introduced in LLVM 13). We should not be updating the older testcases just for the sake of it, because this may incur repercussions.
What do you guys think of it ? Please share your thoughts!

@michalpasztamobica
Copy link
Collaborator

michalpasztamobica commented Apr 19, 2021

EDIT: corrected testname.

@SouraVX , how come this PR (namely the new nametable.f90) is passing CI checks without the changes from flang-compiler/classic-flang-llvm-project#32?

I think this situation we are having here reveals another flaw in our CI setup worth discussing on the Wednesday call.
On every PR to classic-flang-llvm-project we run clang and llvm tests but we should perhaps also build and run latest flang master to check if the merge does not break flang builds? Bear in mind that flang's CI pulls the latest successful build from relevant classic-flang-llvm-project.

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 19, 2021

namely the new nametest.f90

You meant nametable.f90 ?

@michalpasztamobica
Copy link
Collaborator

@SouraVX , yes, my mistake sorry. I thought this test will only pass with the dependent changes?

@SouraVX
Copy link
Collaborator Author

SouraVX commented Apr 19, 2021

It seems to me like, there might be some missing/mismatch/delta of pieces between upstream and downstream :(
Here's the log from our downstream flang
LLVM flow:
nameTableKind: None --> Do not generate the section.
NOTHING ---> Generate the section.

$ flang main.f90 -g -S -emit-llvm -o - | egrep "nameTableKind"
!4 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01",
 isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5,
 globals: !6, imports: !5, nameTableKind: None)

$ flang main.f90 -g -o -| llvm-readelf -S - | egrep "debug_"
  [26] .debug_loc        PROGBITS         0000000000000000  000010ce
  [27] .debug_abbrev     PROGBITS         0000000000000000  00001114
  [28] .debug_info       PROGBITS         0000000000000000  000011b5
  [29] .debug_str        PROGBITS         0000000000000000  00001287
  [30] .debug_line       PROGBITS         0000000000000000  00001318
$ flang main.f90 -g -gpubnames -S -emit-llvm -o - | egrep "nameTableKind"

$ flang main.f90 -g -gpubnames -o -| llvm-readelf -S - | egrep "debug_"
  [26] .debug_loc        PROGBITS         0000000000000000  000010ce
  [27] .debug_abbrev     PROGBITS         0000000000000000  00001114
  [28] .debug_info       PROGBITS         0000000000000000  000011b8
  [29] .debug_str        PROGBITS         0000000000000000  0000128a
  [30] .debug_pubnames   PROGBITS         0000000000000000  0000131b
  [31] .debug_pubtypes   PROGBITS         0000000000000000  0000133f
  [32] .debug_line       PROGBITS         0000000000000000  0000136b

Log for flang-fork: Section absent in both cases

$ trunk-flang/classic-flang-llvm-project/bin/flang main.f90 -g -S -emit-llvm -o - | egrep "nameTableKind"
!4 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01",
 isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, globals: !6
, imports: !5, nameTableKind: None)

$ trunk-flang/classic-flang-llvm-project/bin/flang main.f90 -g && readelf -S a.out | egrep "debug_"
  [26] .debug_str        PROGBITS         0000000000000000  000061b1
  [27] .debug_loc        PROGBITS         0000000000000000  0000623c
  [28] .debug_abbrev     PROGBITS         0000000000000000  000062ab
  [29] .debug_info       PROGBITS         0000000000000000  00006333
  [30] .debug_line       PROGBITS         0000000000000000  000063f0

$ trunk-flang/classic-flang-llvm-project/bin/flang main.f90 -g -gpubnames -S -emit-llvm -o - | egrep "nameTableKind"
!4 = distinct !DICompileUnit(language: DW_LANG_Fortran90, file: !3, producer: " F90 Flang - 1.5 2017-05-01",
 isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !5, retainedTypes: !5, 
globals: !6, imports: !5, nameTableKind: None)
$ trunk-flang/classic-flang-llvm-project/bin/flang main.f90 -g -gpubnames && readelf -S a.out | egrep "debug_"

  [26] .debug_str        PROGBITS         0000000000000000  000061b1
  [27] .debug_loc        PROGBITS         0000000000000000  0000623c
  [28] .debug_abbrev     PROGBITS         0000000000000000  000062ab
  [29] .debug_info       PROGBITS         0000000000000000  00006333
  [30] .debug_line       PROGBITS         0000000000000000  000063f0

!RUN: %flang %s -g -gpubnames -S -emit-llvm -o - | FileCheck %s --check-prefix=PUBNAMESECTION

!Ensure that "nameTableKind: None" field is not present in DICompileUnit.
!NAMESECTION-NOT: !DICompileUnit({{.*}}, nameTableKind: None
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks should fail, catching if the nameTableKind: None is present when -gpubnames is specified. To my surprise this is still passing :(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the test to work correctly by not using -DAG checks.

@michalpasztamobica
Copy link
Collaborator

michalpasztamobica commented May 24, 2021

Hi @SouraVX,
In case this PR is still of interest for you...
I wonder if we could rebase flang-compiler/classic-flang-llvm-project#32 on top of flang-compiler/classic-flang-llvm-project@929e198. If it passes the Flang tests - merge it and then merge this PR. If it does not pass the Flang tests:

  1. think of a way to make it pass with some temporary patch to flang in order not to break the CI and merge that flang patch first.
  2. Merge [DebugInfo] Support of -gpubnames in Driver classic-flang-llvm-project#32
  3. Merge this PR (which should be passing by then)

Does this make sense? I believe this suggestion would be in line with what @bryanpkc suggested in one of the Wednesday calls when we were discussing this topic.

@SouraVX
Copy link
Collaborator Author

SouraVX commented May 24, 2021

Thanks for taking out time & revisiting this @michalpasztamobica :). I've pushed changes updated the testcase to be more specific.
Works great at my machine, let's see how CI Reacts.

Detailed log:

`flang` Built using `master` & Driver build using `release_11x` branch.
sourabh@llvm:~/work/dwarf/fortran$ ~/install/release/trunk-flang/bin/flang -gdwarf-5 nametable.f90 -c -o -| ~/install/release/trunk-flang/bin/llvm-readelf -S | egrep "debug_names"
sourabh@llvm:~/work/dwarf/fortran$  // **Section not present as expected, i.e without `-gpubnames` section should not be there.**

sourabh@llvm:~/work/dwarf/fortran$ ~/install/release/trunk-flang/bin/flang -gdwarf-5 -gpubnames nametable.f90 -c -o -| ~/install/release/trunk-flang/bin/llvm-readelf -S | egrep "debug_names"
  [16] .debug_names      PROGBITS        0000000000000000 0003d0 0000dc 00      0   0  4
  [17] .rela.debug_names RELA            0000000000000000 000b58 0000a8 18     25  16  8
// **Section present when `-gpubnames` is specified by the user.

@SouraVX
Copy link
Collaborator Author

SouraVX commented May 24, 2021

@michalpasztamobica Is it possible for you to build the driver using PR: flang-compiler/classic-flang-llvm-project#32 and then build flang & trying this change locally ?

@michalpasztamobica
Copy link
Collaborator

@SouraVX , I can do it or I can try to hack the CI on my fork to do it for us :)

@SouraVX
Copy link
Collaborator Author

SouraVX commented May 24, 2021

Rebased in hopes of CI pick up the parent Driver change first!

@michalpasztamobica
Copy link
Collaborator

I am running your commit on my fork: michalpasztamobica/classic-flang-llvm-project#4.
So far it is looking good.

@SouraVX
Copy link
Collaborator Author

SouraVX commented May 24, 2021

I am running your commit on my fork: michalpasztamobica/classic-flang-llvm-project#4.
So far it is looking good.

Thank you @michalpasztamobica so much for taking out time & collaborating on this one!

@SouraVX
Copy link
Collaborator Author

SouraVX commented May 24, 2021

CI all checks passes here in michalpasztamobica/classic-flang-llvm-project#4 thanks to @michalpasztamobica .
Now people can review the change. I've also provided manual verification of the patch log locally(See above comments), interested people can check the effect of the patch.

@michalpasztamobica
Copy link
Collaborator

I am running your commit on my fork: michalpasztamobica/classic-flang-llvm-project#4.
So far it is looking good.

Thank you @michalpasztamobica so much for taking out time & collaborating on this one!

No problem at all, it took me just a couple minutes to cherry-pick your changes and modify the script to run a different repo and branch. Feel free to use this trick in your branch to test such multi-repo builds :)

Thanks should go to github for letting us use their servers, which in fact did all the actual work 😄

@SouraVX
Copy link
Collaborator Author

SouraVX commented Jun 8, 2021

PING!

@kiranchandramohan
Copy link
Collaborator

@SouraVX what do you need here to proceed? I guess the driver/llvm side changes have to be committed first?

@SouraVX
Copy link
Collaborator Author

SouraVX commented Jun 16, 2021

@SouraVX what do you need here to proceed? I guess the driver/llvm side changes have to be committed first?

Yes, I think driver PR needed for other branches as well. I'll be doing this in a moment.

@SouraVX
Copy link
Collaborator Author

SouraVX commented Jun 16, 2021

Once CI passes in all branches(i.e after merging of the Driver PR's) -- rebasing should be enough to trigger a CI build.

This option is used to generate extra debug information.
i.e
DWARFv4
`flang -gdwarf-4 -gpubnames test.c` will generate `.debug_pubnames` and
`.debug_pubtypes` in the executable.
DWARFv5
`flang -gdwarf-5 -gpubnames test.c` will generate `.debug_names` in
the executable.

Prior to this change these sections were getting generated by default.

These sections were extra and may or maynot be used by the debugger. Hence
generation of these sections are bind to this `-gpubnames` option.
This behavior is analogous to `clang`, `gcc`, gfortran.
@SouraVX
Copy link
Collaborator Author

SouraVX commented Jul 1, 2021

@kiranchandramohan @bryanpkc , All CI bots are green now :) Would you please take a look. Thank You!

Copy link
Collaborator

@bryanpkc bryanpkc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Tests ran fine in our build.

@SouraVX
Copy link
Collaborator Author

SouraVX commented Jul 6, 2021

@kiranchandramohan could you please have a look :)

Copy link
Collaborator

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@shivaramaarao shivaramaarao merged commit 073966d into flang-compiler:master Jul 7, 2021
@michalpasztamobica
Copy link
Collaborator

I am wondering if we should advertise the merge of this PR somehow? It requires an update of the llvm-project build for make check-all to pass. I am afraid people will spend time looking at why some tests are failing, while they should just checkout and build newer llvm-project...

@SouraVX
Copy link
Collaborator Author

SouraVX commented Jul 7, 2021

am wondering if we should advertise the merge of this PR somehow? It requires an update of the llvm-project build for make check-all to pass. I am afraid people will spend time looking at why some tests are failing, while they should just checkout and build newer llvm-project...

Thanks for the noting this, I'll put a note in Slack. Would that be Okay ? Otherwise folks subscribed/starred to this repo should also receiving this communication & from looking at PR they can easily figure out ?

@michalpasztamobica
Copy link
Collaborator

@SouraVX , I was thinking about the mailing list, but I think you are right that Slack channel is a better idea :) If people think otherwise they can ask for an e-mail to the mailing list :)

I think only people subscribed to this particular PR will receive updates from this PR. At least I am not getting notificiation from other PRs, just those that I contribute, comment or subscribe to.

@SouraVX
Copy link
Collaborator Author

SouraVX commented Jul 7, 2021

@michalpasztamobica I think it's a matter of notification/starring the repo settings: I receive notifications for every event happening in this repo :)
Your settings might be the events you're participating/subscribed too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants