2
0

008-gas-Dwarf-properly-skip-zero-size-functions.patch 3.1 KB

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