public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* bfd: patch for missing strtoull
@ 2002-01-04 10:40 Aldy Hernandez
  2002-01-04 10:46 ` Richard Henderson
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Aldy Hernandez @ 2002-01-04 10:40 UTC (permalink / raw)
  To: binutils; +Cc: nickc

hi guys!

MacOS X does not have strtoull so bfd doesn't build.  *sigh*  

here is a patch to add configury magic to check for strtoull, and if not
available, use our own version of strtoull (stolen from newlib).

is this the right approach?

ok to install?

Cheers.
Aldy 

2002-01-04  Aldy Hernandez  <aldyh@redhat.com>

	* libbfd.c (strtoull): New.
	Include ctype.h.
	
	* sysdep.h: Add extern for strtoull.

	* bfd/configure.in: Check for strtoull.
	
	* bfd/configure: Regenerate.

	* bfd/config.in: Regenerate.

	* bfd/acconfig.h: New.

Index: configure.in
===================================================================
RCS file: /cvs/uberbaum/bfd/configure.in,v
retrieving revision 1.77
diff -c -p -r1.77 configure.in
*** configure.in	2002/01/04 14:49:03	1.77
--- configure.in	2002/01/04 18:30:25
*************** AC_HEADER_TIME
*** 141,146 ****
--- 141,148 ----
  AC_HEADER_DIRENT
  AC_CHECK_FUNCS(fcntl getpagesize setitimer sysconf fdopen getuid getgid)
  
+ AC_CHECK_FUNC(strtoull, [AC_DEFINE(HAVE_STRTOULL)], )
+ 
  BFD_BINARY_FOPEN
  
  BFD_NEED_DECLARATION(strstr)
Index: sysdep.h
===================================================================
RCS file: /cvs/uberbaum/bfd/sysdep.h,v
retrieving revision 1.6
diff -c -p -r1.6 sysdep.h
*** sysdep.h	2001/08/19 23:42:47	1.6
--- sysdep.h	2002/01/04 18:30:26
*************** extern void free ();
*** 125,130 ****
--- 125,134 ----
  extern char *getenv ();
  #endif
  
+ #ifndef HAVE_STRTOULL
+ extern unsigned long long strtoull ();
+ #endif
+ 
  /* Define offsetof for those systems which lack it */
  
  #ifndef offsetof
Index: libbfd.c
===================================================================
RCS file: /cvs/uberbaum/bfd/libbfd.c,v
retrieving revision 1.20
diff -c -p -r1.20 libbfd.c
*** libbfd.c	2001/09/21 14:25:09	1.20
--- libbfd.c	2002/01/04 18:30:28
*************** Foundation, Inc., 59 Temple Place - Suit
*** 24,29 ****
--- 24,31 ----
  #include "sysdep.h"
  #include "libbfd.h"
  
+ #include <ctype.h>
+ 
  #ifndef HAVE_GETPAGESIZE
  #define getpagesize() 2048
  #endif
*************** warn_deprecated (what, file, line, func)
*** 1468,1470 ****
--- 1470,1541 ----
        mask |= ~(size_t) func;
      }
  }
+ 
+ #ifndef HAVE_STRTOULL
+ /*
+  * Our own version of strtoull for imbecile systems.
+  *
+  * Convert a string to an unsigned long long integer.
+  *
+  * Ignores `locale' stuff.  Assumes that the upper and lower case
+  * alphabets and digits are each contiguous.
+  */
+ unsigned long long
+ strtoull (nptr, endptr, base)
+      const char *nptr;
+      char **endptr;
+      int base;
+ {
+ 	register const char *s = nptr;
+ 	register unsigned long long acc;
+ 	register int c;
+ 	register unsigned long long cutoff;
+ 	register int neg = 0, any, cutlim;
+ 
+ 	/*
+ 	 * See strtol for comments as to the logic used.
+ 	 */
+ 	do {
+ 		c = *s++;
+ 	} while (isspace(c));
+ 	if (c == '-') {
+ 		neg = 1;
+ 		c = *s++;
+ 	} else if (c == '+')
+ 		c = *s++;
+ 	if ((base == 0 || base == 16) &&
+ 	    c == '0' && (*s == 'x' || *s == 'X')) {
+ 		c = s[1];
+ 		s += 2;
+ 		base = 16;
+ 	}
+ 	if (base == 0)
+ 		base = c == '0' ? 8 : 10;
+ 	cutoff = (unsigned long long)ULONG_LONG_MAX / (unsigned long long)base;
+ 	cutlim = (unsigned long long)ULONG_LONG_MAX % (unsigned long long)base;
+ 	for (acc = 0, any = 0;; c = *s++) {
+ 		if (isdigit(c))
+ 			c -= '0';
+ 		else if (isalpha(c))
+ 			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+ 		else
+ 			break;
+ 		if (c >= base)
+ 			break;
+                if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+ 			any = -1;
+ 		else {
+ 			any = 1;
+ 			acc *= base;
+ 			acc += c;
+ 		}
+ 	}
+ 	if (any < 0) {
+ 		acc = ULONG_LONG_MAX;
+ 	} else if (neg)
+ 		acc = -acc;
+ 	if (endptr != 0)
+ 		*endptr = (char *) (any ? s - 1 : nptr);
+ 	return (acc);
+ }
+ #endif

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bfd: patch for missing strtoull
  2002-01-04 10:40 bfd: patch for missing strtoull Aldy Hernandez
@ 2002-01-04 10:46 ` Richard Henderson
  2002-01-04 10:47 ` Ian Lance Taylor
  2002-01-04 10:54 ` Andreas Schwab
  2 siblings, 0 replies; 10+ messages in thread
From: Richard Henderson @ 2002-01-04 10:46 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: binutils, nickc

On Fri, Jan 04, 2002 at 10:39:59AM -0800, Aldy Hernandez wrote:
> is this the right approach?

Should go in libiberty instead.


r~

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bfd: patch for missing strtoull
  2002-01-04 10:40 bfd: patch for missing strtoull Aldy Hernandez
  2002-01-04 10:46 ` Richard Henderson
@ 2002-01-04 10:47 ` Ian Lance Taylor
  2002-01-04 10:48   ` Ian Lance Taylor
                     ` (3 more replies)
  2002-01-04 10:54 ` Andreas Schwab
  2 siblings, 4 replies; 10+ messages in thread
From: Ian Lance Taylor @ 2002-01-04 10:47 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: binutils, nickc

Aldy Hernandez <aldyh@redhat.com> writes:

> hi guys!
> 
> MacOS X does not have strtoull so bfd doesn't build.  *sigh*  
> 
> here is a patch to add configury magic to check for strtoull, and if not
> available, use our own version of strtoull (stolen from newlib).
> 
> is this the right approach?

No.  The right approach is to add strtoull to newlib.  (As far as I
can see, newlib has strtoul, but not strtoull.)

Or perhaps the code which uses strtoull should use bfd_scan_vma
instead.  The value appears to being stored in a bfd_vma, not in a
long long.

Ian

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bfd: patch for missing strtoull
  2002-01-04 10:47 ` Ian Lance Taylor
@ 2002-01-04 10:48   ` Ian Lance Taylor
  2002-01-04 12:44   ` Aldy Hernandez
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Ian Lance Taylor @ 2002-01-04 10:48 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: binutils, nickc

Ian Lance Taylor <ian@airs.com> writes:

> No.  The right approach is to add strtoull to newlib.  (As far as I
> can see, newlib has strtoul, but not strtoull.)

Gahh, I mean libiberty, not newlib.  Sorry.

Ian

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bfd: patch for missing strtoull
  2002-01-04 10:40 bfd: patch for missing strtoull Aldy Hernandez
  2002-01-04 10:46 ` Richard Henderson
  2002-01-04 10:47 ` Ian Lance Taylor
@ 2002-01-04 10:54 ` Andreas Schwab
  2 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2002-01-04 10:54 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: binutils, nickc

Aldy Hernandez <aldyh@redhat.com> writes:

|> Index: configure.in
|> ===================================================================
|> RCS file: /cvs/uberbaum/bfd/configure.in,v
|> retrieving revision 1.77
|> diff -c -p -r1.77 configure.in
|> *** configure.in	2002/01/04 14:49:03	1.77
|> --- configure.in	2002/01/04 18:30:25
|> *************** AC_HEADER_TIME
|> *** 141,146 ****
|> --- 141,148 ----
|>   AC_HEADER_DIRENT
|>   AC_CHECK_FUNCS(fcntl getpagesize setitimer sysconf fdopen getuid getgid)
|>   
|> + AC_CHECK_FUNC(strtoull, [AC_DEFINE(HAVE_STRTOULL)], )
|> + 

IMHO that should be AC_CHECK_FUNCS(strtoull), or extend the list above.

Andreas.

-- 
Andreas Schwab                                  "And now for something
Andreas.Schwab@suse.de				completely different."
SuSE Labs, SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bfd: patch for missing strtoull
  2002-01-04 12:44   ` Aldy Hernandez
@ 2002-01-04 12:44     ` Ian Lance Taylor
  0 siblings, 0 replies; 10+ messages in thread
From: Ian Lance Taylor @ 2002-01-04 12:44 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: binutils, nickc

Aldy Hernandez <aldyh@redhat.com> writes:

> On Fri, Jan 04, 2002 at 10:47:18AM -0800, Ian Lance Taylor wrote:
> 
> > No.  The right approach is to add strtoull to newlib.  (As far as I
> > can see, newlib has strtoul, but not strtoull.)
> 
> it seems it's already in there:
> 
> culebra:/source/uber/devo/newlib/libc/stdlib$ ls strtoull*.c
> strtoull.c  strtoull_r.c
> 
> i wonder why it's not getting linked...

I meant libiberty.  Sorry.

> > Or perhaps the code which uses strtoull should use bfd_scan_vma
> > instead.  The value appears to being stored in a bfd_vma, not in a
> > long long.
> 
> hmm, i don't know much about this bfd stuff.  the code is here (bfd/coff-rs6000.c)
> and it's the only place where strtoull is used in bfd, so an approach without
> strtoull would be better:
> 
> 	#define READ20(d, v) \
> 	  buff20[20] = 0, \
> 	  memcpy (buff20, (d), 20), \
> -->	  (v) = strtoull (buff20, (char **) NULL, 10)
> 
> 	static boolean
> 	xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
> 	...
> 	...
> 	  /* xcoff_write_archive_contents_big passes nextoff in symoff. */
> -->	  READ20 (fhdr->memoff, prevoff);
> -->	  READ20 (fhdr->symoff, nextoff);
> 
> do you suggest another approach?

Yes, change strtoull to bfd_scan_vma, if that's OK with Tom Rix.
While you're at it, eliminate the ``long long'' from PRINT20, and use
bfd_print_vma.  As far as I can tell from looking at the code for 20
seconds, that will always work.  I think the existing code is making
some unportable assumptions which are not appropriate for BFD.

Ian

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bfd: patch for missing strtoull
  2002-01-04 10:47 ` Ian Lance Taylor
  2002-01-04 10:48   ` Ian Lance Taylor
@ 2002-01-04 12:44   ` Aldy Hernandez
  2002-01-04 12:44     ` Ian Lance Taylor
  2002-01-04 13:48   ` Aldy Hernandez
  2002-01-05  5:08   ` Aldy Hernandez
  3 siblings, 1 reply; 10+ messages in thread
From: Aldy Hernandez @ 2002-01-04 12:44 UTC (permalink / raw)
  To: binutils, nickc

On Fri, Jan 04, 2002 at 10:47:18AM -0800, Ian Lance Taylor wrote:

> No.  The right approach is to add strtoull to newlib.  (As far as I
> can see, newlib has strtoul, but not strtoull.)

it seems it's already in there:

culebra:/source/uber/devo/newlib/libc/stdlib$ ls strtoull*.c
strtoull.c  strtoull_r.c

i wonder why it's not getting linked...

> Or perhaps the code which uses strtoull should use bfd_scan_vma
> instead.  The value appears to being stored in a bfd_vma, not in a
> long long.

hmm, i don't know much about this bfd stuff.  the code is here (bfd/coff-rs6000.c)
and it's the only place where strtoull is used in bfd, so an approach without
strtoull would be better:

	#define READ20(d, v) \
	  buff20[20] = 0, \
	  memcpy (buff20, (d), 20), \
-->	  (v) = strtoull (buff20, (char **) NULL, 10)

	static boolean
	xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
	...
	...
	  /* xcoff_write_archive_contents_big passes nextoff in symoff. */
-->	  READ20 (fhdr->memoff, prevoff);
-->	  READ20 (fhdr->symoff, nextoff);

do you suggest another approach?

aldy

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bfd: patch for missing strtoull
  2002-01-04 10:47 ` Ian Lance Taylor
  2002-01-04 10:48   ` Ian Lance Taylor
  2002-01-04 12:44   ` Aldy Hernandez
@ 2002-01-04 13:48   ` Aldy Hernandez
  2002-01-05  5:08   ` Aldy Hernandez
  3 siblings, 0 replies; 10+ messages in thread
From: Aldy Hernandez @ 2002-01-04 13:48 UTC (permalink / raw)
  To: binutils, nickc

> No.  The right approach is to add strtoull to newlib.  (As far as I
> can see, newlib has strtoul, but not strtoull.)

did you mean libiberty like rth mentioned or newlib?  because newlib already
has strtoull

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bfd: patch for missing strtoull
  2002-01-04 10:47 ` Ian Lance Taylor
                     ` (2 preceding siblings ...)
  2002-01-04 13:48   ` Aldy Hernandez
@ 2002-01-05  5:08   ` Aldy Hernandez
  2002-01-07 16:28     ` Alan Modra
  3 siblings, 1 reply; 10+ messages in thread
From: Aldy Hernandez @ 2002-01-05  5:08 UTC (permalink / raw)
  To: binutils

> 
> Or perhaps the code which uses strtoull should use bfd_scan_vma
> instead.  The value appears to being stored in a bfd_vma, not in a
> long long.

right... here's a patch that fixes my problem.

sigh... bootstraphood again.

ok?

2002-01-04  Aldy Hernandez  <aldyh@redhat.com>

        * bfd/coff-rs6000.c (READ20): Use bfd_scan_vma.

Index: coff-rs6000.c
===================================================================
RCS file: /cvs/uberbaum/bfd/coff-rs6000.c,v
retrieving revision 1.28
diff -c -p -r1.28 coff-rs6000.c
*** coff-rs6000.c	2001/12/31 04:08:23	1.28
--- coff-rs6000.c	2002/01/04 22:17:48
*************** static char buff20[XCOFFARMAGBIG_ELEMENT
*** 1555,1561 ****
  #define READ20(d, v) \
    buff20[20] = 0, \
    memcpy (buff20, (d), 20), \
!   (v) = strtoull (buff20, (char **) NULL, 10)
  
  static boolean
  xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
--- 1555,1561 ----
  #define READ20(d, v) \
    buff20[20] = 0, \
    memcpy (buff20, (d), 20), \
!   (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
  
  static boolean
  xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: bfd: patch for missing strtoull
  2002-01-05  5:08   ` Aldy Hernandez
@ 2002-01-07 16:28     ` Alan Modra
  0 siblings, 0 replies; 10+ messages in thread
From: Alan Modra @ 2002-01-07 16:28 UTC (permalink / raw)
  To: Aldy Hernandez; +Cc: binutils

On Fri, Jan 04, 2002 at 10:38:34PM -0800, Aldy Hernandez wrote:
>         * bfd/coff-rs6000.c (READ20): Use bfd_scan_vma.

OK.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2002-01-08  0:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-04 10:40 bfd: patch for missing strtoull Aldy Hernandez
2002-01-04 10:46 ` Richard Henderson
2002-01-04 10:47 ` Ian Lance Taylor
2002-01-04 10:48   ` Ian Lance Taylor
2002-01-04 12:44   ` Aldy Hernandez
2002-01-04 12:44     ` Ian Lance Taylor
2002-01-04 13:48   ` Aldy Hernandez
2002-01-05  5:08   ` Aldy Hernandez
2002-01-07 16:28     ` Alan Modra
2002-01-04 10:54 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).