9ad6b3be0548ee11257c75d04dcfadb857a4691d
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / binutils / 2.23.2 / 911-xtensa-fix-localized-symbol-refcounting-with-gc-sect.patch
1 From 8ec76b16f62d1bf386fb2c39af5f66c3afddc5cb Mon Sep 17 00:00:00 2001
2 From: Max Filippov <jcmvbkbc@gmail.com>
3 Date: Thu, 14 May 2015 05:22:55 +0300
4 Subject: [PATCH] xtensa: fix localized symbol refcounting with --gc-sections
5
6 elf_xtensa_gc_sweep_hook doesn't correctly unreference symbols that were
7 made local, that results in link failure with the following message:
8
9   BFD (GNU Binutils) 2.24 internal error, aborting at elf32-xtensa.c line
10   3372 in elf_xtensa_finish_dynamic_sections
11
12 elf_xtensa_gc_sweep_hook determines symbol reference type (PLT or GOT) by
13 relocation type. Relocation types are not changed when symbol becomes
14 local, but its PLT references are added to GOT references and
15 plt.refcount is set to 0. Such symbol cannot be unreferences in the
16 elf_xtensa_gc_sweep_hook and its extra references make calculated GOT
17 relocations section size not match number of GOT relocations.
18
19 Fix it by treating PLT reference as GOT reference when plt.refcount is
20 not positive.
21
22 2015-05-14  Max Filippov  <jcmvbkbc@gmail.com>
23 bfd/
24         * elf32-xtensa.c (elf_xtensa_gc_sweep_hook): Treat PLT reference
25         as GOT reference when plt.refcount is not positive.
26
27 Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
28 ---
29 Backported from: e6c9a083ec5ae7a45bd71682b26aae1939849388
30 Changes to ChangeLog are dropped.
31
32  bfd/elf32-xtensa.c | 6 +++++-
33  1 file changed, 5 insertions(+), 1 deletion(-)
34
35 diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
36 index 53af1c6..2523670 100644
37 --- a/bfd/elf32-xtensa.c
38 +++ b/bfd/elf32-xtensa.c
39 @@ -1360,10 +1360,14 @@ elf_xtensa_gc_sweep_hook (bfd *abfd,
40         {
41           if (is_plt)
42             {
43 +             /* If the symbol has been localized its plt.refcount got moved
44 +                to got.refcount.  Handle it as GOT.  */
45               if (h->plt.refcount > 0)
46                 h->plt.refcount--;
47 +             else
48 +               is_got = TRUE;
49             }
50 -         else if (is_got)
51 +         if (is_got)
52             {
53               if (h->got.refcount > 0)
54                 h->got.refcount--;
55 -- 
56 1.8.1.4
57