Skip to content

Commit 730be96

Browse files
Jinjie-Huanglravenclaw
authored andcommitted
Give a warning when no dwo files are provided (llvm#94336)
In some scenarios based on the split-dwarf build process, the dwo file is not generated as expected(That is to say, no dwo file path is stored in the binary). When the llvm-dwp tool is called to generate the .dwp file, it will exit without any warning. So, the plan is to prompt a warning to tell the user that the dwo file was not actually generated. <img width="699" alt="image" src="https://github.com/llvm/llvm-project/assets/150100070/5e5742f6-daad-450f-87e9-cb25449c3c7a">
1 parent 726c69f commit 730be96

File tree

2 files changed

+149
-1
lines changed

2 files changed

+149
-1
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# RUN: llvm-mc --triple=x86_64-unknown-linux --filetype=obj -dwarf-version=4 %s -o non_split.o
2+
# RUN: llvm-dwp -e non_split.o -o non_split.dwp 2>&1 | FileCheck %s --check-prefix=CHECK-WARNING
3+
4+
# CHECK-WARNING: warning: executable file does not contain any references to dwo files
5+
6+
.ifdef GEN
7+
;--- main.c
8+
int main() {
9+
return 0;
10+
}
11+
;--- gen
12+
clang -g -S -gdwarf-4 main.c -o -
13+
.endif
14+
.text
15+
.file "main.c"
16+
.globl main # -- Begin function main
17+
.p2align 4, 0x90
18+
.type main,@function
19+
main: # @main
20+
.Lfunc_begin0:
21+
.file 1 "/proc/self/cwd" "main.c"
22+
.loc 1 8 0 # main.c:8:0
23+
.cfi_startproc
24+
# %bb.0: # %entry
25+
pushq %rbp
26+
.cfi_def_cfa_offset 16
27+
.cfi_offset %rbp, -16
28+
movq %rsp, %rbp
29+
.cfi_def_cfa_register %rbp
30+
xorl %eax, %eax
31+
movl $0, -4(%rbp)
32+
.Ltmp0:
33+
.loc 1 9 5 prologue_end # main.c:9:5
34+
popq %rbp
35+
.cfi_def_cfa %rsp, 8
36+
retq
37+
.Ltmp1:
38+
.Lfunc_end0:
39+
.size main, .Lfunc_end0-main
40+
.cfi_endproc
41+
# -- End function
42+
.section .debug_abbrev,"",@progbits
43+
.byte 1 # Abbreviation Code
44+
.byte 17 # DW_TAG_compile_unit
45+
.byte 1 # DW_CHILDREN_yes
46+
.byte 37 # DW_AT_producer
47+
.byte 14 # DW_FORM_strp
48+
.byte 19 # DW_AT_language
49+
.byte 5 # DW_FORM_data2
50+
.byte 3 # DW_AT_name
51+
.byte 14 # DW_FORM_strp
52+
.byte 16 # DW_AT_stmt_list
53+
.byte 23 # DW_FORM_sec_offset
54+
.byte 27 # DW_AT_comp_dir
55+
.byte 14 # DW_FORM_strp
56+
.byte 17 # DW_AT_low_pc
57+
.byte 1 # DW_FORM_addr
58+
.byte 18 # DW_AT_high_pc
59+
.byte 6 # DW_FORM_data4
60+
.byte 0 # EOM(1)
61+
.byte 0 # EOM(2)
62+
.byte 2 # Abbreviation Code
63+
.byte 46 # DW_TAG_subprogram
64+
.byte 0 # DW_CHILDREN_no
65+
.byte 17 # DW_AT_low_pc
66+
.byte 1 # DW_FORM_addr
67+
.byte 18 # DW_AT_high_pc
68+
.byte 6 # DW_FORM_data4
69+
.byte 64 # DW_AT_frame_base
70+
.byte 24 # DW_FORM_exprloc
71+
.byte 3 # DW_AT_name
72+
.byte 14 # DW_FORM_strp
73+
.byte 58 # DW_AT_decl_file
74+
.byte 11 # DW_FORM_data1
75+
.byte 59 # DW_AT_decl_line
76+
.byte 11 # DW_FORM_data1
77+
.byte 73 # DW_AT_type
78+
.byte 19 # DW_FORM_ref4
79+
.byte 63 # DW_AT_external
80+
.byte 25 # DW_FORM_flag_present
81+
.byte 0 # EOM(1)
82+
.byte 0 # EOM(2)
83+
.byte 3 # Abbreviation Code
84+
.byte 36 # DW_TAG_base_type
85+
.byte 0 # DW_CHILDREN_no
86+
.byte 3 # DW_AT_name
87+
.byte 14 # DW_FORM_strp
88+
.byte 62 # DW_AT_encoding
89+
.byte 11 # DW_FORM_data1
90+
.byte 11 # DW_AT_byte_size
91+
.byte 11 # DW_FORM_data1
92+
.byte 0 # EOM(1)
93+
.byte 0 # EOM(2)
94+
.byte 0 # EOM(3)
95+
.section .debug_info,"",@progbits
96+
.Lcu_begin0:
97+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
98+
.Ldebug_info_start0:
99+
.short 4 # DWARF version number
100+
.long .debug_abbrev # Offset Into Abbrev. Section
101+
.byte 8 # Address Size (in bytes)
102+
.byte 1 # Abbrev [1] 0xb:0x40 DW_TAG_compile_unit
103+
.long .Linfo_string0 # DW_AT_producer
104+
.short 12 # DW_AT_language
105+
.long .Linfo_string1 # DW_AT_name
106+
.long .Lline_table_start0 # DW_AT_stmt_list
107+
.long .Linfo_string2 # DW_AT_comp_dir
108+
.quad .Lfunc_begin0 # DW_AT_low_pc
109+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
110+
.byte 2 # Abbrev [2] 0x2a:0x19 DW_TAG_subprogram
111+
.quad .Lfunc_begin0 # DW_AT_low_pc
112+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
113+
.byte 1 # DW_AT_frame_base
114+
.byte 86
115+
.long .Linfo_string3 # DW_AT_name
116+
.byte 1 # DW_AT_decl_file
117+
.byte 8 # DW_AT_decl_line
118+
.long 67 # DW_AT_type
119+
# DW_AT_external
120+
.byte 3 # Abbrev [3] 0x43:0x7 DW_TAG_base_type
121+
.long .Linfo_string4 # DW_AT_name
122+
.byte 5 # DW_AT_encoding
123+
.byte 4 # DW_AT_byte_size
124+
.byte 0 # End Of Children Mark
125+
.Ldebug_info_end0:
126+
.section .debug_str,"MS",@progbits,1
127+
.Linfo_string0:
128+
.byte 0 # string offset=0
129+
.Linfo_string1:
130+
.asciz "main.c" # string offset=1
131+
.Linfo_string2:
132+
.asciz "/proc/self/cwd" # string offset=8
133+
.Linfo_string3:
134+
.asciz "main" # string offset=23
135+
.Linfo_string4:
136+
.asciz "int" # string offset=28
137+
.section .GCC.command.line,"MS",@progbits,1
138+
.zero 1
139+
.ascii "/usr/local/bin/clang-11 -Qn -g -S -gdwarf-4 main.c -o -"
140+
.zero 1
141+
.section .debug_str,"MS",@progbits,1
142+
.section ".note.GNU-stack","",@progbits
143+
.addrsig
144+
.section .debug_line,"",@progbits
145+
.Lline_table_start0:

llvm/tools/llvm-dwp/llvm-dwp.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@ int llvm_dwp_main(int argc, char **argv, const llvm::ToolContext &) {
188188
std::make_move_iterator(DWOs->end()));
189189
}
190190

191-
if (DWOFilenames.empty())
191+
if (DWOFilenames.empty()) {
192+
WithColor::defaultWarningHandler(make_error<DWPError>(
193+
"executable file does not contain any references to dwo files"));
192194
return 0;
195+
}
193196

194197
std::string ErrorStr;
195198
StringRef Context = "dwarf streamer init";

0 commit comments

Comments
 (0)