From patchwork Wed May 7 22:51:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 346841 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ozlabs.org (Postfix) with ESMTP id 39C411401A7 for ; Thu, 8 May 2014 08:51:46 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 534F68ADC7; Wed, 7 May 2014 22:51:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v3qm-ExrQe8E; Wed, 7 May 2014 22:51:42 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id DA3068807A; Wed, 7 May 2014 22:51:41 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (hemlock.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id B7A221C245E for ; Wed, 7 May 2014 22:51:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id B1B8487A05 for ; Wed, 7 May 2014 22:51:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yRUGvePUKcjl for ; Wed, 7 May 2014 22:51:38 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com [209.85.217.170]) by hemlock.osuosl.org (Postfix) with ESMTPS id 3788687BBC for ; Wed, 7 May 2014 22:51:38 +0000 (UTC) Received: by mail-lb0-f170.google.com with SMTP id w7so2370164lbi.29 for ; Wed, 07 May 2014 15:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2HeO4EyotjE2ufJpyT/43YxD4iudiKusHSGq83W2L+k=; b=0FOqykKI/4IR8SN0xugWYxMt0QecjIT9zuHpYkFAuylUYbT7ECWNDc0+P7Ue1bskFh a2M66SCULGpjM7dV5E98k7XU5mRw1uWhCPgTErPfWXIe+sjJwGGfz/mwi7OXsZ2uTUHc rzyCvWZ2l57OzI6+rN3TnocM2pVCRqyHZiRHSiZwkNrjSxUhfR5kqyToQEzsPplaiOGM m8Vg+tIMhGlZFc6jgsruUWNixbwNd7rDote+pAFN8+X/9DR4Dqeo2Yr6vkt8RqtdXuOd nH3+U2PM9nQ601w27pbRjwaxkLkPkzWq/B+zF2RLXeQwN30lIqTepBO9i6Bh0qlvtgNm 7xXw== X-Received: by 10.112.63.169 with SMTP id h9mr36077lbs.84.1399503096269; Wed, 07 May 2014 15:51:36 -0700 (PDT) Received: from octofox.metropolis ([188.134.19.124]) by mx.google.com with ESMTPSA id jg8sm5891241lbc.9.2014.05.07.15.51.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 May 2014 15:51:33 -0700 (PDT) From: Max Filippov To: buildroot@uclibc.org Date: Thu, 8 May 2014 02:51:05 +0400 Message-Id: <1399503065-18819-3-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1399503065-18819-1-git-send-email-jcmvbkbc@gmail.com> References: <1399503065-18819-1-git-send-email-jcmvbkbc@gmail.com> Cc: Thomas Petazzoni , linux-xtensa@linux-xtensa.org Subject: [Buildroot] [PATCH 2/2] binutils: backport R_XTENSA_DIFF* relocation signedness fix X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: buildroot-bounces@busybox.net This fixes the following build errors: qlatincodec.o:(.debug_line+0xcd7): dangerous relocation: overflow after relaxation qmetaobject.o:(.debug_frame+0xa89): dangerous relocation: overflow after relaxation Fixes: http://autobuild.buildroot.net/results/f51/f51c87ae3c883cc36b06c0741999b52e48e4c943/ http://autobuild.buildroot.net/results/bcb/bcbf25e4054911a7a192bdb5c92e0ebd50e9666c/ http://autobuild.buildroot.net/results/8a8/8a8a0f8cca293ce1f383421ba8b1223b4266e3bc/ http://autobuild.buildroot.net/results/a54/a54f3707781dc193292eda7d1723fce6487d6980/ Backported from: 1058c7532d0b012ac329219264ddad59049fb6e6 Signed-off-by: Max Filippov --- .../902-xtensa-gas-ld-diff-relocation-signed.patch | 133 +++++++++++++++++++++ .../902-xtensa-gas-ld-diff-relocation-signed.patch | 133 +++++++++++++++++++++ .../902-xtensa-gas-ld-diff-relocation-signed.patch | 133 +++++++++++++++++++++ .../902-xtensa-gas-ld-diff-relocation-signed.patch | 133 +++++++++++++++++++++ 4 files changed, 532 insertions(+) create mode 100644 package/binutils/2.22/902-xtensa-gas-ld-diff-relocation-signed.patch create mode 100644 package/binutils/2.23.1/902-xtensa-gas-ld-diff-relocation-signed.patch create mode 100644 package/binutils/2.23.2/902-xtensa-gas-ld-diff-relocation-signed.patch create mode 100644 package/binutils/2.24/902-xtensa-gas-ld-diff-relocation-signed.patch diff --git a/package/binutils/2.22/902-xtensa-gas-ld-diff-relocation-signed.patch b/package/binutils/2.22/902-xtensa-gas-ld-diff-relocation-signed.patch new file mode 100644 index 0000000..ba24f4e --- /dev/null +++ b/package/binutils/2.22/902-xtensa-gas-ld-diff-relocation-signed.patch @@ -0,0 +1,133 @@ +From 6a17eba5358549d0d6d195bb22b34cdbc068def2 Mon Sep 17 00:00:00 2001 +From: Volodymyr Arbatov +Date: Mon, 6 May 2013 09:43:21 -0800 +Subject: [PATCH] Use signed data type for R_XTENSA_DIFF* relocation offsets. + +R_XTENSA_DIFF relocation offsets are in fact signed. Treat them as such. +Add testcase that examines ld behaviour on R_XTENSA_DIFF relocation +changing sign during relaxation. + +2014-05-02 Volodymyr Arbatov + David Weatherford + Max Filippov + +bfd/ + * elf32-xtensa.c (relax_section): treat R_XTENSA_DIFF* relocations as + signed. + +gas/ + * config/tc-xtensa.c (md_apply_fix): mark BFD_RELOC_XTENSA_DIFF* + fixups as signed. +--- +Backported from: 1058c7532d0b012ac329219264ddad59049fb6e6 +Changes to Changelog files and tests are dropped. + + bfd/elf32-xtensa.c | 32 ++++++++++++----------- + gas/config/tc-xtensa.c | 3 +++ + 2 files changed, 20 insertions(+), 15 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index edb04b4..8818d67 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -222,11 +222,11 @@ static reloc_howto_type elf_howto_table[] = + FALSE, 0, 0, FALSE), + + /* Relocations for supporting difference of symbols. */ +- HOWTO (R_XTENSA_DIFF8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF8, 0, 0, 8, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF8", FALSE, 0, 0xff, FALSE), +- HOWTO (R_XTENSA_DIFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF16, 0, 1, 16, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF16", FALSE, 0, 0xffff, FALSE), +- HOWTO (R_XTENSA_DIFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF32", FALSE, 0, 0xffffffff, FALSE), + + /* General immediate operand relocations. */ +@@ -9013,7 +9013,8 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + || r_type == R_XTENSA_DIFF16 + || r_type == R_XTENSA_DIFF32) + { +- bfd_vma diff_value = 0, new_end_offset, diff_mask = 0; ++ bfd_signed_vma diff_value = 0; ++ bfd_vma new_end_offset, diff_mask = 0; + + if (bfd_get_section_limit (abfd, sec) < old_source_offset) + { +@@ -9027,15 +9028,15 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + { + case R_XTENSA_DIFF8: + diff_value = +- bfd_get_8 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: + diff_value = +- bfd_get_16 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: + diff_value = +- bfd_get_32 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + } + +@@ -9047,24 +9048,25 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0xff; +- bfd_put_8 (abfd, diff_value, ++ diff_mask = 0x7f; ++ bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0xffff; +- bfd_put_16 (abfd, diff_value, ++ diff_mask = 0x7fff; ++ bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0xffffffff; +- bfd_put_32 (abfd, diff_value, ++ diff_mask = 0x7fffffff; ++ bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. */ +- if ((diff_value & ~diff_mask) != 0) ++ /* 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)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c +index 58ace38..7547c0a0 100644 +--- a/gas/config/tc-xtensa.c ++++ b/gas/config/tc-xtensa.c +@@ -5867,12 +5867,15 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg) + { + case BFD_RELOC_8: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF8; ++ fixP->fx_signed = 1; + break; + case BFD_RELOC_16: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF16; ++ fixP->fx_signed = 1; + break; + case BFD_RELOC_32: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF32; ++ fixP->fx_signed = 1; + break; + default: + break; +-- +1.8.1.4 + diff --git a/package/binutils/2.23.1/902-xtensa-gas-ld-diff-relocation-signed.patch b/package/binutils/2.23.1/902-xtensa-gas-ld-diff-relocation-signed.patch new file mode 100644 index 0000000..ba24f4e --- /dev/null +++ b/package/binutils/2.23.1/902-xtensa-gas-ld-diff-relocation-signed.patch @@ -0,0 +1,133 @@ +From 6a17eba5358549d0d6d195bb22b34cdbc068def2 Mon Sep 17 00:00:00 2001 +From: Volodymyr Arbatov +Date: Mon, 6 May 2013 09:43:21 -0800 +Subject: [PATCH] Use signed data type for R_XTENSA_DIFF* relocation offsets. + +R_XTENSA_DIFF relocation offsets are in fact signed. Treat them as such. +Add testcase that examines ld behaviour on R_XTENSA_DIFF relocation +changing sign during relaxation. + +2014-05-02 Volodymyr Arbatov + David Weatherford + Max Filippov + +bfd/ + * elf32-xtensa.c (relax_section): treat R_XTENSA_DIFF* relocations as + signed. + +gas/ + * config/tc-xtensa.c (md_apply_fix): mark BFD_RELOC_XTENSA_DIFF* + fixups as signed. +--- +Backported from: 1058c7532d0b012ac329219264ddad59049fb6e6 +Changes to Changelog files and tests are dropped. + + bfd/elf32-xtensa.c | 32 ++++++++++++----------- + gas/config/tc-xtensa.c | 3 +++ + 2 files changed, 20 insertions(+), 15 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index edb04b4..8818d67 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -222,11 +222,11 @@ static reloc_howto_type elf_howto_table[] = + FALSE, 0, 0, FALSE), + + /* Relocations for supporting difference of symbols. */ +- HOWTO (R_XTENSA_DIFF8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF8, 0, 0, 8, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF8", FALSE, 0, 0xff, FALSE), +- HOWTO (R_XTENSA_DIFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF16, 0, 1, 16, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF16", FALSE, 0, 0xffff, FALSE), +- HOWTO (R_XTENSA_DIFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF32", FALSE, 0, 0xffffffff, FALSE), + + /* General immediate operand relocations. */ +@@ -9013,7 +9013,8 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + || r_type == R_XTENSA_DIFF16 + || r_type == R_XTENSA_DIFF32) + { +- bfd_vma diff_value = 0, new_end_offset, diff_mask = 0; ++ bfd_signed_vma diff_value = 0; ++ bfd_vma new_end_offset, diff_mask = 0; + + if (bfd_get_section_limit (abfd, sec) < old_source_offset) + { +@@ -9027,15 +9028,15 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + { + case R_XTENSA_DIFF8: + diff_value = +- bfd_get_8 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: + diff_value = +- bfd_get_16 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: + diff_value = +- bfd_get_32 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + } + +@@ -9047,24 +9048,25 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0xff; +- bfd_put_8 (abfd, diff_value, ++ diff_mask = 0x7f; ++ bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0xffff; +- bfd_put_16 (abfd, diff_value, ++ diff_mask = 0x7fff; ++ bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0xffffffff; +- bfd_put_32 (abfd, diff_value, ++ diff_mask = 0x7fffffff; ++ bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. */ +- if ((diff_value & ~diff_mask) != 0) ++ /* 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)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c +index 58ace38..7547c0a0 100644 +--- a/gas/config/tc-xtensa.c ++++ b/gas/config/tc-xtensa.c +@@ -5867,12 +5867,15 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg) + { + case BFD_RELOC_8: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF8; ++ fixP->fx_signed = 1; + break; + case BFD_RELOC_16: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF16; ++ fixP->fx_signed = 1; + break; + case BFD_RELOC_32: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF32; ++ fixP->fx_signed = 1; + break; + default: + break; +-- +1.8.1.4 + diff --git a/package/binutils/2.23.2/902-xtensa-gas-ld-diff-relocation-signed.patch b/package/binutils/2.23.2/902-xtensa-gas-ld-diff-relocation-signed.patch new file mode 100644 index 0000000..ba24f4e --- /dev/null +++ b/package/binutils/2.23.2/902-xtensa-gas-ld-diff-relocation-signed.patch @@ -0,0 +1,133 @@ +From 6a17eba5358549d0d6d195bb22b34cdbc068def2 Mon Sep 17 00:00:00 2001 +From: Volodymyr Arbatov +Date: Mon, 6 May 2013 09:43:21 -0800 +Subject: [PATCH] Use signed data type for R_XTENSA_DIFF* relocation offsets. + +R_XTENSA_DIFF relocation offsets are in fact signed. Treat them as such. +Add testcase that examines ld behaviour on R_XTENSA_DIFF relocation +changing sign during relaxation. + +2014-05-02 Volodymyr Arbatov + David Weatherford + Max Filippov + +bfd/ + * elf32-xtensa.c (relax_section): treat R_XTENSA_DIFF* relocations as + signed. + +gas/ + * config/tc-xtensa.c (md_apply_fix): mark BFD_RELOC_XTENSA_DIFF* + fixups as signed. +--- +Backported from: 1058c7532d0b012ac329219264ddad59049fb6e6 +Changes to Changelog files and tests are dropped. + + bfd/elf32-xtensa.c | 32 ++++++++++++----------- + gas/config/tc-xtensa.c | 3 +++ + 2 files changed, 20 insertions(+), 15 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index edb04b4..8818d67 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -222,11 +222,11 @@ static reloc_howto_type elf_howto_table[] = + FALSE, 0, 0, FALSE), + + /* Relocations for supporting difference of symbols. */ +- HOWTO (R_XTENSA_DIFF8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF8, 0, 0, 8, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF8", FALSE, 0, 0xff, FALSE), +- HOWTO (R_XTENSA_DIFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF16, 0, 1, 16, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF16", FALSE, 0, 0xffff, FALSE), +- HOWTO (R_XTENSA_DIFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF32", FALSE, 0, 0xffffffff, FALSE), + + /* General immediate operand relocations. */ +@@ -9013,7 +9013,8 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + || r_type == R_XTENSA_DIFF16 + || r_type == R_XTENSA_DIFF32) + { +- bfd_vma diff_value = 0, new_end_offset, diff_mask = 0; ++ bfd_signed_vma diff_value = 0; ++ bfd_vma new_end_offset, diff_mask = 0; + + if (bfd_get_section_limit (abfd, sec) < old_source_offset) + { +@@ -9027,15 +9028,15 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + { + case R_XTENSA_DIFF8: + diff_value = +- bfd_get_8 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: + diff_value = +- bfd_get_16 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: + diff_value = +- bfd_get_32 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + } + +@@ -9047,24 +9048,25 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0xff; +- bfd_put_8 (abfd, diff_value, ++ diff_mask = 0x7f; ++ bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0xffff; +- bfd_put_16 (abfd, diff_value, ++ diff_mask = 0x7fff; ++ bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0xffffffff; +- bfd_put_32 (abfd, diff_value, ++ diff_mask = 0x7fffffff; ++ bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. */ +- if ((diff_value & ~diff_mask) != 0) ++ /* 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)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c +index 58ace38..7547c0a0 100644 +--- a/gas/config/tc-xtensa.c ++++ b/gas/config/tc-xtensa.c +@@ -5867,12 +5867,15 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg) + { + case BFD_RELOC_8: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF8; ++ fixP->fx_signed = 1; + break; + case BFD_RELOC_16: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF16; ++ fixP->fx_signed = 1; + break; + case BFD_RELOC_32: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF32; ++ fixP->fx_signed = 1; + break; + default: + break; +-- +1.8.1.4 + diff --git a/package/binutils/2.24/902-xtensa-gas-ld-diff-relocation-signed.patch b/package/binutils/2.24/902-xtensa-gas-ld-diff-relocation-signed.patch new file mode 100644 index 0000000..ba24f4e --- /dev/null +++ b/package/binutils/2.24/902-xtensa-gas-ld-diff-relocation-signed.patch @@ -0,0 +1,133 @@ +From 6a17eba5358549d0d6d195bb22b34cdbc068def2 Mon Sep 17 00:00:00 2001 +From: Volodymyr Arbatov +Date: Mon, 6 May 2013 09:43:21 -0800 +Subject: [PATCH] Use signed data type for R_XTENSA_DIFF* relocation offsets. + +R_XTENSA_DIFF relocation offsets are in fact signed. Treat them as such. +Add testcase that examines ld behaviour on R_XTENSA_DIFF relocation +changing sign during relaxation. + +2014-05-02 Volodymyr Arbatov + David Weatherford + Max Filippov + +bfd/ + * elf32-xtensa.c (relax_section): treat R_XTENSA_DIFF* relocations as + signed. + +gas/ + * config/tc-xtensa.c (md_apply_fix): mark BFD_RELOC_XTENSA_DIFF* + fixups as signed. +--- +Backported from: 1058c7532d0b012ac329219264ddad59049fb6e6 +Changes to Changelog files and tests are dropped. + + bfd/elf32-xtensa.c | 32 ++++++++++++----------- + gas/config/tc-xtensa.c | 3 +++ + 2 files changed, 20 insertions(+), 15 deletions(-) + +diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c +index edb04b4..8818d67 100644 +--- a/bfd/elf32-xtensa.c ++++ b/bfd/elf32-xtensa.c +@@ -222,11 +222,11 @@ static reloc_howto_type elf_howto_table[] = + FALSE, 0, 0, FALSE), + + /* Relocations for supporting difference of symbols. */ +- HOWTO (R_XTENSA_DIFF8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF8, 0, 0, 8, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF8", FALSE, 0, 0xff, FALSE), +- HOWTO (R_XTENSA_DIFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF16, 0, 1, 16, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF16", FALSE, 0, 0xffff, FALSE), +- HOWTO (R_XTENSA_DIFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, ++ HOWTO (R_XTENSA_DIFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed, + bfd_elf_xtensa_reloc, "R_XTENSA_DIFF32", FALSE, 0, 0xffffffff, FALSE), + + /* General immediate operand relocations. */ +@@ -9013,7 +9013,8 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + || r_type == R_XTENSA_DIFF16 + || r_type == R_XTENSA_DIFF32) + { +- bfd_vma diff_value = 0, new_end_offset, diff_mask = 0; ++ bfd_signed_vma diff_value = 0; ++ bfd_vma new_end_offset, diff_mask = 0; + + if (bfd_get_section_limit (abfd, sec) < old_source_offset) + { +@@ -9027,15 +9028,15 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + { + case R_XTENSA_DIFF8: + diff_value = +- bfd_get_8 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_8 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: + diff_value = +- bfd_get_16 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_16 (abfd, &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: + diff_value = +- bfd_get_32 (abfd, &contents[old_source_offset]); ++ bfd_get_signed_32 (abfd, &contents[old_source_offset]); + break; + } + +@@ -9047,24 +9048,25 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) + switch (r_type) + { + case R_XTENSA_DIFF8: +- diff_mask = 0xff; +- bfd_put_8 (abfd, diff_value, ++ diff_mask = 0x7f; ++ bfd_put_signed_8 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF16: +- diff_mask = 0xffff; +- bfd_put_16 (abfd, diff_value, ++ diff_mask = 0x7fff; ++ bfd_put_signed_16 (abfd, diff_value, + &contents[old_source_offset]); + break; + case R_XTENSA_DIFF32: +- diff_mask = 0xffffffff; +- bfd_put_32 (abfd, diff_value, ++ diff_mask = 0x7fffffff; ++ bfd_put_signed_32 (abfd, diff_value, + &contents[old_source_offset]); + break; + } + +- /* Check for overflow. */ +- if ((diff_value & ~diff_mask) != 0) ++ /* 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)) + { + (*link_info->callbacks->reloc_dangerous) + (link_info, _("overflow after relaxation"), +diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c +index 58ace38..7547c0a0 100644 +--- a/gas/config/tc-xtensa.c ++++ b/gas/config/tc-xtensa.c +@@ -5867,12 +5867,15 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg) + { + case BFD_RELOC_8: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF8; ++ fixP->fx_signed = 1; + break; + case BFD_RELOC_16: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF16; ++ fixP->fx_signed = 1; + break; + case BFD_RELOC_32: + fixP->fx_r_type = BFD_RELOC_XTENSA_DIFF32; ++ fixP->fx_signed = 1; + break; + default: + break; +-- +1.8.1.4 +