]> code.ossystems Code Review - openembedded-core.git/blob
23ad10ab4a0426610f7b988d373f2f22f48224ab
[openembedded-core.git] /
1 From 3239a4231ff79bf8b67b8faaf414b1667486167c Mon Sep 17 00:00:00 2001
2 From: Andrew Burgess <andrew.burgess@embecosm.com>
3 Date: Mon, 19 Dec 2016 15:27:59 +0000
4 Subject: [PATCH] bfd: Improve lookup of file / line information for errors
5
6 When looking up file and line information (used from the linker to
7 report error messages) if no symbol is passed in, then use the symbol
8 list to look for a matching symbol.
9
10 If a matching symbol is found then use this to look up the file / line
11 information.
12
13 This should improve errors when looking up file / line information for
14 data sections.  Hopefully we should find a matching data symbol, which
15 should, in turn (we hope) match a DW_TAG_variable in the DWARF, this
16 should allow us to give accurate file / line errors for data symbols.
17
18 As the hope is to find a matching DW_TAG_variable in the DWARF then we
19 ignore section symbols, and prefer global symbols to locals.
20
21 CVE: CVE-2017-8392
22 Upstream-Status: Accepted
23
24 Signed-off-by: Fan Xin <fan.xin@jp.fujitsu.com>
25 ---
26  bfd/dwarf2.c                   | 32 ++++++++++++++++++++++++++++++++
27  1 files changed, 32 insertions(+)
28
29
30 diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
31 index 03447a9..9bb8126 100644
32 --- a/bfd/dwarf2.c
33 +++ b/bfd/dwarf2.c
34 @@ -4155,6 +4155,38 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd,
35      {
36        BFD_ASSERT (section != NULL && functionname_ptr != NULL);
37        addr = offset;
38 +
39 +      /* If we have no SYMBOL but the section we're looking at is not a
40 +         code section, then take a look through the list of symbols to see
41 +         if we have a symbol at the address we're looking for.  If we do
42 +         then use this to look up line information.  This will allow us to
43 +         give file and line results for data symbols.  We exclude code
44 +         symbols here, if we look up a function symbol and then look up the
45 +         line information we'll actually return the line number for the
46 +         opening '{' rather than the function definition line.  This is
47 +         because looking up by symbol uses the line table, in which the
48 +         first line for a function is usually the opening '{', while
49 +         looking up the function by section + offset uses the
50 +         DW_AT_decl_line from the function DW_TAG_subprogram for the line,
51 +         which will be the line of the function name.  */
52 +      if ((section->flags & SEC_CODE) == 0)
53 +       {
54 +         asymbol **tmp;
55 +
56 +         for (tmp = symbols; (*tmp) != NULL; ++tmp)
57 +           if ((*tmp)->the_bfd == abfd
58 +               && (*tmp)->section == section
59 +               && (*tmp)->value == offset
60 +               && ((*tmp)->flags & BSF_SECTION_SYM) == 0)
61 +             {
62 +               symbol = *tmp;
63 +               do_line = TRUE;
64 +                /* For local symbols, keep going in the hope we find a
65 +                   global.  */
66 +                if ((symbol->flags & BSF_GLOBAL) != 0)
67 +                  break;
68 +             }
69 +       }
70      }
71  
72    if (section->output_section)
73 -- 
74 1.9.1
75