]>
Commit | Line | Data |
---|---|---|
6061979e JP |
1 | From e8cf73215187b0c08679d726a5cc7c019fa3ea2e Mon Sep 17 00:00:00 2001 |
2 | From: Jan Beulich <jbeulich@suse.com> | |
3 | Date: Wed, 10 Aug 2022 10:34:22 +0200 | |
4 | Subject: [PATCH] gas/Dwarf: properly skip zero-size functions | |
5 | ||
6 | PR gas/29451 | |
7 | ||
8 | While out_debug_abbrev() properly skips such functions, out_debug_info() | |
9 | mistakenly didn't. It needs to calculate the high_pc expression ahead of | |
10 | time, in order to skip emitting any data for the function if the value | |
11 | is zero. | |
12 | ||
13 | The one case which would still leave a zero-size entry is when | |
14 | symbol_get_obj(symp)->size ends up evaluating to zero. I hope we can | |
15 | expect that to not be the case, otherwise we'd need to have a way to | |
16 | post-process .debug_info contents between resolving expressions and | |
17 | actually writing the data out to the file. Even then it wouldn't be | |
18 | entirely obvious in which way to alter the data. | |
19 | ||
20 | (cherry picked from commit d7abcbcea5ddd40a3bf28758b62f35933c59f996) | |
21 | --- | |
22 | gas/dwarf2dbg.c | 39 ++++++++++++++++++++------------------- | |
23 | 1 file changed, 20 insertions(+), 19 deletions(-) | |
24 | ||
25 | diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c | |
26 | index 868ec79ee2c..f346bd6a412 100644 | |
27 | --- a/gas/dwarf2dbg.c | |
28 | +++ b/gas/dwarf2dbg.c | |
29 | @@ -2882,6 +2882,7 @@ out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT str_seg, | |
30 | { | |
31 | const char *name; | |
32 | size_t len; | |
33 | + expressionS size = { .X_op = O_constant }; | |
34 | ||
35 | /* Skip warning constructs (see above). */ | |
36 | if (symbol_get_bfdsym (symp)->flags & BSF_WARNING) | |
37 | @@ -2895,6 +2896,18 @@ out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT str_seg, | |
38 | if (!S_IS_DEFINED (symp) || !S_IS_FUNCTION (symp)) | |
39 | continue; | |
40 | ||
41 | +#if defined (OBJ_ELF) /* || defined (OBJ_MAYBE_ELF) */ | |
42 | + size.X_add_number = S_GET_SIZE (symp); | |
43 | + if (size.X_add_number == 0 && IS_ELF | |
44 | + && symbol_get_obj (symp)->size != NULL) | |
45 | + { | |
46 | + size.X_op = O_add; | |
47 | + size.X_op_symbol = make_expr_symbol (symbol_get_obj (symp)->size); | |
48 | + } | |
49 | +#endif | |
50 | + if (size.X_op == O_constant && size.X_add_number == 0) | |
51 | + continue; | |
52 | + | |
53 | subseg_set (str_seg, 0); | |
54 | name_sym = symbol_temp_new_now_octets (); | |
55 | name = S_GET_NAME (symp); | |
56 | @@ -2920,29 +2933,17 @@ out_debug_info (segT info_seg, segT abbrev_seg, segT line_seg, segT str_seg, | |
57 | emit_expr (&exp, sizeof_address); | |
58 | ||
59 | /* DW_AT_high_pc */ | |
60 | - exp.X_op = O_constant; | |
61 | -#if defined (OBJ_ELF) /* || defined (OBJ_MAYBE_ELF) */ | |
62 | - exp.X_add_number = S_GET_SIZE (symp); | |
63 | - if (exp.X_add_number == 0 && IS_ELF | |
64 | - && symbol_get_obj (symp)->size != NULL) | |
65 | - { | |
66 | - exp.X_op = O_add; | |
67 | - exp.X_op_symbol = make_expr_symbol (symbol_get_obj (symp)->size); | |
68 | - } | |
69 | -#else | |
70 | - exp.X_add_number = 0; | |
71 | -#endif | |
72 | if (DWARF2_VERSION < 4) | |
73 | { | |
74 | - if (exp.X_op == O_constant) | |
75 | - exp.X_op = O_symbol; | |
76 | - exp.X_add_symbol = symp; | |
77 | - emit_expr (&exp, sizeof_address); | |
78 | + if (size.X_op == O_constant) | |
79 | + size.X_op = O_symbol; | |
80 | + size.X_add_symbol = symp; | |
81 | + emit_expr (&size, sizeof_address); | |
82 | } | |
83 | - else if (exp.X_op == O_constant) | |
84 | - out_uleb128 (exp.X_add_number); | |
85 | + else if (size.X_op == O_constant) | |
86 | + out_uleb128 (size.X_add_number); | |
87 | else | |
88 | - emit_leb128_expr (symbol_get_value_expression (exp.X_op_symbol), 0); | |
89 | + emit_leb128_expr (symbol_get_value_expression (size.X_op_symbol), 0); | |
90 | } | |
91 | ||
92 | /* End of children. */ | |
93 | -- | |
94 | 2.31.1 | |
95 |