This is an archive of the discontinued LLVM Phabricator instance.

[BOLT][DWARF] updateDWARFObjectAddressRanges: nullify low pc
ClosedPublic

Authored by yota9 on Jan 13 2022, 5:51 AM.

Details

Summary

In case the case the DW_AT_ranges tag already exists for the object the
low pc values won't be updated and will be incorrect in
after-bolt binaries.

Due to the large test binary the test is prepared separately in
https://github.com/rafaelauler/bolt-tests/pull/8

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei

Diff Detail

Event Timeline

yota9 requested review of this revision.Jan 13 2022, 5:51 AM
yota9 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 13 2022, 5:51 AM
ayermolo added a comment.EditedJan 13 2022, 6:44 PM

How hard will it be to add a small repro llvm test for this?
Something similar to bolt/test/X86/debug-fission-single.s
Final push. Sorry it's taking so long.

@ayermolo Sorry I'm not quite sure how to manipulate the DWARF in C for example, so it will generate such a combination of tags and attributes. Except of a hexdump and changing them by hands... I would glad to hear the better idea :)

@ayermolo Sorry I'm not quite sure how to manipulate the DWARF in C for example, so it will generate such a combination of tags and attributes. Except of a hexdump and changing them by hands... I would glad to hear the better idea :)

Previously when I created unit tests I either used YAML2OBJ or compiling small "hello world" program and stripping resulting assembly as much as possible by hand.
There is also a question of BOLT hitting that code path. For this year I was thinking of adding "test mode" for debug info where we can kind of skip all other steps and "force" debug update path to do what we want. It's just an idea for now.
At least for this, I don't think it should be an issue.

Also can you add [BOLT][DWARF] tags to the title. Sorry forgot to mention in other diff.

yota9 retitled this revision from updateDWARFObjectAddressRanges: nullify low pc to [BOLT][DWARF] updateDWARFObjectAddressRanges: nullify low pc.Jan 15 2022, 4:26 AM
yota9 updated this revision to Diff 400643.Jan 17 2022, 2:12 PM

Hello @ayermolo! It's to hard to decrease the golang binary size. So I've devided to hexedit the C hello-word dwarf to get the fixed cases of this and previous dward reviws :)

Hello @ayermolo! It's to hard to decrease the golang binary size. So I've devided to hexedit the C hello-word dwarf to get the fixed cases of this and previous dward reviws :)

Thanks for adding the test.
I wonder if it can be reduced further considering we don't actually care if binary is executable, just that bolt processes it and debug info is changed.

yota9 updated this revision to Diff 400922.EditedJan 18 2022, 11:22 AM

@ayermolo Sure, this is the best I can get fast. I wish there will be automated process. It is great that even the beginning file was small enough. I won't be able to reduce golang test by hands in a reasonable time..

ayermolo accepted this revision.Jan 18 2022, 11:26 AM

Thanks for working on this.

This revision is now accepted and ready to land.Jan 18 2022, 11:26 AM
yota9 updated this revision to Diff 400927.Jan 18 2022, 11:31 AM

remove couple more sections

@ayermolo Thank you too! :)
Off topic: Sorry, did you managed to locate the problem with dwarfdump?

@ayermolo Thank you too! :)
Off topic: Sorry, did you managed to locate the problem with dwarfdump?

It's on my todo list for this week to see what bolt is messing up. :)

This revision was landed with ongoing or failed builds.Jan 18 2022, 11:37 AM
This revision was automatically updated to reflect the committed changes.
Amir added a comment.Jan 18 2022, 11:56 AM

@ayermolo Sure, this is the best I can get fast. I wish there will be automated process. It is great that even the beginning file was small enough. I won't be able to reduce golang test by hands in a reasonable time..

Sorry for a late comment, but the following might be helpful:

  • If golang compiler lowers to LLVM IR, it should be possible to dump it and reduce it using llvm-reduce,
  • If not, but the compiler can emit an assembly (with all DWARF sections), it might be possible to reduce it using creduce.
  • Otherwise, we'd need to work on extending BOLT's asm-dump to also dump DWARF sections, and reduce the resulting assembly.

Also, the commit title is out of sync with diff's title. Please double-check the commit before the push, and sync from phabricator as necessary.

@Amir Thank you for your answer! I will check these tools.

Also, the commit title is out of sync with diff's title. Please double-check the commit before the push, and sync from phabricator as necessary.

You are right, it is my bad :( I forgot to "arc patch" before the push, I will try to be more careful next time :)

yota9 added a comment.EditedJan 18 2022, 12:35 PM

Thanks again @Amir

If golang compiler lowers to LLVM IR

No, it is stand-alone compiler. The LLVM has it's own implementation but it is incompatible with the default gc and I didn't even try to support it

If not, but the compiler can emit an assembly (with all DWARF sections), it might be possible to reduce it using creduce.

Do you mean to compile to object files, using creduce find the needed lines and emit it with linker? I'm not sure if it is possible. The golang compile may produce the archive files, although I didn't try it and not sure what kind of output it has. AFAIU it is very problematic since it is not intended to do such things, it is mostly intended to produce the ready executable files (even the SOs are used very very rarely in golang world) and it is very limited compared to the standard C compiler. But I don't exclude that using some hacks and tricks it is possible.

Otherwise, we'd need to work on extending BOLT's asm-dump to also dump DWARF sections, and reduce the resulting assembly.

Probably it is the best solution here, although I hope we won't need it :))

Amir added a comment.Jan 18 2022, 1:03 PM

Thanks again @Amir

If golang compiler lowers to LLVM IR

No, it is stand-alone compiler. The LLVM has it's own implementation but it is incompatible with the default gc and I didn't even try to support it

Got it.

If not, but the compiler can emit an assembly (with all DWARF sections), it might be possible to reduce it using creduce.

Do you mean to compile to object files, using creduce find the needed lines and emit it with linker? I'm not sure if it is possible. The golang compile may produce the archive files, although I didn't try it and not sure what kind of output it has. AFAIU it is very problematic since it is not intended to do such things, it is mostly intended to produce the ready executable files (even the SOs are used very very rarely in golang world) and it is very limited compared to the standard C compiler. But I don't exclude that using some hacks and tricks it is possible.

No, I mean to dump assembly. I did a quick google search and the following options are available:

  • go tool compile -S file.go > file.s
  • gccgo -S test.go

Then inspect the assembly, strip out the irrelevant parts while still preserving the integrity of DWARF data.

yota9 added a comment.Jan 18 2022, 1:06 PM

Oh I see, thanks. But I don't think it will work great. The test I've used is like a few lines of code, most of the code is coming from the golang library, so such a compile method won't help anyway :)