Skip to contentSkip to conversation

ARC: gcc - fixes for improperly calculated jump/branch offsets

PATCH New Alexey Brodkin 2 participants 3 messages Oct 8, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARC: gcc - fixes for improperly calculated jump/branch offsets

Symptoms usually seen are like that:
--->---
Error: operand out of range (128 is not between -128 and 127) --->---
where range may differ.

Since compiler tries to use jump/branch instructions with the shortes encoding of offset it's important to calculate required offset properly.

In case of miscalculation by compiler later assembler throws an error because of inability to encode requested value.

Fixes are taken from current development branch of GCC for ARC and will be a part of the next release of ARC tools, so at that point patch should be dropped.

Cc Anton Kolesov <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Peter Korsgaard <[email protected]>
---
 ...-call-arc_hazard-before-branch-shortening.patch | 96 ++++++++++++++++++++++
 ...-length-attribute-for-casesi_load-pattern.patch | 44 ++++++++++
 ...-in-delay-slot-and-needs-to-be-predicated.patch | 69 ++++++++++++++++
 ...te-casesi_compact_jump-instruction-length.patch | 31 +++++++
 4 files changed, 240 insertions(+)
 create mode 100644 package/gcc/arc-2014.08/400-call-arc_hazard-before-branch-shortening.patch
 create mode 100644 package/gcc/arc-2014.08/401-fix-length-attribute-for-casesi_load-pattern.patch
 create mode 100644 package/gcc/arc-2014.08/402-fix-length-of-instructions-that-are-in-delay-slot-and-needs-to-be-predicated.patch
 create mode 100644 package/gcc/arc-2014.08/403-update-casesi_compact_jump-instruction-length.patch
package/gcc/arc-2014.08/400-call-arc_hazard-before-branch-shortening.patch new file +96 -0
new file mode 100644
index 0000000..7361e6b
@@ -0,0 +1,96 @@
+Call arc_hazard before branch shortening
+
+On attempt to compile busybox (1.22.1) from buildroot master following build
+error happened:
+--->---
+$ arc-linux-gcc -Iinclude -Ilibbb  -include include/autoconf.h -D_FILE_OFFSET_BITS=64 -fstack-protector-all -fno-guess-branch-probability -Os -c -o libbb/xfuncs.o libbb/xfuncs.c
+xfuncs.s: Assembler messages:
+xfuncs.s:444: Error: operand out of range (128 is not between -128 and 127)
+--->---
+
+Fix is taken from current development branch of GCC for ARC and will be a
+part of the next release of ARC tools, so at that point patch should be dropped.
+
+https://github.com/foss-for-synopsys-dwc-arc-processors/gcc/commit/37ba2006be0b8c629d2f8ba6c5ec2819bd0269e5
+
+Signed-off-by: Claudiu Zissulescu <[email protected]>
+---
+
+diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
+index 7d64f69..30baae1 100644
+--- a/gcc/config/arc/arc.c
++++ b/gcc/config/arc/arc.c
+@@ -6520,6 +6520,16 @@ workaround_arc_anomaly (void)
+ {
+   rtx insn, succ0, succ1;
+ 
++  /* For any architecture: call arc_hazard here. */
++  for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
++    {
++      succ0 = next_real_insn(insn);
++      if (arc_hazard (insn, succ0))
++	{
++	  emit_insn_before (gen_nopv (), succ0);
++	}
++    }
++
+   if (!TARGET_ARC700)
+     return;
+ 
+@@ -8710,7 +8720,7 @@ arc_loop_hazard (rtx pred, rtx succ)
+ 	succ_bb = BLOCK_FOR_INSN (NEXT_INSN (label));
+     }
+ 
+-  if (succ_bb && REGNO_REG_SET_P (df_get_live_in (succ_bb), LP_COUNT))
++  if (succ_bb && REGNO_REG_SET_P (df_get_live_out (succ_bb), LP_COUNT))
+     return true;
+ 
+   return false;
+diff --git a/gcc/testsuite/gcc.target/arc/pr9000798619.c b/gcc/testsuite/gcc.target/arc/pr9000798619.c
+new file mode 100644
+index 0000000..b08b32d
+--- /dev/null
++++ b/gcc/testsuite/gcc.target/arc/pr9000798619.c
+@@ -0,0 +1,42 @@
++/* { dg-do assemble } */
++/* { dg-options "-Os -fstack-protector-all -fno-guess-branch-probability" } */
++/* The arc_hazard introduces a NOP which is not taken into account by
++   branch shortening step, resulting in an out of range branch
++   offset (ARC700 architecture). */
++
++typedef unsigned char uint8_t;
++extern int *const bb_errno;
++
++char* hex2bin(char *dst, const char *str, int count)
++{
++ (*bb_errno) = 22;
++ while (*str && count) {
++  uint8_t val;
++  uint8_t c = *str++;
++  if (((unsigned char)((c) - '0') <= 9))
++   val = c - '0';
++  else if ((c|0x20) >= 'a' && (c|0x20) <= 'f')
++   val = (c|0x20) - ('a' - 10);
++  else
++   return ((void *)0);
++  val <<= 4;
++  c = *str;
++  if (((unsigned char)((c) - '0') <= 9))
++   val |= c - '0';
++  else if ((c|0x20) >= 'a' && (c|0x20) <= 'f')
++   val |= (c|0x20) - ('a' - 10);
++  else if (c == ':' || c == '\0')
++   val >>= 4;
++  else
++   return ((void *)0);
++
++  *dst++ = val;
++  if (c != '\0')
++   str++;
++  if (*str == ':')
++   str++;
++  count--;
++ }
++ (*bb_errno) = (*str ? 34 : 0);
++ return dst;
++}
package/gcc/arc-2014.08/401-fix-length-attribute-for-casesi_load-pattern.patch new file +44 -0

44 lines not on this page · raw message

package/gcc/arc-2014.08/402-fix-length-of-instructions-that-are-in-delay-slot-and-needs-to-be-predicated.patch new file +69 -0

69 lines not on this page · raw message

package/gcc/arc-2014.08/403-update-casesi_compact_jump-instruction-length.patch new file +31 -0
new file mode 100644
index 0000000..dd188a4
@@ -0,0 +1,31 @@
+Update casesi_compact_jump instruction length
+
+Fixes autobuilder issue http://autobuild.buildroot.net/results/bc5/bc5100d6462af4e2805f2bc8d39c87a55d843e2b/
+
+--->---
+$ arc-linux-gcc -c -o wps_attr_parse.o -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os  -I.../host/usr/arc-buildroot-linux-uclibc/sysroot/usr/include/libnl3/ -I.../build/hostapd-2.2/src -I.../build/hostapd-2.2/src/utils wps_attr_parse.c
+wps_attr_parse.s: Assembler messages:
+wps_attr_parse.s:860: Error: operand out of range (512 is not between -512 and 511)
+--->---
+
+Fix is taken from current development branch of GCC for ARC and will be a
+part of the next release of ARC tools, so at that point patch should be dropped.
+
+https://github.com/foss-for-synopsys-dwc-arc-processors/gcc/commit/8e704c43cb50407ec79795f6f7459f09800b9f01
+
+Signed-off-by: Claudiu Zissulescu <[email protected]>
+---
+ 
+diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
+index 88b2e37..8e18703 100644
+--- a/gcc/config/arc/arc.md
++++ b/gcc/config/arc/arc.md
+@@ -3948,7 +3948,7 @@
+   output_asm_insn (s, xop);
+   return \"add_s %2,%2,pcl\n\tj_s%* [%2]\";
+ }"
+-  [(set_attr "length" "10")
++  [(set_attr "length" "12")
+    (set_attr "type" "jump")
+    (set_attr "iscompact" "true")
+    (set_attr "cond" "nocond")])
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/1 ARC: gcc - fixes for improperly calculated jump/branch offsets

Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Alexey" == Alexey Brodkin <[email protected]> writes:

Symptoms usually seen are like that:

---> ---

Quoted 1 line

Error: operand out of range (128 is not between -128 and 127)

---> ---

Quoted 8 lines

where range may differ.

Since compiler tries to use jump/branch instructions with the shortes encoding of offset it's important to calculate required offset properly.

In case of miscalculation by compiler later assembler throws an error because of inability to encode requested value.

Quoted 7 lines

Fixes are taken from current development branch of GCC for ARC and will be a part of the next release of ARC tools, so at that point patch should be dropped.

Cc Anton Kolesov <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Peter Korsgaard <[email protected]>

This presumably fixes the recent autobuild issues?

Committed, thanks.

Signature · 2 lines
Venlig hilsen,
Peter Korsgaard 
#2 lore raw

PATCH 1/1 ARC: gcc - fixes for improperly calculated jump/branch offsets

Hi Peter,

Quoted 17 lines · Peter Korsgaard
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Alexey" == Alexey Brodkin <[email protected]> writes:

Symptoms usually seen are like that:

---> ---

Quoted 1 line

Error: operand out of range (128 is not between -128 and 127)

---> ---

Quoted 10 lines

where range may differ.

Since compiler tries to use jump/branch instructions with the shortes encoding of offset it's important to calculate required offset properly.

In case of miscalculation by compiler later assembler throws an error because of inability to encode requested value.

Fixes are taken from current development branch of GCC for ARC and will be a part of the next release of ARC tools, so at that point patch should be dropped.

Quoted 6 lines
Quoted 4 lines
Cc Anton Kolesov <[email protected]>
Cc Thomas Petazzoni <[email protected]>
Cc Peter Korsgaard <[email protected]>

This presumably fixes the recent autobuild issues?

At least the one reported against "hostapd" here.

Quoted 1 line
Quoted 1 line

arc | hostapd-2.2 | NOK |

http://autobuild.buildroot.net/results/bc5100d6462af4e2805f2bc8d39c87a55d843e2b/

Quoted 3 lines

{standard input}: Assembler messages:
{standard input}:863: Error: operand out of range (512 is not between

-512 and 511)

Quoted 2 lines

make[1]: *** [../src/wps/wps_attr_parse.o] Error 1 make[1]: *** Waiting for unfinished jobs....

This should be now solved.

-Alexey