Bug 19222 - Undefined behavoour in tc-arm.c:encode_arm_immediate with Xcode 7.1
Summary: Undefined behavoour in tc-arm.c:encode_arm_immediate with Xcode 7.1
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.25
: P2 normal
Target Milestone: 2.26
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-10 01:21 UTC by Chris Johns
Modified: 2015-11-10 08:49 UTC (History)
1 user (show)

See Also:
Host: OS X
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Johns 2015-11-10 01:21:38 UTC
The function 'encode_arm_immediate' in tc-arm.c does not compile RTEMS 4.11 ARM GCC on OS X. The error reported is:

../../../../gcc-4.9.3/libgcc/config/arm/ieee754-df.S: Assembler messages:
../../../../gcc-4.9.3/libgcc/config/arm/ieee754-df.S:567: Error: invalid constant (ff) after fixup
../../../../gcc-4.9.3/libgcc/config/arm/ieee754-df.S:673: Error: invalid constant (ff) after fixup
../../../../gcc-4.9.3/libgcc/config/arm/ieee754-df.S:689: Error: invalid constant (fd) after fixup
../../../../gcc-4.9.3/libgcc/config/arm/ieee754-df.S:875: Error: invalid constant (ff) after fixup
../../../../gcc-4.9.3/libgcc/config/arm/ieee754-df.S:912: Error: invalid constant (fd) after fixup
../../../../gcc-4.9.3/libgcc/config/arm/ieee754-df.S:985: Error: invalid constant (fd) after fixup

The error has been reported to Apple and they have have said the error is due to undefined behaviour in the function. A possible solution is:

@@ -9,7 +9,7 @@ encode_arm_immediate (unsigned int val)
   printf("val = %08x\n", val);
 
   for (i = 0; i < 32; i += 2)
-    if ((a = (val << i | val >> (32 - i))) <= 0xff)
+    if ((a = (val << i | (i == 0 ? 0:val >> (32 - i)))) <= 0xff)
       return a | (i << 7);
 
   return (-1);
Comment 1 Andreas Schwab 2015-11-10 08:49:07 UTC
Fixed by d840c08.

2014-11-20  Richard Earnshaw  <rearnsha@arm.com>

	* config/tc-arm.c (rotate_left): Avoid undefined behaviour when
	N = 0.