package/binutils: fix XTENSA_NDIFF handling for PR ld/25861
PATCH 1/1 package/binutils: fix XTENSA_NDIFF handling for PR ld/25861
Fix for xtensa PR ld/25861 introduced a regression in handling negative symbol differences resulting in linker performing incorrect relaxation or failing to link. Fix XTENSA_NDIFF relocation handling.
Backported from:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=d548f47df4d2e3d117d504a4c9977982c78a0556
--- ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ 3 files changed, 384 insertions(+) create mode 100644 package/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch create mode 100644 package/binutils/2.32/0009-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch create mode 100644 package/binutils/2.33.1/0006-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch
package/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128 -0
@@ -0,0 +1,128 @@ +From 735321812435ae278d3766a3371f55937dc776d6 Mon Sep 17 00:00:00 2001 +From: Max Filippov <[email protected]> +Date: Sat, 25 Apr 2020 00:40:25 -0700 +Subject: [PATCH] xtensa: fix XTENSA_NDIFF handling for PR ld/25861 + +Fields marked with XTENSA_NDIFF relocations are not negated, they only +have sign bits removed. Don't negate their values when relaxation is +performed. Don't add sign bits when the value is zero. Report overflow +when the result has negative sign but all significant bits are zero. + +2020-04-29 Max Filippov <[email protected]> +bfd/ + * elf32-xtensa.c (relax_section): Don't negate diff_value for + XTENSA_NDIFF relocations. Don't add sign bits whe diff_value + equals 0. Report overflow when the result has negative sign but + all significant bits are zero. + +Signed-off-by: Max Filippov <[email protected]> +--- +Backported from: d548f47df4d2e3d117d504a4c9977982c78a0556 + + bfd/elf32-xtensa.c | 26 +++++++++++++++----------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index fded42d52a9a..4327b027911f 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -9670,37 +9670,44 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: ++ diff_mask = 0x7f; + diff_value = + bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: ++ diff_mask = 0x7fff; + diff_value = + bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: ++ diff_mask = 0x7fffffff; + diff_value = + bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: ++ diff_mask = 0xff; + diff_value = + bfd_get_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: ++ diff_mask = 0xffff; + diff_value = + bfd_get_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: ++ diff_mask = 0xffffffff; + diff_value = + bfd_get_32 (abfd, &contents[old_source_offset]); + break; + } + + if (r_type >= R_XTENSA_NDIFF8 +- && r_type <= R_XTENSA_NDIFF32) +- diff_value = -diff_value; ++ && r_type <= R_XTENSA_NDIFF32 ++ && diff_value) ++ diff_value |= ~diff_mask; + + new_end_offset = offset_with_removed_text_map + (&target_relax_info->action_list, +@@ -9710,43 +9717,40 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0x7f; + bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0x7fff; + bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0x7fffffff; + bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: +- diff_mask = 0xff; + bfd_put_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: +- diff_mask = 0xffff; + bfd_put_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: +- diff_mask = 0xffffffff; + bfd_put_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. Sign bits must be all zeroes or all ones */ +- if ((diff_value & ~diff_mask) != 0 && +- (diff_value & ~diff_mask) != (-1 & ~diff_mask)) ++ /* Check for overflow. Sign bits must be all zeroes or ++ all ones. When sign bits are all ones diff_value ++ may not be zero. */ ++ if (((diff_value & ~diff_mask) != 0 ++ && (diff_value & ~diff_mask) != ~diff_mask) ++ || (diff_value && (bfd_vma) diff_value == ~diff_mask)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +-- +2.20.1 +
package/binutils/2.32/0009-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128 -0
128 lines not on this page · raw message
package/binutils/2.33.1/0006-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128 -0
128 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 1/1 package/binutils: fix XTENSA_NDIFF handling for PR ld/25861
Hi Max,
Le 30/04/2020 ? 07:08, Max Filippov a ?crit?:
Quoted 9 lines
Fix for xtensa PR ld/25861 introduced a regression in handling negative symbol differences resulting in linker performing incorrect relaxation or failing to link. Fix
XTENSA_NDIFFrelocation handling.Backported from:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=d548f47df4d2e3d117d504a4c9977982c78a0556Fixes f0291ef4aba0 ("package/binutils: fix xtensa PR ld/25861")Signed-off-by Max Filippov <[email protected]>
Best regards,
Romain
Quoted 412 lines
--- ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ 3 files changed, 384 insertions(+) create mode 100644 package/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch create mode 100644 package/binutils/2.32/0009-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch create mode 100644 package/binutils/2.33.1/0006-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patchpackage/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128
-0@@ -0,0 +1,128 @@ +From 735321812435ae278d3766a3371f55937dc776d6 Mon Sep 17 00:00:00 2001 +From: Max Filippov <[email protected]> +Date: Sat, 25 Apr 2020 00:40:25 -0700 +Subject: [PATCH] xtensa: fix XTENSA_NDIFF handling for PR ld/25861 + +Fields marked with XTENSA_NDIFF relocations are not negated, they only +have sign bits removed. Don't negate their values when relaxation is +performed. Don't add sign bits when the value is zero. Report overflow +when the result has negative sign but all significant bits are zero. + +2020-04-29 Max Filippov <[email protected]> +bfd/ + * elf32-xtensa.c (relax_section): Don't negate diff_value for + XTENSA_NDIFF relocations. Don't add sign bits whe diff_value + equals 0. Report overflow when the result has negative sign but + all significant bits are zero. + +Signed-off-by: Max Filippov <[email protected]> +--- +Backported from: d548f47df4d2e3d117d504a4c9977982c78a0556 + + bfd/elf32-xtensa.c | 26 +++++++++++++++----------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index fded42d52a9a..4327b027911f 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -9670,37 +9670,44 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: ++ diff_mask = 0x7f; + diff_value = + bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: ++ diff_mask = 0x7fff; + diff_value = + bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: ++ diff_mask = 0x7fffffff; + diff_value = + bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: ++ diff_mask = 0xff; + diff_value = + bfd_get_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: ++ diff_mask = 0xffff; + diff_value = + bfd_get_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: ++ diff_mask = 0xffffffff; + diff_value = + bfd_get_32 (abfd, &contents[old_source_offset]); + break; + } + + if (r_type >= R_XTENSA_NDIFF8 +- && r_type <= R_XTENSA_NDIFF32) +- diff_value = -diff_value; ++ && r_type <= R_XTENSA_NDIFF32 ++ && diff_value) ++ diff_value |= ~diff_mask; + + new_end_offset = offset_with_removed_text_map + (&target_relax_info->action_list, +@@ -9710,43 +9717,40 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0x7f; + bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0x7fff; + bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0x7fffffff; + bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: +- diff_mask = 0xff; + bfd_put_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: +- diff_mask = 0xffff; + bfd_put_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: +- diff_mask = 0xffffffff; + bfd_put_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. Sign bits must be all zeroes or all ones */ +- if ((diff_value & ~diff_mask) != 0 && +- (diff_value & ~diff_mask) != (-1 & ~diff_mask)) ++ /* Check for overflow. Sign bits must be all zeroes or ++ all ones. When sign bits are all ones diff_value ++ may not be zero. */ ++ if (((diff_value & ~diff_mask) != 0 ++ && (diff_value & ~diff_mask) != ~diff_mask) ++ || (diff_value && (bfd_vma) diff_value == ~diff_mask)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +-- +2.20.1 +package/binutils/2.32/0009-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128
-0@@ -0,0 +1,128 @@ +From 735321812435ae278d3766a3371f55937dc776d6 Mon Sep 17 00:00:00 2001 +From: Max Filippov <[email protected]> +Date: Sat, 25 Apr 2020 00:40:25 -0700 +Subject: [PATCH] xtensa: fix XTENSA_NDIFF handling for PR ld/25861 + +Fields marked with XTENSA_NDIFF relocations are not negated, they only +have sign bits removed. Don't negate their values when relaxation is +performed. Don't add sign bits when the value is zero. Report overflow +when the result has negative sign but all significant bits are zero. + +2020-04-29 Max Filippov <[email protected]> +bfd/ + * elf32-xtensa.c (relax_section): Don't negate diff_value for + XTENSA_NDIFF relocations. Don't add sign bits whe diff_value + equals 0. Report overflow when the result has negative sign but + all significant bits are zero. + +Signed-off-by: Max Filippov <[email protected]> +--- +Backported from: d548f47df4d2e3d117d504a4c9977982c78a0556 + + bfd/elf32-xtensa.c | 26 +++++++++++++++----------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index fded42d52a9a..4327b027911f 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -9670,37 +9670,44 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: ++ diff_mask = 0x7f; + diff_value = + bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: ++ diff_mask = 0x7fff; + diff_value = + bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: ++ diff_mask = 0x7fffffff; + diff_value = + bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: ++ diff_mask = 0xff; + diff_value = + bfd_get_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: ++ diff_mask = 0xffff; + diff_value = + bfd_get_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: ++ diff_mask = 0xffffffff; + diff_value = + bfd_get_32 (abfd, &contents[old_source_offset]); + break; + } + + if (r_type >= R_XTENSA_NDIFF8 +- && r_type <= R_XTENSA_NDIFF32) +- diff_value = -diff_value; ++ && r_type <= R_XTENSA_NDIFF32 ++ && diff_value) ++ diff_value |= ~diff_mask; + + new_end_offset = offset_with_removed_text_map + (&target_relax_info->action_list, +@@ -9710,43 +9717,40 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0x7f; + bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0x7fff; + bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0x7fffffff; + bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: +- diff_mask = 0xff; + bfd_put_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: +- diff_mask = 0xffff; + bfd_put_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: +- diff_mask = 0xffffffff; + bfd_put_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. Sign bits must be all zeroes or all ones */ +- if ((diff_value & ~diff_mask) != 0 && +- (diff_value & ~diff_mask) != (-1 & ~diff_mask)) ++ /* Check for overflow. Sign bits must be all zeroes or ++ all ones. When sign bits are all ones diff_value ++ may not be zero. */ ++ if (((diff_value & ~diff_mask) != 0 ++ && (diff_value & ~diff_mask) != ~diff_mask) ++ || (diff_value && (bfd_vma) diff_value == ~diff_mask)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +-- +2.20.1 +package/binutils/2.33.1/0006-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128
-0@@ -0,0 +1,128 @@ +From 735321812435ae278d3766a3371f55937dc776d6 Mon Sep 17 00:00:00 2001 +From: Max Filippov <[email protected]> +Date: Sat, 25 Apr 2020 00:40:25 -0700 +Subject: [PATCH] xtensa: fix XTENSA_NDIFF handling for PR ld/25861 + +Fields marked with XTENSA_NDIFF relocations are not negated, they only +have sign bits removed. Don't negate their values when relaxation is +performed. Don't add sign bits when the value is zero. Report overflow +when the result has negative sign but all significant bits are zero. + +2020-04-29 Max Filippov <[email protected]> +bfd/ + * elf32-xtensa.c (relax_section): Don't negate diff_value for + XTENSA_NDIFF relocations. Don't add sign bits whe diff_value + equals 0. Report overflow when the result has negative sign but + all significant bits are zero. + +Signed-off-by: Max Filippov <[email protected]> +--- +Backported from: d548f47df4d2e3d117d504a4c9977982c78a0556 + + bfd/elf32-xtensa.c | 26 +++++++++++++++----------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index fded42d52a9a..4327b027911f 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -9670,37 +9670,44 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: ++ diff_mask = 0x7f; + diff_value = + bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: ++ diff_mask = 0x7fff; + diff_value = + bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: ++ diff_mask = 0x7fffffff; + diff_value = + bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: ++ diff_mask = 0xff; + diff_value = + bfd_get_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: ++ diff_mask = 0xffff; + diff_value = + bfd_get_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: ++ diff_mask = 0xffffffff; + diff_value = + bfd_get_32 (abfd, &contents[old_source_offset]); + break; + } + + if (r_type >= R_XTENSA_NDIFF8 +- && r_type <= R_XTENSA_NDIFF32) +- diff_value = -diff_value; ++ && r_type <= R_XTENSA_NDIFF32 ++ && diff_value) ++ diff_value |= ~diff_mask; + + new_end_offset = offset_with_removed_text_map + (&target_relax_info->action_list, +@@ -9710,43 +9717,40 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0x7f; + bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0x7fff; + bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0x7fffffff; + bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: +- diff_mask = 0xff; + bfd_put_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: +- diff_mask = 0xffff; + bfd_put_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: +- diff_mask = 0xffffffff; + bfd_put_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. Sign bits must be all zeroes or all ones */ +- if ((diff_value & ~diff_mask) != 0 && +- (diff_value & ~diff_mask) != (-1 & ~diff_mask)) ++ /* Check for overflow. Sign bits must be all zeroes or ++ all ones. When sign bits are all ones diff_value ++ may not be zero. */ ++ if (((diff_value & ~diff_mask) != 0 ++ && (diff_value & ~diff_mask) != ~diff_mask) ++ || (diff_value && (bfd_vma) diff_value == ~diff_mask)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +-- +2.20.1 +
PATCH 1/1 package/binutils: fix XTENSA_NDIFF handling for PR ld/25861
Hi Max,
Le 01/05/2020 ? 21:25, Romain Naour a ?crit?:
Quoted 12 lines
Hi Max,
Le 30/04/2020 ? 07:08, Max Filippov a ?crit?:
Quoted 9 lines
Fix for xtensa PR ld/25861 introduced a regression in handling negative symbol differences resulting in linker performing incorrect relaxation or failing to link. Fix
XTENSA_NDIFFrelocation handling.Backported from:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=d548f47df4d2e3d117d504a4c9977982c78a0556Fixes f0291ef4aba0 ("package/binutils: fix xtensa PR ld/25861")Signed-off-by Max Filippov <[email protected]>
It seems elf2flt used by qemu_xtensa_lx60_nommu_defconfig doesn't support R_XTENSA_PDIFF32:
elf2flt: 267 bad relocs
https://gitlab.com/kubu93/buildroot/-/jobs/543293510
(Note gcc 9.3.0 is used here in gitlab and reproduced locally with gcc 8.4.0).
Best regards,
Romain
Quoted 420 lines
Tested-by Romain Naour <[email protected]>Best regards,
RomainQuoted 412 lines
--- ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ 3 files changed, 384 insertions(+) create mode 100644 package/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch create mode 100644 package/binutils/2.32/0009-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch create mode 100644 package/binutils/2.33.1/0006-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patchpackage/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128
-0@@ -0,0 +1,128 @@ +From 735321812435ae278d3766a3371f55937dc776d6 Mon Sep 17 00:00:00 2001 +From: Max Filippov <[email protected]> +Date: Sat, 25 Apr 2020 00:40:25 -0700 +Subject: [PATCH] xtensa: fix XTENSA_NDIFF handling for PR ld/25861 + +Fields marked with XTENSA_NDIFF relocations are not negated, they only +have sign bits removed. Don't negate their values when relaxation is +performed. Don't add sign bits when the value is zero. Report overflow +when the result has negative sign but all significant bits are zero. + +2020-04-29 Max Filippov <[email protected]> +bfd/ + * elf32-xtensa.c (relax_section): Don't negate diff_value for + XTENSA_NDIFF relocations. Don't add sign bits whe diff_value + equals 0. Report overflow when the result has negative sign but + all significant bits are zero. + +Signed-off-by: Max Filippov <[email protected]> +--- +Backported from: d548f47df4d2e3d117d504a4c9977982c78a0556 + + bfd/elf32-xtensa.c | 26 +++++++++++++++----------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index fded42d52a9a..4327b027911f 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -9670,37 +9670,44 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: ++ diff_mask = 0x7f; + diff_value = + bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: ++ diff_mask = 0x7fff; + diff_value = + bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: ++ diff_mask = 0x7fffffff; + diff_value = + bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: ++ diff_mask = 0xff; + diff_value = + bfd_get_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: ++ diff_mask = 0xffff; + diff_value = + bfd_get_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: ++ diff_mask = 0xffffffff; + diff_value = + bfd_get_32 (abfd, &contents[old_source_offset]); + break; + } + + if (r_type >= R_XTENSA_NDIFF8 +- && r_type <= R_XTENSA_NDIFF32) +- diff_value = -diff_value; ++ && r_type <= R_XTENSA_NDIFF32 ++ && diff_value) ++ diff_value |= ~diff_mask; + + new_end_offset = offset_with_removed_text_map + (&target_relax_info->action_list, +@@ -9710,43 +9717,40 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0x7f; + bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0x7fff; + bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0x7fffffff; + bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: +- diff_mask = 0xff; + bfd_put_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: +- diff_mask = 0xffff; + bfd_put_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: +- diff_mask = 0xffffffff; + bfd_put_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. Sign bits must be all zeroes or all ones */ +- if ((diff_value & ~diff_mask) != 0 && +- (diff_value & ~diff_mask) != (-1 & ~diff_mask)) ++ /* Check for overflow. Sign bits must be all zeroes or ++ all ones. When sign bits are all ones diff_value ++ may not be zero. */ ++ if (((diff_value & ~diff_mask) != 0 ++ && (diff_value & ~diff_mask) != ~diff_mask) ++ || (diff_value && (bfd_vma) diff_value == ~diff_mask)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +-- +2.20.1 +package/binutils/2.32/0009-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128
-0@@ -0,0 +1,128 @@ +From 735321812435ae278d3766a3371f55937dc776d6 Mon Sep 17 00:00:00 2001 +From: Max Filippov <[email protected]> +Date: Sat, 25 Apr 2020 00:40:25 -0700 +Subject: [PATCH] xtensa: fix XTENSA_NDIFF handling for PR ld/25861 + +Fields marked with XTENSA_NDIFF relocations are not negated, they only +have sign bits removed. Don't negate their values when relaxation is +performed. Don't add sign bits when the value is zero. Report overflow +when the result has negative sign but all significant bits are zero. + +2020-04-29 Max Filippov <[email protected]> +bfd/ + * elf32-xtensa.c (relax_section): Don't negate diff_value for + XTENSA_NDIFF relocations. Don't add sign bits whe diff_value + equals 0. Report overflow when the result has negative sign but + all significant bits are zero. + +Signed-off-by: Max Filippov <[email protected]> +--- +Backported from: d548f47df4d2e3d117d504a4c9977982c78a0556 + + bfd/elf32-xtensa.c | 26 +++++++++++++++----------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index fded42d52a9a..4327b027911f 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -9670,37 +9670,44 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: ++ diff_mask = 0x7f; + diff_value = + bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: ++ diff_mask = 0x7fff; + diff_value = + bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: ++ diff_mask = 0x7fffffff; + diff_value = + bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: ++ diff_mask = 0xff; + diff_value = + bfd_get_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: ++ diff_mask = 0xffff; + diff_value = + bfd_get_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: ++ diff_mask = 0xffffffff; + diff_value = + bfd_get_32 (abfd, &contents[old_source_offset]); + break; + } + + if (r_type >= R_XTENSA_NDIFF8 +- && r_type <= R_XTENSA_NDIFF32) +- diff_value = -diff_value; ++ && r_type <= R_XTENSA_NDIFF32 ++ && diff_value) ++ diff_value |= ~diff_mask; + + new_end_offset = offset_with_removed_text_map + (&target_relax_info->action_list, +@@ -9710,43 +9717,40 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0x7f; + bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0x7fff; + bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0x7fffffff; + bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: +- diff_mask = 0xff; + bfd_put_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: +- diff_mask = 0xffff; + bfd_put_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: +- diff_mask = 0xffffffff; + bfd_put_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. Sign bits must be all zeroes or all ones */ +- if ((diff_value & ~diff_mask) != 0 && +- (diff_value & ~diff_mask) != (-1 & ~diff_mask)) ++ /* Check for overflow. Sign bits must be all zeroes or ++ all ones. When sign bits are all ones diff_value ++ may not be zero. */ ++ if (((diff_value & ~diff_mask) != 0 ++ && (diff_value & ~diff_mask) != ~diff_mask) ++ || (diff_value && (bfd_vma) diff_value == ~diff_mask)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +-- +2.20.1 +package/binutils/2.33.1/0006-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128
-0@@ -0,0 +1,128 @@ +From 735321812435ae278d3766a3371f55937dc776d6 Mon Sep 17 00:00:00 2001 +From: Max Filippov <[email protected]> +Date: Sat, 25 Apr 2020 00:40:25 -0700 +Subject: [PATCH] xtensa: fix XTENSA_NDIFF handling for PR ld/25861 + +Fields marked with XTENSA_NDIFF relocations are not negated, they only +have sign bits removed. Don't negate their values when relaxation is +performed. Don't add sign bits when the value is zero. Report overflow +when the result has negative sign but all significant bits are zero. + +2020-04-29 Max Filippov <[email protected]> +bfd/ + * elf32-xtensa.c (relax_section): Don't negate diff_value for + XTENSA_NDIFF relocations. Don't add sign bits whe diff_value + equals 0. Report overflow when the result has negative sign but + all significant bits are zero. + +Signed-off-by: Max Filippov <[email protected]> +--- +Backported from: d548f47df4d2e3d117d504a4c9977982c78a0556 + + bfd/elf32-xtensa.c | 26 +++++++++++++++----------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index fded42d52a9a..4327b027911f 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -9670,37 +9670,44 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: ++ diff_mask = 0x7f; + diff_value = + bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: ++ diff_mask = 0x7fff; + diff_value = + bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: ++ diff_mask = 0x7fffffff; + diff_value = + bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: ++ diff_mask = 0xff; + diff_value = + bfd_get_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: ++ diff_mask = 0xffff; + diff_value = + bfd_get_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: ++ diff_mask = 0xffffffff; + diff_value = + bfd_get_32 (abfd, &contents[old_source_offset]); + break; + } + + if (r_type >= R_XTENSA_NDIFF8 +- && r_type <= R_XTENSA_NDIFF32) +- diff_value = -diff_value; ++ && r_type <= R_XTENSA_NDIFF32 ++ && diff_value) ++ diff_value |= ~diff_mask; + + new_end_offset = offset_with_removed_text_map + (&target_relax_info->action_list, +@@ -9710,43 +9717,40 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0x7f; + bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0x7fff; + bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0x7fffffff; + bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: +- diff_mask = 0xff; + bfd_put_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: +- diff_mask = 0xffff; + bfd_put_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: +- diff_mask = 0xffffffff; + bfd_put_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. Sign bits must be all zeroes or all ones */ +- if ((diff_value & ~diff_mask) != 0 && +- (diff_value & ~diff_mask) != (-1 & ~diff_mask)) ++ /* Check for overflow. Sign bits must be all zeroes or ++ all ones. When sign bits are all ones diff_value ++ may not be zero. */ ++ if (((diff_value & ~diff_mask) != 0 ++ && (diff_value & ~diff_mask) != ~diff_mask) ++ || (diff_value && (bfd_vma) diff_value == ~diff_mask)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +-- +2.20.1 +
PATCH 1/1 package/binutils: fix XTENSA_NDIFF handling for PR ld/25861
Hi Romain,
Quoted 6 lines · Romain Naour
It seems elf2flt used by
qemu_xtensa_lx60_nommu_defconfigdoesn't supportR_XTENSA_PDIFF32:elf2flt: 267 bad relocs
Thanks for the report. Proposed fix:
https://github.com/uclinux-dev/elf2flt/pull/18
Signature · 2 lines
Thanks. -- Max
Yann E. MORIN
AppliedPATCH 1/1 package/binutils: fix XTENSA_NDIFF handling for PR ld/25861
In reply to Max FilippovMax, All,
On 2020-04-29 22:08 -0700, Max Filippov spake thusly:
Quoted 34 lines
Fix for xtensa PR ld/25861 introduced a regression in handling negative symbol differences resulting in linker performing incorrect relaxation or failing to link. Fix
XTENSA_NDIFFrelocation handling.Backported from:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=d548f47df4d2e3d117d504a4c9977982c78a0556Fixes f0291ef4aba0 ("package/binutils: fix xtensa PR ld/25861")Signed-off-by Max Filippov <[email protected]>--- ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ ...TENSA_NDIFF-handling-for-PR-ld-25861.patch | 128 ++++++++++++++++++ 3 files changed, 384 insertions(+) create mode 100644 package/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch create mode 100644 package/binutils/2.32/0009-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch create mode 100644 package/binutils/2.33.1/0006-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patchpackage/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +10
-0@@ -0,0 +1,128 @@ +From 735321812435ae278d3766a3371f55937dc776d6 Mon Sep 17 00:00:00 2001 +From: Max Filippov <[email protected]> +Date: Sat, 25 Apr 2020 00:40:25 -0700 +Subject: [PATCH] xtensa: fix XTENSA_NDIFF handling for PR ld/25861 + +Fields marked with XTENSA_NDIFF relocations are not negated, they only +have sign bits removed. Don't negate their values when relaxation is +performed. Don't add sign bits when the value is zero. Report overflow +when the result has negative sign but all significant bits are zero. +
package/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch line 20
Quoted 10 lines
package/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +10
-0+2020-04-29 Max Filippov <[email protected]> +bfd/ + * elf32-xtensa.c (relax_section): Don't negate diff_value for + XTENSA_NDIFF relocations. Don't add sign bits whe diff_value + equals 0. Report overflow when the result has negative sign but + all significant bits are zero. + +Signed-off-by: Max Filippov <[email protected]> +--- +Backported from: d548f47df4d2e3d117d504a4c9977982c78a0556
I thnk the "Backported from" info is important, and so should belong to the commit log, so I moved in just before the --- line, in all three patches.
Applied to master, thanks.
Regards,
Yann E. MORIN.
Quoted 382 lines
package/binutils/2.31.1/0020-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +107
-0+ bfd/elf32-xtensa.c | 26 +++++++++++++++----------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index fded42d52a9a..4327b027911f 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -9670,37 +9670,44 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: ++ diff_mask = 0x7f; + diff_value = + bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: ++ diff_mask = 0x7fff; + diff_value = + bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: ++ diff_mask = 0x7fffffff; + diff_value = + bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: ++ diff_mask = 0xff; + diff_value = + bfd_get_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: ++ diff_mask = 0xffff; + diff_value = + bfd_get_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: ++ diff_mask = 0xffffffff; + diff_value = + bfd_get_32 (abfd, &contents[old_source_offset]); + break; + } + + if (r_type >= R_XTENSA_NDIFF8 +- && r_type <= R_XTENSA_NDIFF32) +- diff_value = -diff_value; ++ && r_type <= R_XTENSA_NDIFF32 ++ && diff_value) ++ diff_value |= ~diff_mask; + + new_end_offset = offset_with_removed_text_map + (&target_relax_info->action_list, +@@ -9710,43 +9717,40 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0x7f; + bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0x7fff; + bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0x7fffffff; + bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: +- diff_mask = 0xff; + bfd_put_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: +- diff_mask = 0xffff; + bfd_put_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: +- diff_mask = 0xffffffff; + bfd_put_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. Sign bits must be all zeroes or all ones */ +- if ((diff_value & ~diff_mask) != 0 && +- (diff_value & ~diff_mask) != (-1 & ~diff_mask)) ++ /* Check for overflow. Sign bits must be all zeroes or ++ all ones. When sign bits are all ones diff_value ++ may not be zero. */ ++ if (((diff_value & ~diff_mask) != 0 ++ && (diff_value & ~diff_mask) != ~diff_mask) ++ || (diff_value && (bfd_vma) diff_value == ~diff_mask)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +-- +2.20.1 +package/binutils/2.32/0009-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128
-0@@ -0,0 +1,128 @@ +From 735321812435ae278d3766a3371f55937dc776d6 Mon Sep 17 00:00:00 2001 +From: Max Filippov <[email protected]> +Date: Sat, 25 Apr 2020 00:40:25 -0700 +Subject: [PATCH] xtensa: fix XTENSA_NDIFF handling for PR ld/25861 + +Fields marked with XTENSA_NDIFF relocations are not negated, they only +have sign bits removed. Don't negate their values when relaxation is +performed. Don't add sign bits when the value is zero. Report overflow +when the result has negative sign but all significant bits are zero. + +2020-04-29 Max Filippov <[email protected]> +bfd/ + * elf32-xtensa.c (relax_section): Don't negate diff_value for + XTENSA_NDIFF relocations. Don't add sign bits whe diff_value + equals 0. Report overflow when the result has negative sign but + all significant bits are zero. + +Signed-off-by: Max Filippov <[email protected]> +--- +Backported from: d548f47df4d2e3d117d504a4c9977982c78a0556 + + bfd/elf32-xtensa.c | 26 +++++++++++++++----------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index fded42d52a9a..4327b027911f 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -9670,37 +9670,44 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: ++ diff_mask = 0x7f; + diff_value = + bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: ++ diff_mask = 0x7fff; + diff_value = + bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: ++ diff_mask = 0x7fffffff; + diff_value = + bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: ++ diff_mask = 0xff; + diff_value = + bfd_get_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: ++ diff_mask = 0xffff; + diff_value = + bfd_get_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: ++ diff_mask = 0xffffffff; + diff_value = + bfd_get_32 (abfd, &contents[old_source_offset]); + break; + } + + if (r_type >= R_XTENSA_NDIFF8 +- && r_type <= R_XTENSA_NDIFF32) +- diff_value = -diff_value; ++ && r_type <= R_XTENSA_NDIFF32 ++ && diff_value) ++ diff_value |= ~diff_mask; + + new_end_offset = offset_with_removed_text_map + (&target_relax_info->action_list, +@@ -9710,43 +9717,40 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0x7f; + bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0x7fff; + bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0x7fffffff; + bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: +- diff_mask = 0xff; + bfd_put_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: +- diff_mask = 0xffff; + bfd_put_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: +- diff_mask = 0xffffffff; + bfd_put_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. Sign bits must be all zeroes or all ones */ +- if ((diff_value & ~diff_mask) != 0 && +- (diff_value & ~diff_mask) != (-1 & ~diff_mask)) ++ /* Check for overflow. Sign bits must be all zeroes or ++ all ones. When sign bits are all ones diff_value ++ may not be zero. */ ++ if (((diff_value & ~diff_mask) != 0 ++ && (diff_value & ~diff_mask) != ~diff_mask) ++ || (diff_value && (bfd_vma) diff_value == ~diff_mask)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +-- +2.20.1 +package/binutils/2.33.1/0006-xtensa-fix-XTENSA_NDIFF-handling-for-PR-ld-25861.patch new file +128
-0@@ -0,0 +1,128 @@ +From 735321812435ae278d3766a3371f55937dc776d6 Mon Sep 17 00:00:00 2001 +From: Max Filippov <[email protected]> +Date: Sat, 25 Apr 2020 00:40:25 -0700 +Subject: [PATCH] xtensa: fix XTENSA_NDIFF handling for PR ld/25861 + +Fields marked with XTENSA_NDIFF relocations are not negated, they only +have sign bits removed. Don't negate their values when relaxation is +performed. Don't add sign bits when the value is zero. Report overflow +when the result has negative sign but all significant bits are zero. + +2020-04-29 Max Filippov <[email protected]> +bfd/ + * elf32-xtensa.c (relax_section): Don't negate diff_value for + XTENSA_NDIFF relocations. Don't add sign bits whe diff_value + equals 0. Report overflow when the result has negative sign but + all significant bits are zero. + +Signed-off-by: Max Filippov <[email protected]> +--- +Backported from: d548f47df4d2e3d117d504a4c9977982c78a0556 + + bfd/elf32-xtensa.c | 26 +++++++++++++++----------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index fded42d52a9a..4327b027911f 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -9670,37 +9670,44 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: ++ diff_mask = 0x7f; + diff_value = + bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: ++ diff_mask = 0x7fff; + diff_value = + bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: ++ diff_mask = 0x7fffffff; + diff_value = + bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: ++ diff_mask = 0xff; + diff_value = + bfd_get_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: ++ diff_mask = 0xffff; + diff_value = + bfd_get_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: ++ diff_mask = 0xffffffff; + diff_value = + bfd_get_32 (abfd, &contents[old_source_offset]); + break; + } + + if (r_type >= R_XTENSA_NDIFF8 +- && r_type <= R_XTENSA_NDIFF32) +- diff_value = -diff_value; ++ && r_type <= R_XTENSA_NDIFF32 ++ && diff_value) ++ diff_value |= ~diff_mask; + + new_end_offset = offset_with_removed_text_map + (&target_relax_info->action_list, +@@ -9710,43 +9717,40 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0x7f; + bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0x7fff; + bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0x7fffffff; + bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF8: + case R_XTENSA_NDIFF8: +- diff_mask = 0xff; + bfd_put_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF16: + case R_XTENSA_NDIFF16: +- diff_mask = 0xffff; + bfd_put_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_PDIFF32: + case R_XTENSA_NDIFF32: +- diff_mask = 0xffffffff; + bfd_put_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. Sign bits must be all zeroes or all ones */ +- if ((diff_value & ~diff_mask) != 0 && +- (diff_value & ~diff_mask) != (-1 & ~diff_mask)) ++ /* Check for overflow. Sign bits must be all zeroes or ++ all ones. When sign bits are all ones diff_value ++ may not be zero. */ ++ if (((diff_value & ~diff_mask) != 0 ++ && (diff_value & ~diff_mask) != ~diff_mask) ++ || (diff_value && (bfd_vma) diff_value == ~diff_mask)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +-- +2.20.1 +Signature · 6 lines
2.20.1 _______________________________________________ buildroot mailing list buildroot at busybox.net http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH 1/1 package/binutils: fix XTENSA_NDIFF handling for PR ld/25861
In reply to Max FilippovQuoted 11 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Max" == Max Filippov <[email protected]> writes:
Fix for xtensa PR ld/25861 introduced a regression in handling negative symbol differences resulting in linker performing incorrect relaxation or failing to link. Fix
XTENSA_NDIFFrelocation handling.Backported from:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=d548f47df4d2e3d117d504a4c9977982c78a0556Fixes f0291ef4aba0 ("package/binutils: fix xtensa PR ld/25861")Signed-off-by Max Filippov <[email protected]>
Committed to 2020.02.x, thanks.
Signature · 1 line
Bye, Peter Korsgaard