From 611e3d87d81364b19888afcaa03d328a64bdcdb0 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 10 Feb 2016 01:04:01 +0100 Subject: binutils: Repair nios2 PLT and GP handling Repair corner cases in nios2 PLT and GP handling. See the patches themselves for extensive detailed explanation. The patches don't contain the ChangeLog entries, since the changelog entries often cause trouble when applying the patch. (From OE-Core rev: fdac5c38183aa96faea8d51d16ce5f54ee16f944) Signed-off-by: Marek Vasut Cc: Ross Burton Cc: Richard Purdie Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- ...ress-computations-in-initial-PLT-entries-.patch | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 meta/recipes-devtools/binutils/binutils/0013-Fix-GOT-address-computations-in-initial-PLT-entries-.patch (limited to 'meta/recipes-devtools/binutils/binutils/0013-Fix-GOT-address-computations-in-initial-PLT-entries-.patch') diff --git a/meta/recipes-devtools/binutils/binutils/0013-Fix-GOT-address-computations-in-initial-PLT-entries-.patch b/meta/recipes-devtools/binutils/binutils/0013-Fix-GOT-address-computations-in-initial-PLT-entries-.patch new file mode 100644 index 0000000000..a62b519173 --- /dev/null +++ b/meta/recipes-devtools/binutils/binutils/0013-Fix-GOT-address-computations-in-initial-PLT-entries-.patch @@ -0,0 +1,72 @@ +From 45490ccc18bbb518550209c38b2278b04703c183 Mon Sep 17 00:00:00 2001 +From: Sandra Loosemore +Date: Wed, 9 Dec 2015 16:13:58 -0800 +Subject: [PATCH 1/2] Fix GOT address computations in initial PLT entries for + nios2. + +2015-12-09 Sandra Loosemore + + bfd/ + * elf32-nios2.c (nios2_elf32_finish_dynamic_sections): Correct + %hiadj/%lo computations for _GLOBAL_OFFSET_TABLE_ in initial + PLT entries. Assert alignment requirements. + +Signed-off-by: Marek Vasut +Upstream-Status: Backport +--- + bfd/elf32-nios2.c | 23 ++++++++++++++++------- + 1 file changed, 16 insertions(+), 7 deletions(-) + +diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c +index 6b29d8b..1c54320 100644 +--- a/bfd/elf32-nios2.c ++++ b/bfd/elf32-nios2.c +@@ -5383,12 +5383,17 @@ nios2_elf32_finish_dynamic_sections (bfd *output_bfd, + + sgotplt->output_offset); + if (bfd_link_pic (info)) + { +- bfd_vma corrected = got_address - (splt->output_section->vma +- + splt->output_offset + 4); ++ bfd_vma got_pcrel = got_address - (splt->output_section->vma ++ + splt->output_offset); ++ /* Both GOT and PLT must be aligned to a 16-byte boundary ++ for the two loads to share the %hiadj part. The 4-byte ++ offset for nextpc is accounted for in the %lo offsets ++ on the loads. */ ++ BFD_ASSERT ((got_pcrel & 0xf) == 0); + nios2_elf32_install_data (splt, nios2_so_plt0_entry, 0, 6); +- nios2_elf32_install_imm16 (splt, 4, hiadj (corrected)); +- nios2_elf32_install_imm16 (splt, 12, (corrected & 0xffff) + 4); +- nios2_elf32_install_imm16 (splt, 16, (corrected & 0xffff) + 8); ++ nios2_elf32_install_imm16 (splt, 4, hiadj (got_pcrel)); ++ nios2_elf32_install_imm16 (splt, 12, got_pcrel & 0xffff); ++ nios2_elf32_install_imm16 (splt, 16, (got_pcrel + 4) & 0xffff); + } + else + { +@@ -5404,6 +5409,10 @@ nios2_elf32_finish_dynamic_sections (bfd *output_bfd, + 6 | ((res_size - (res_offset + 4)) << 6), + splt->contents + res_offset); + ++ /* The GOT must be aligned to a 16-byte boundary for the ++ two loads to share the same %hiadj part. */ ++ BFD_ASSERT ((got_address & 0xf) == 0); ++ + nios2_elf32_install_data (splt, nios2_plt0_entry, res_size, 7); + nios2_elf32_install_imm16 (splt, res_size, hiadj (res_start)); + nios2_elf32_install_imm16 (splt, res_size + 4, +@@ -5411,9 +5420,9 @@ nios2_elf32_finish_dynamic_sections (bfd *output_bfd, + nios2_elf32_install_imm16 (splt, res_size + 12, + hiadj (got_address)); + nios2_elf32_install_imm16 (splt, res_size + 16, +- (got_address & 0xffff) + 4); ++ (got_address + 4) & 0xffff); + nios2_elf32_install_imm16 (splt, res_size + 20, +- (got_address & 0xffff) + 8); ++ (got_address + 8) & 0xffff); + } + } + } +-- +2.7.0 + -- cgit v1.2.3-54-g00ecf