This is an archive of the discontinued LLVM Phabricator instance.

[BOLT][DWARF] Fix incorrect DW_AT_type offset for unittest
ClosedPublic

Authored by zr33 on Jul 14 2022, 8:56 PM.

Details

Summary

Some unit tests has incorrect DW_AT_type offset since they are manual crafted, fix them to the correct offset.

Diff Detail

Event Timeline

zr33 created this revision.Jul 14 2022, 8:56 PM
Herald added a reviewer: Amir. · View Herald Transcript
Herald added a reviewer: maksfb. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: ayermolo. · View Herald Transcript
zr33 requested review of this revision.Jul 14 2022, 8:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2022, 8:56 PM
zr33 retitled this revision from fix incorrect DW_AT_type offset for unittest to [BOLT][DWARF] Fix incorrect DW_AT_type offset for unittest.Jul 14 2022, 8:59 PM
zr33 edited the summary of this revision. (Show Details)
zr33 edited reviewers, added: ayermolo; removed: maksfb.
ayermolo accepted this revision.Jul 15 2022, 10:19 AM
This revision is now accepted and ready to land.Jul 15 2022, 10:19 AM
Amir added a comment.EditedJul 15 2022, 11:29 AM

Some general questions:
Why are tests incorrect? Were they generated by a buggy clang version? How do we know they are correct now?

Some general questions:
Why are tests incorrect? Were they generated by a buggy clang version? How do we know they are correct now?

It's my fault. From what I remember I manually modified them.

zr33 added a comment.Jul 15 2022, 11:54 AM

Some general questions:
Why are tests incorrect? Were they generated by a buggy clang version? How do we know they are correct now?

Thanks for you questions!

The clang version is clang version 15.0.0.
These tests are manual edit at beginning , when I pass them to my IR constructor, I found some reference offset in them are incorrect so IR construction process failed.
For example, debug information in the pre-bolt binary bolt/test/X86/high_pc_udata.s like following,

.debug_info contents:
0x00000000: Compile Unit: length = 0x00000044, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000048)

0x0000000b: DW_TAG_compile_unit [1] *
              DW_AT_producer [DW_FORM_strp]     ( .debug_str[0x00000009] = "clang")
              DW_AT_language [DW_FORM_data2]    (DW_LANG_C_plus_plus_14)
              DW_AT_stmt_list [DW_FORM_sec_offset]      (0x00000000)
              DW_AT_comp_dir [DW_FORM_strp]     ( .debug_str[0x0000000f] = "test")
              DW_AT_low_pc [DW_FORM_addr]       (0x00000000000012f0)
              DW_AT_high_pc [DW_FORM_udata]     (15)
              DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000000] = "main.cpp")

0x00000027:   DW_TAG_subprogram [2]
                DW_AT_low_pc [DW_FORM_addr]     (0x00000000000012f0)
                DW_AT_high_pc [DW_FORM_data4]   (0x0000000f)
                DW_AT_frame_base [DW_FORM_exprloc]      (DW_OP_reg6 RBP)
                DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000014] = "main")
                DW_AT_decl_file [DW_FORM_data1] ("test/main.cpp")
                DW_AT_decl_line [DW_FORM_data1] (1)
                DW_AT_type [DW_FORM_ref4]       (cu + 0x0043 => {0x00000043})
                DW_AT_external [DW_FORM_flag_present]   (true)

0x00000040:   DW_TAG_base_type [3]
                DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000019] = "int")
                DW_AT_encoding [DW_FORM_data1]  (DW_ATE_signed)
                DW_AT_byte_size [DW_FORM_data1] (0x04)

0x00000047:   NULL

DW_AT_type [DW_FORM_ref4] (cu + 0x0043 => {0x00000043}) at Entry 0x00000027 does not refer to any entry. Ideally, it should point to 0x00000040 which is the entry for int

There are same situations happened for other patched tests.

After I patch it, it looks good as following,

.debug_info contents:
0x00000000: Compile Unit: length = 0x00000044, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000048)

0x0000000b: DW_TAG_compile_unit [1] *
              DW_AT_producer [DW_FORM_strp]     ( .debug_str[0x00000009] = "clang")
              DW_AT_language [DW_FORM_data2]    (DW_LANG_C_plus_plus_14)
              DW_AT_stmt_list [DW_FORM_sec_offset]      (0x00000000)
              DW_AT_comp_dir [DW_FORM_strp]     ( .debug_str[0x0000000f] = "test")
              DW_AT_low_pc [DW_FORM_addr]       (0x00000000000012f0)
              DW_AT_high_pc [DW_FORM_udata]     (15)
              DW_AT_name [DW_FORM_strp] ( .debug_str[0x00000000] = "main.cpp")

0x00000027:   DW_TAG_subprogram [2]
                DW_AT_low_pc [DW_FORM_addr]     (0x00000000000012f0)
                DW_AT_high_pc [DW_FORM_data4]   (0x0000000f)
                DW_AT_frame_base [DW_FORM_exprloc]      (DW_OP_reg6 RBP)
                DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000014] = "main")
                DW_AT_decl_file [DW_FORM_data1] ("test/main.cpp")
                DW_AT_decl_line [DW_FORM_data1] (1)
                DW_AT_type [DW_FORM_ref4]       (cu + 0x0040 => {0x00000040} "int")
                DW_AT_external [DW_FORM_flag_present]   (true)

0x00000040:   DW_TAG_base_type [3]
                DW_AT_name [DW_FORM_strp]       ( .debug_str[0x00000019] = "int")
                DW_AT_encoding [DW_FORM_data1]  (DW_ATE_signed)
                DW_AT_byte_size [DW_FORM_data1] (0x04)

0x00000047:   NULL

The patched tests can pass both current test and my IR constructor (the IR constructor have check for reference destination, if invalid, it will failed), so I consider they are correct now.

Amir added a comment.Jul 15 2022, 12:43 PM

@zr33 @ayermolo thank you for clarifications.
@zr33: would you mind adding a brief explanation to the summary?

zr33 edited the summary of this revision. (Show Details)Jul 15 2022, 2:36 PM
Amir accepted this revision.Jul 15 2022, 2:53 PM

Thanks

This revision was automatically updated to reflect the committed changes.