This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Fix K&R problem in align_power macro
- From: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- To: binutils at sources dot redhat dot com
- Date: Thu, 29 Aug 2002 16:25:47 -0400 (EDT)
- Subject: Fix K&R problem in align_power macro
The enclosed patch fixes a promotion problem in the align_power macro.
When expanded by a K&R compiler, ints are not sign extended to unsigned
long. This affects the hppa64-hp-hpux11 port where ints are 4 bytes
and longs are 8 bytes. The constant "-1" is treated as an int before
the shift and the result is not sign extended. The problem can be
avoided by explicitly casting the constants to bfd_vma type.
I also removed one extraneous set of parentheses to make the result more
readable.
Tested with builds and checks on hppa64-hp-hpux11 and hppa2.0w-hp-hpux
using both gcc and "cc -Ac". A bootstrap of gcc 3.2 on hppa64-hp-hpux11*
using binutils built with "cc -Ac" has successfully completed. So,
now it is possible to build a working binutils and gcc 3.2 starting
with the HP bundled compiler.
OK?
Dave
--
J. David Anglin dave.anglin@nrc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6605)
2002-08-29 John David Anglin <dave@hiauly1.hia.nrc.ca>
* bfd-in.h (align_power): Cast constants to bfd_vma type.
* bfd-in2.h (align_power): Likewise.
Index: bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.49
diff -u -3 -p -r1.49 bfd-in.h
--- bfd-in.h 28 Aug 2002 10:38:44 -0000 1.49
+++ bfd-in.h 29 Aug 2002 16:41:23 -0000
@@ -331,7 +331,7 @@ alent;
/* Object and core file sections. */
#define align_power(addr, align) \
- ( ((addr) + ((1<<(align))-1)) & (-1 << (align)))
+ (((addr) + ((bfd_vma) 1 << (align)) - 1) & ((bfd_vma) -1 << (align)))
typedef struct sec *sec_ptr;
Index: bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.167
diff -u -3 -p -r1.167 bfd-in2.h
--- bfd-in2.h 28 Aug 2002 10:38:44 -0000 1.167
+++ bfd-in2.h 29 Aug 2002 16:41:26 -0000
@@ -337,7 +337,7 @@ alent;
/* Object and core file sections. */
#define align_power(addr, align) \
- ( ((addr) + ((1<<(align))-1)) & (-1 << (align)))
+ (((addr) + ((bfd_vma) 1 << (align)) - 1) & ((bfd_vma) -1 << (align)))
typedef struct sec *sec_ptr;