我应该怎么做才能在 LLVM 的新后端上启用 DWARF?

问题描述 投票:0回答:2

我正在学习 LLVM 并尝试为特定目标架构编写后端。

当我用

clang -g
编译一个hello-world时,
llvm-dwarfdump --verify
的结果如下

llvm-dwarfdump --verify

我用 gdb 跟踪了 llvm-dwarfdump 的过程,看起来

.debug_info
部分没有正确生成。

我看过与 LLVM 和 DWARF 相关的文档。看起来他们主要是关于如何在前端使 DWARF 适应新语言。

我还搜索了 LLVM 和 DWARF 等关键字的组合,但没有找到有同样问题的人。

我grep了

Target/X86
Target/AArch64
下的关键字。看起来也没有与
.debug_info
部分相关的任何代码。

我想知道我是否需要为新的后端编写一些额外的代码来支持 DWARF,如果需要,是否有文档告诉我需要编写哪些代码?如果没有,我应该从哪里开始调试这个问题?


这里是

llvm-objdump -s
的部分结果。我对 ELF 不熟悉。如果需要其他信息,请告诉我。

Contents of section .debug_info:
 0000 00000000 05000102 00000000 01000c00  ................
 0010 01000000 00000000 00020123 00000000  ...........#....
 0020 00000002 2d000000 000302a1 00033900  ....-.........9.
 0030 0000043d 00000005 00050306 01060408  ...=............
 0040 07070123 00000002 90230500 02510000  ...#.....#...Q..
 0050 00050605 0400

作为比较,这里是 X86_64 的结果。

Contents of section .debug_info:
 0000 51000000 05000108 00000000 01000c00  Q...............
 0010 01080000 00000000 00020125 00000008  ...........%....
 0020 00000002 2d000000 000302a1 00033900  ....-.........9.
 0030 0000043d 00000005 00050306 01060408  ...=............
 0040 07070125 00000001 56050002 50000000  ...%....V...P...
 0050 05060504 00

这是我的目标集会:

.Lcu_begin0:
    .long   .Ldebug_info_end0-.Ldebug_info_start0
.Ldebug_info_start0:
    .short  5
    .byte   1
    .byte   2
    .long   .debug_abbrev
    0x01    .byte   0
    .short  12
    .byte   1
    .long   .Lstr_offsets_base0
    .long   .Lline_table_start0
    .byte   2
    0x01    .long   .Lfunc_end0-.Lfunc_begin0
    .long   .Laddr_table_base0
    0x02    .long   45
    .byte   0
    .byte   3
    0x02    .byte   161
    0x00    0x03    .long   57
    0x04    .long   61
    .byte   5
    .byte   0
    0x05    .byte   3
    .byte   6
    .byte   1
    0x06    .byte   4
    .byte   8
    .byte   7
    0x07    0x01    .long   .Lfunc_end0-.Lfunc_begin0
    0x02    .byte   144
    0x23    .byte   5
    .byte   0
    .byte   2
    .long   81

    0x05    .byte   6
    .byte   5
    .byte   4
    .byte   0
.Ldebug_info_end0:
    .section    .debug_str_offsets,"",@progbits
    .long   32
    .short  5
    .short  0

这里是 X86_64:

.Lcu_begin0:
    .long   .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
.Ldebug_info_start0:
    .short  5                               # DWARF version number
    .byte   1                               # DWARF Unit Type
    .byte   8                               # Address Size (in bytes)
    .long   .debug_abbrev                   # Offset Into Abbrev. Section
    .byte   1                               # Abbrev [1] 0xc:0x49 DW_TAG_compile_unit
    .byte   0                               # DW_AT_producer
    .short  12                              # DW_AT_language
    .byte   1                               # DW_AT_name
    .long   .Lstr_offsets_base0             # DW_AT_str_offsets_base
    .long   .Lline_table_start0             # DW_AT_stmt_list
    .byte   2                               # DW_AT_comp_dir
    .byte   1                               # DW_AT_low_pc
    .long   .Lfunc_end0-.Lfunc_begin0       # DW_AT_high_pc
    .long   .Laddr_table_base0              # DW_AT_addr_base
    .byte   2                               # Abbrev [2] 0x23:0xa DW_TAG_variable
    .long   45                              # DW_AT_type
    .byte   0                               # DW_AT_decl_file
    .byte   3                               # DW_AT_decl_line
    .byte   2                               # DW_AT_location
    .byte   161
    .byte   0
    .byte   3                               # Abbrev [3] 0x2d:0xc DW_TAG_array_type
    .long   57                              # DW_AT_type
    .byte   4                               # Abbrev [4] 0x32:0x6 DW_TAG_subrange_type
    .long   61                              # DW_AT_type
    .byte   5                               # DW_AT_count
    .byte   0                               # End Of Children Mark
    .byte   5                               # Abbrev [5] 0x39:0x4 DW_TAG_base_type
    .byte   3                               # DW_AT_name
    .byte   6                               # DW_AT_encoding
    .byte   1                               # DW_AT_byte_size
    .byte   6                               # Abbrev [6] 0x3d:0x4 DW_TAG_base_type
    .byte   4                               # DW_AT_name
    .byte   8                               # DW_AT_byte_size
    .byte   7                               # DW_AT_encoding
    .byte   7                               # Abbrev [7] 0x41:0xf DW_TAG_subprogram
    .byte   1                               # DW_AT_low_pc
    .long   .Lfunc_end0-.Lfunc_begin0       # DW_AT_high_pc
    .byte   1                               # DW_AT_frame_base
    .byte   86
    .byte   5                               # DW_AT_name
    .byte   0                               # DW_AT_decl_file
    .byte   2                               # DW_AT_decl_line
    .long   80                              # DW_AT_type
                                        # DW_AT_external
    .byte   5                               # Abbrev [5] 0x50:0x4 DW_TAG_base_type
    .byte   6                               # DW_AT_name
    .byte   5                               # DW_AT_encoding
    .byte   4                               # DW_AT_byte_size
    .byte   0                               # End Of Children Mark
.Ldebug_info_end0:
    .section    .debug_str_offsets,"",@progbits
    .long   32                              # Length of String Offsets Set
    .short  5
    .short  0

虽然我的目标的汇编代码看起来很奇怪,但看起来 .debug_info 的开始和结束标记被正确发出,单位长度也是如此

.Ldebug_info_end0-.Ldebug_info_start0
。看起来从汇编到二进制的转换可能出了问题。

clang llvm dwarf
2个回答
0
投票

没有更多信息,我无法重现此错误。这对我有用github的代码空间空白模板

hello.c 内容:

#include <stdio.h>

int main(int argc, char *argv[]){
    printf("hi\n");
}

命令:

clang -g -o hello hello.c
@TannerFirl ➜ /workspaces/codespaces-blank $  /usr/bin/llvm-dwarfdump --verify hello
Verifying hello:        file format ELF64-x86-64
Verifying .debug_abbrev...
Verifying .debug_info Unit Header Chain...
Verifying .debug_info references...
Verifying .debug_types Unit Header Chain...
No errors.
@TannerFirl ➜ /workspaces/codespaces-blank $ clang --version
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

0
投票

我已经解决了这个问题,这是一份报告

© www.soinside.com 2019 - 2024. All rights reserved.