tizen 2.3 release
[external/binutils.git] / packaging / pr_13990_14189.patch
1 diff --git a/bfd/ChangeLog b/bfd/ChangeLog
2 index 1f6c1a0..0c81318 100644
3 --- a/bfd/ChangeLog
4 +++ b/bfd/ChangeLog
5 @@ -1,3 +1,15 @@
6 +2012-06-29  Nick Clifton  <nickc@redhat.com>
7 +
8 +       PR ld/14189
9 +       * elf32-arm.c (elf32_arm_check_relocs): Do not increment refcount
10 +       for locally bound symbols.
11 +
12 +2012-04-24  Hans-Peter Nilsson  <hp@axis.com>
13 +
14 +       PR ld/13990
15 +       * elf32-arm.c (elf32_arm_gc_sweep_hook): Handle a forced-local
16 +       symbol, where PLT refcount is set to -1.
17 +
18  2011-12-10  David Daney  <david.daney@cavium.com>
19  
20         Backport from mainline:
21 diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
22 index 1f6c1a0..8daebe5 100644
23 --- a/bfd/elf32-arm.c
24 +++ b/bfd/elf32-arm.c
25 @@ -12046,9 +12046,19 @@ elf32_arm_gc_sweep_hook (bfd *                     abfd,
26        if (may_need_local_target_p
27           && elf32_arm_get_plt_info (abfd, eh, r_symndx, &root_plt, &arm_plt))
28         {
29 -         BFD_ASSERT (root_plt->refcount > 0);
30 -         root_plt->refcount -= 1;
31 -
32 +         /* If PLT refcount book-keeping is wrong and too low, we'll
33 +            see a zero value (going to -1) for the root PLT reference
34 +            count.  */
35 +         if (root_plt->refcount >= 0)
36 +           {
37 +             BFD_ASSERT (root_plt->refcount != 0);
38 +             root_plt->refcount -= 1;
39 +           }
40 +         else
41 +           /* A value of -1 means the symbol has become local, forced
42 +              or seeing a hidden definition.  Any other negative value
43 +              is an error.  */
44 +           BFD_ASSERT (root_plt->refcount == -1);
45           if (!call_reloc_p)
46             arm_plt->noncall_refcount--;
47  
48 @@ -12408,7 +12418,8 @@ elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
49  
50           /* If the symbol is a function that doesn't bind locally,
51              this relocation will need a PLT entry.  */
52 -         root_plt->refcount += 1;
53 +          if (root_plt->refcount != -1)
54 +           root_plt->refcount += 1;
55  
56           if (!call_reloc_p)
57             arm_plt->noncall_refcount++;
58 diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp
59 index c7a0b2c..8631466 100644
60 --- a/ld/testsuite/ld-arm/arm-elf.exp
61 +++ b/ld/testsuite/ld-arm/arm-elf.exp
62 @@ -733,3 +733,4 @@ run_dump_test "attr-merge-vfp-6r"
63  run_dump_test "attr-merge-incompatible"
64  run_dump_test "unresolved-1"
65  run_dump_test "unresolved-1-dyn"
66 +run_dump_test "gc-hidden-1"
67 diff --git a/ld/testsuite/ld-arm/gc-hidden-1.d b/ld/testsuite/ld-arm/gc-hidden-1.d
68 new file mode 100644
69 index 0000000..80c7e9e
70 --- /dev/null
71 +++ b/ld/testsuite/ld-arm/gc-hidden-1.d
72 @@ -0,0 +1,25 @@
73 +#target: arm*-*-*eabi
74 +#source: main.s
75 +#source: gcdfn.s
76 +#source: hidfn.s
77 +#ld: --gc-sections --shared --version-script hideall.ld
78 +#objdump: -dRT
79 +
80 +# See PR ld/13990: a forced-local PLT reference to a
81 +# forced-local symbol is GC'ed, trigging a BFD_ASSERT.
82 +
83 +.*:     file format elf32-.*
84 +
85 +DYNAMIC SYMBOL TABLE:
86 +0+124 l    d  .text    0+              .text
87 +0+ g    DO \*ABS\*     0+  NS          NS
88 +
89 +Disassembly of section .text:
90 +
91 +0+124 <_start>:
92 + 124:  e52de004        push    {lr}            ; \(str lr, \[sp, #-4\]!\)
93 + 128:  eb000000        bl      130 <hidfn>
94 + 12c:  e8bd8000        pop     {pc}
95 +
96 +0+130 <hidfn>:
97 + 130:  e8bd8000        pop     {pc}
98 diff --git a/ld/testsuite/ld-arm/gcdfn.s b/ld/testsuite/ld-arm/gcdfn.s
99 new file mode 100644
100 index 0000000..f2afae7
101 --- /dev/null
102 +++ b/ld/testsuite/ld-arm/gcdfn.s
103 @@ -0,0 +1,8 @@
104 +       .text
105 +       .globl gcdfn
106 +       .type gcdfn, %function
107 +gcdfn:
108 +       str     lr, [sp, #-4]!
109 +       bl      hidfn(PLT)
110 +       ldmfd   sp!, {pc}
111 +       .size gcdfn, . - gcdfn
112 diff --git a/ld/testsuite/ld-arm/hideall.ld b/ld/testsuite/ld-arm/hideall.ld
113 new file mode 100644
114 index 0000000..077d6b5
115 --- /dev/null
116 +++ b/ld/testsuite/ld-arm/hideall.ld
117 @@ -0,0 +1 @@
118 +NS { local: *; };
119 diff --git a/ld/testsuite/ld-arm/hidfn.s b/ld/testsuite/ld-arm/hidfn.s
120 new file mode 100644
121 index 0000000..a66b558
122 --- /dev/null
123 +++ b/ld/testsuite/ld-arm/hidfn.s
124 @@ -0,0 +1,7 @@
125 +       .text
126 +       .globl hidfn
127 +       .hidden hidfn
128 +       .type hidfn, %function
129 +hidfn:
130 +       ldmfd   sp!, {pc}
131 +       .size hidfn, . - hidfn
132 diff --git a/ld/testsuite/ld-arm/main.s b/ld/testsuite/ld-arm/main.s
133 new file mode 100644
134 index 0000000..046d19d
135 --- /dev/null
136 +++ b/ld/testsuite/ld-arm/main.s
137 @@ -0,0 +1,8 @@
138 +       .text
139 +       .globl _start
140 +       .type _start, %function
141 +_start:
142 +       str     lr, [sp, #-4]!
143 +       bl      hidfn(PLT)
144 +       ldmfd   sp!, {pc}
145 +       .size _start, . - _start