1 From 5eeb7401eed2f26d5fc255de816ca70a2cb9374e Mon Sep 17 00:00:00 2001
2 From: Sandra Loosemore <sandra@codesourcery.com>
3 Date: Sun, 27 Dec 2015 12:30:26 -0800
4 Subject: [PATCH 900/901] Correct nios2 _gp address computation.
6 2015-12-27 Sandra Loosemore <sandra@codesourcery.com>
9 * elf32-nios2.c (nios2_elf_assign_gp): Correct computation of _gp
11 (nios2_elf32_relocate_section): Tidy code for R_NIOS2_GPREL error
15 - backport upstream patch on 2.26
16 - drop bfd/ChangeLog entry]
17 Signed-off-by: Romain Naour <romain.naour@gmail.com>
19 bfd/elf32-nios2.c | 31 +++++++++++++++++++++----------
20 1 file changed, 21 insertions(+), 10 deletions(-)
22 diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c
23 index 6b29d8b..01ebd6e 100644
24 --- a/bfd/elf32-nios2.c
25 +++ b/bfd/elf32-nios2.c
26 @@ -3086,7 +3086,15 @@ lookup:
27 case bfd_link_hash_defined:
28 case bfd_link_hash_defweak:
30 - *pgp = lh->u.def.value;
32 + asection *sym_sec = lh->u.def.section;
33 + bfd_vma sym_value = lh->u.def.value;
35 + if (sym_sec->output_section)
36 + sym_value = (sym_value + sym_sec->output_offset
37 + + sym_sec->output_section->vma);
41 case bfd_link_hash_indirect:
42 case bfd_link_hash_warning:
43 @@ -3719,7 +3727,6 @@ nios2_elf32_relocate_section (bfd *output_bfd,
44 struct elf32_nios2_link_hash_entry *eh;
47 - bfd_vma reloc_address;
48 bfd_reloc_status_type r = bfd_reloc_ok;
49 const char *name = NULL;
51 @@ -3762,12 +3769,6 @@ nios2_elf32_relocate_section (bfd *output_bfd,
52 if (bfd_link_relocatable (info))
55 - if (sec && sec->output_section)
56 - reloc_address = (sec->output_section->vma + sec->output_offset
64 @@ -3816,6 +3817,15 @@ nios2_elf32_relocate_section (bfd *output_bfd,
65 /* Turns an absolute address into a gp-relative address. */
66 if (!nios2_elf_assign_gp (output_bfd, &gp, info))
68 + bfd_vma reloc_address;
70 + if (sec && sec->output_section)
71 + reloc_address = (sec->output_section->vma
72 + + sec->output_offset
77 format = _("global pointer relative relocation at address "
78 "0x%08x when _gp not defined\n");
79 sprintf (msgbuf, format, reloc_address);
80 @@ -3825,7 +3835,7 @@ nios2_elf32_relocate_section (bfd *output_bfd,
83 bfd_vma symbol_address = rel->r_addend + relocation;
84 - relocation = relocation + rel->r_addend - gp;
85 + relocation = symbol_address - gp;
87 if (((signed) relocation < -32768
88 || (signed) relocation > 32767)
89 @@ -3833,6 +3843,8 @@ nios2_elf32_relocate_section (bfd *output_bfd,
90 || h->root.type == bfd_link_hash_defined
91 || h->root.type == bfd_link_hash_defweak))
94 + name = h->root.root.string;
95 format = _("Unable to reach %s (at 0x%08x) from the "
96 "global pointer (at 0x%08x) because the "
97 "offset (%d) is out of the allowed range, "
98 @@ -3848,7 +3860,6 @@ nios2_elf32_relocate_section (bfd *output_bfd,
99 rel->r_offset, relocation,
105 r = nios2_elf32_do_ujmp_relocate (input_bfd, howto,