This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 64-bit obstack support


64-bit obstack support, >2G obstacks

An update, importing a newer version of glibc's obstack support (with
new bugs, use of glibc macros, fixed).  Plus fix some thinkos in my
first patch, like including config.h in obstack.h.  And gcc tweaks.

- Get rid of "int" and "long" size parameters and vars in obstacks.
  If we want to keep compatibility with OBSTACK_INTERFACE_VERSION==1
  obstack struct and functions, we can make them "unsigned int" and
  "unsigned long" allowing larger than 2G obstacks even on 32-bit
  hosts.  For 64-bit hosts OBSTACK_INTERFACE_VERSION==2 we make them
  all "size_t".
- Using "long" as obstack_chunk_alloc function parameter type is
  simply a bug, since malloc etc. always take a size_t, and long might
  be smaller than size_t.  (long is 32-bit on Microsoft 64-bit.)
- Use obstack_room throughout whenever checking space left in obstacks
  (next_free + desired > chunk_limit may wrap the lhs for chunks
  allocated near the top of memory).  To support >2G on 32-bit, temp.i
  needs to be unsigned, so size_t rather than ptrdiff_t.
- Steal lots of fixes from glibc by importing glibc's obstack.{h,c}
  and fix recent regressions.
- Don't roll our own slow memcpy in _obstack_newchunk.
- Rename obstack_free to _obstack_free for consistency with other
  obstack.c functions.
- Move OBSTACK_INTERFACE_VERSION to obstack.h, in order to make it
  possible to force compilation of version 1 obstack, with a nod
  toward glibc being able to compile obstack.c twice.

Since I imported obstack.h and obtack.c from glibc, the changelog
shows deltas from glibc versions, and the diff for obstack.h and
obstack.c is against glibc and made with -uw to better see the real
changes.

I removed the use of gettext.h and exitfail.h in obstack.c.  We
don't have those files in binutils/gdb/gcc and it hardly seems worth
importing them from gnulib.

Outside of obstack.{h,c} the changes are relatively minor, and can be
applied before the obstack patches.  My plan of attach is to get those
patches, minus the configury changes, applied first.  So I'd like
permission to apply the gdb and gcc changes now.  They have been
tested independently of the obstack changes.  Next, apply the obstack
changes to binutils/gdb/gcc, and finally backport to glibc.

I'm ambivalent over whether the configury changes are really
desirable.  Their aim is to allow the new obstack.h to be used with
current glibc when sizeof(size_t)==sizeof(int), ie. on most 32-bit
targets.  Under those conditions the obstack ABI is unchanged so it is
possible to save some code space by using glibc's _obstack_begin,
_obstack_newchunk etc., at the cost of losing >2G obstacks.  Now it's
a brave person who would want >2G obstacks on a 32-bit host so you
don't lose much.  However, the configury changes are an added
complication that I haven't yet tested for cross-compilation, and only
help in the transition period until glibc is released with >2G obstack
support.

include/
	PR gdb/17133
	* obstack.h: Import current glibc file.  On top of that..
	Formatting.
	(__OBSTACK_INTERFACE_VERSION): Define.
	(__OBSTACK_ELIDE_CODE): Define.
	(__OBSTACK_SIZE_T, __CHUNK_SIZE_T): Define.
	(__PTR_INT_TYPE): Rename from PTR_INT_TYPE.
	(__attribute_pure__): Define without reference to glibc macro.
	(__extension__): Avoid warning when __GNUC_MINOR__ undefined.
	(struct obstack): Make chunk_size a __CHUNK_SIZE_T, and temp union
	with __OBSTACK_SIZE_T.  Correct chunkfun prototype to take a size_t.
	(_obstack_newchunk): Update prototype.
	(_obstack_begin, _obstack_begin_1, _obstack_memory_used): Likewise.
	(__obstack_free): Define as _obstack_free.
	(obstack_init, obstack_begin, obstack_specify_allocation_with_arg,
	obstack_chunkfun): Update alloc function casts, formatting.
	For __STDC__ versions of the following macros:
	(obstack_object_size): Return __OBSTACK_SIZE_T.
	(obstack_room): Likewise, and rename __o.
	(obstack_make_room): Make __len __OBSTACK_SIZE_T, and use obstack_room.
	(obstack_grow, obstack_grow0, obstack_1grow, obstack_ptr_grow,
	obstack_int_grow, obstack_blank): Likewise.
	(obstack_finish): Use unsigned comparision when comparing aligned
	next_free against chunk_limit.
	(obstack_free): Cast OBJ to remove possible const qualifier.
	Don't wrap __obstack_free in parentheses.
	For !__STDC__ versions of the following macros:
	(obstack_object_size, obstack_room): Return __OBSTACK_SIZE_T.
	(obstack_make_room): Use temp.i and obstack_room.
	(obstack_grow, obstack_grow0, obstack_1grow, obstack_ptr_grow,
	obstack_int_grow, obstack_blank): Likewise.
	(obstack_finish): Use temp.p.  Use unsigned comparision when
	comparing aligned next_free against chunk_limit.
	(obstack_free): Use temp.p and same comparisons as __STDC__ version.
	Don't wrap __obstack_free in parentheses.
libiberty/
	PR gdb/17133
	* obstack.c: Import current glibc file.  On top of that..
	Include gnu-versions.h.  Don't include exitfail.h and gettext.h.
	(OBSTACK_INTERFACE_VERSION): Delete.
	(ELIDE_CODE): Delete.  Test __OBSTACK_ELIDE_CODE instead.
	(COPYING_UNIT): Delete.
	(print_and_abort, obstack_alloc_failed_handler): Conditionally define.
	(_obstack_compat): Likewise.
	(_Noreturn): Don't rely on this being defined, define ..
	(__attribute_noreturn__): ..and use this instead.
	(EXIT_FAILURE): Define.
	(CALL_CHUNKFUN): Update chunkfun cast.
	(chunkfun_t, freefun_t): New typdefs.
	(_obstack_begin_worker): Split out from ..
	(_obstack_begin, _obstack_begin_1): ..here.  Make "size" param
	 __CHUNK_SIZE_T, and correct chunkfun prototype.
	(_obstack_newchunk): Make "length" param __OBSTACK_SIZE_T and local
	vars size_t.  Use memcpy to move existing object.
	(obstack_free): Only define alias for version 1 interface.
	(_obstack_memory_used): Return and use __OBSTACK_SIZE_T local.
	* obstacks.texi: Update function signatures.
	* configure.ac: Get size of size_t.
	* config.in: Regenerate.
	* configure: Regenerate.
binutils/
	* configure.ac: Get size of int and size_t.
	* config.in: Regenerate.
	* configure: Regenerate.
gas/
	* config/bfin-parse.y: Don't include obstack.h.
	* config/obj-aout.c: Likewise.
	* config/obj-coff.c: Likewise.
	* config/obj-som.c: Likewise.
	* config/tc-bfin.c: Likewise.
	* config/tc-i960.c: Likewise.
	* config/tc-rl78.c: Likewise.
	* config/tc-rx.c: Likewise.
	* config/tc-tic4x.c: Likewise.
	* expr.c: Likewise.
	* listing.c: Likewise.
	* config/obj-elf.c (elf_file_symbol): Make name_length a size_t.
	* config/tc-aarch64.c (symbol_locate): Likewise.
	* config/tc-arm.c (symbol_locate): Likewise.
	* config/tc-mmix.c (mmix_handle_mmixal): Make len_0 a size_t.
	* config/tc-score.c (s3_build_score_ops_hsh): Make len a size_t.
	(s3_build_dependency_insn_hsh): Likewise.
	* config/tc-score7.c (s7_build_score_ops_hsh): Likewise.
	(s7_build_dependency_insn_hsh): Likewise.
	* frags.c (frag_grow): Make parameter a size_t, and use size_t locals.
	(frag_new): Make parameter a size_t.
	(frag_var_init): Make max_chars and var parameters size_t.
	(frag_var, frag_variant): Likewise.
	(frag_room): Return a size_t.
	(frag_align_pattern): Make n_fill parameter a size_t.
	* frags.h: Update function prototypes.
	* symbols.c (save_symbol_name): Make name_length a size_t.
	* configure.ac: Get size of int and size_t.
	* config.in: Regenerate.
	* configure: Regenerate.
gdb/
	* charset.c (convert_between_encodings): Cast result of obstack_base.
	* cp-valprint.c (cp_print_value_fields): Use size_t locals.
	* hppa-tdep.c (internalize_unwinds): Change "size" parm to size_t.
	(read_unwind_info): Use size_t for some locals.
	* jit.c (finalize_symtab): Likewise.
	* utils.c (hashtab_obstack_allocate): Likewise.
	* symmisc.c (print_objfile_statistics): Update format strings.
	* configure.ac: Get size of int and size_t.
	* config.in: Regenerate.
	* configure: Regenerate.
ld/
	* configure.ac: Get size of int and size_t.
	* config.in: Regenerate.
	* configure: Regenerate.
gcc/
	* gengtype.h (obstack_chunk_alloc, obstack_chunk_free): Remove cast.
	* coretypes.h (obstack_chunk_alloc, obstack_chunk_free): Likewise.
	(gcc_obstack_init): Use obstack_specify_allocation in place of
	_obstack_begin.
	* genautomata.c (next_sep_el): Cast result of obstack_base to (char *).
	(regexp_representation): Likewise.
	* godump.c (go_output_type): Likewise.
	* configure.ac: Check size of size_t.
	* configure: Regenerate.
	* config.in: Regenerate.
gcc/java/
	* mangle.c (finish_mangling): Cast result of obstack_base to (char *).
	* typeck.c (build_java_argument_signature): Likewise.
	(build_java_signature): Likewise.
gcc/objc/
	* objc-encoding.c (encode_array): Cast result of obstack_base.
	(encode_type): Likewise.
libcpp/
	* symtab.c (ht_create): Use obstack_specify_allocation in place of
	_obstack_begin.
	* files.c (_cpp_init_files): Likewise.
	* init.c (cpp_create_reader): Likewise.
	* identifiers.c (_cpp_init_hashtable): Likewise.
	* configure.ac: Check size of size_t.
	* configure: Regenerate.
	* config.in: Regenerate.
libvtv/
	* vtv-malloc.c: Include config.h.
	* configure.ac: Generate config.h.  Check size of int and size_t.
	* configure: Regenerate.
	* config.in: Generate.
libsanitizer/
	* configure.ac: Check size of int and size_t.
	* configure: Regenerate.
	* config.in: Regenerate.

-- 
Alan Modra
Australia Development Lab, IBM
--- glibc-current/malloc/obstack.h	2014-07-12 13:18:12.805934386 +0930
+++ binutils-gdb/include/obstack.h	2014-07-13 19:52:15.560418673 +0930
@@ -104,16 +104,62 @@
 #ifndef _OBSTACK_H
 #define _OBSTACK_H 1
 
+#ifndef __OBSTACK_INTERFACE_VERSION
+# define __OBSTACK_INTERFACE_VERSION 2
+#endif
+
+/* Comment out all the obstack.c code if we are using the GNU C
+   Library, and are not actually compiling the library itself, and the
+   installed library supports the same library interface we do.  This
+   code is part of the GNU C Library, but also included in many other
+   GNU distributions.  Compiling and linking in obstack.c code is a
+   waste when using the GNU C library (especially if it is a shared
+   library).  Rather than having every GNU program understand
+   'configure --with-gnu-libc' and omit the object files, it is
+   simpler to just do this in the source for each such file.  */
+
+#include <stdio.h>		/* Random thing to get __GNU_LIBRARY__.  */
+#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
+# include <gnu-versions.h>
+# if (_GNU_OBSTACK_INTERFACE_VERSION == __OBSTACK_INTERFACE_VERSION	\
+      || (_GNU_OBSTACK_INTERFACE_VERSION == 1				\
+	  && __OBSTACK_INTERFACE_VERSION >= 2				\
+	  && defined SIZEOF_INT && defined SIZEOF_SIZE_T		\
+	  && SIZEOF_INT == SIZEOF_SIZE_T))
+#  define __OBSTACK_ELIDE_CODE
+# endif
+#endif
+
+#if __OBSTACK_INTERFACE_VERSION == 1
+# define __OBSTACK_SIZE_T unsigned int
+# define __CHUNK_SIZE_T unsigned long
+#else
+# define __OBSTACK_SIZE_T size_t
+# define __CHUNK_SIZE_T size_t
+
+/* The version 2 functions in obstack.c are renamed so old shared
+   libraries that want version 1 code won't accidentally be linked
+   against functions with an incompatible ABI.  */
+# if !defined __OBSTACK_ELIDE_CODE || _GNU_OBSTACK_INTERFACE_VERSION >= 2
+#  define _obstack_allocated_p	_obstack2_allocated_p
+#  define _obstack_begin	_obstack2_begin
+#  define _obstack_begin_1	_obstack2_begin_1
+#  define _obstack_free		_obstack2_free
+#  define _obstack_memory_used	_obstack2_memory_used
+#  define _obstack_newchunk	_obstack2_newchunk
+# endif
+#endif
+
 /* We need the type of a pointer subtraction.  If __PTRDIFF_TYPE__ is
    defined, as with GNU C, use that; that way we don't pollute the
    namespace with <stddef.h>'s symbols.  Otherwise, include <stddef.h>
    and use ptrdiff_t.  */
 
 #ifdef __PTRDIFF_TYPE__
-# define PTR_INT_TYPE __PTRDIFF_TYPE__
+# define __PTR_INT_TYPE __PTRDIFF_TYPE__
 #else
 # include <stddef.h>
-# define PTR_INT_TYPE ptrdiff_t
+# define __PTR_INT_TYPE ptrdiff_t
 #endif
 
 /* If B is the base of an object addressed by P, return the result of
@@ -122,21 +168,28 @@
 
 #define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
 
-/* Similar to _BPTR_ALIGN (B, P, A), except optimize the common case
+/* Similar to __BPTR_ALIGN (B, P, A), except optimize the common case
    where pointers can be converted to integers, aligned as integers,
-   and converted back again.  If PTR_INT_TYPE is narrower than a
+   and converted back again.  If __PTR_INT_TYPE is narrower than a
    pointer (e.g., the AS/400), play it safe and compute the alignment
    relative to B.  Otherwise, use the faster strategy of computing the
    alignment relative to 0.  */
 
 #define __PTR_ALIGN(B, P, A)						      \
-  __BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
+  __BPTR_ALIGN (sizeof (__PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
 		P, A)
 
+#if defined _LIBC || defined HAVE_STRING_H
 #include <string.h>
+#endif
 
+/* Attribute 'pure' was valid as of gcc 3.0.  */
 #ifndef __attribute_pure__
-# define __attribute_pure__ _GL_ATTRIBUTE_PURE
+# if defined __GNUC__ && __GNUC__ >= 3
+#  define __attribute_pure__ __attribute__ ((__pure__))
+# else
+#  define __attribute_pure__
+# endif
 #endif
 
 #ifdef __cplusplus
@@ -152,21 +205,21 @@
 
 struct obstack          /* control current object in current chunk */
 {
-  long chunk_size;              /* preferred size to allocate chunks in */
+  __CHUNK_SIZE_T chunk_size;	/* preferred size to allocate chunks in */
   struct _obstack_chunk *chunk; /* address of current struct obstack_chunk */
   char *object_base;            /* address of object we are building */
   char *next_free;              /* where to add next char to current object */
   char *chunk_limit;            /* address of char after current chunk */
   union
   {
-    PTR_INT_TYPE tempint;
-    void *tempptr;
+    __OBSTACK_SIZE_T i;
+    void *p;
   } temp;                       /* Temporary for some macros.  */
   int alignment_mask;           /* Mask of alignment for each object. */
   /* These prototypes vary based on 'use_extra_arg', and we use
      casts to the prototypeless function type in all assignments,
      but having prototypes here quiets -Wstrict-prototypes.  */
-  struct _obstack_chunk *(*chunkfun) (void *, long);
+  struct _obstack_chunk *(*chunkfun) (void *, size_t);
   void (*freefun) (void *, struct _obstack_chunk *);
   void *extra_arg;              /* first arg for chunk alloc/dealloc funcs */
   unsigned use_extra_arg : 1;     /* chunk alloc/dealloc funcs take extra arg */
@@ -181,18 +234,19 @@
 
 /* Declare the external functions we use; they are in obstack.c.  */
 
-extern void _obstack_newchunk (struct obstack *, int);
-extern int _obstack_begin (struct obstack *, int, int,
-			   void *(*)(long), void (*)(void *));
-extern int _obstack_begin_1 (struct obstack *, int, int,
-			     void *(*)(void *, long),
+extern void _obstack_newchunk (struct obstack *, __OBSTACK_SIZE_T);
+extern int _obstack_begin (struct obstack *, __CHUNK_SIZE_T, int,
+			    void *(*) (size_t), void (*) (void *));
+extern int _obstack_begin_1 (struct obstack *, __CHUNK_SIZE_T, int,
+			     void *(*) (void *, size_t),
 			     void (*)(void *, void *), void *);
-extern int _obstack_memory_used (struct obstack *) __attribute_pure__;
+extern __OBSTACK_SIZE_T _obstack_memory_used (struct obstack *)
+  __attribute_pure__;
 
-/* The default name of the function for freeing a chunk is 'obstack_free',
+/* The default name of the function for freeing a chunk is '_obstack_free',
    but gnulib users can override this by defining '__obstack_free'.  */
 #ifndef __obstack_free
-# define __obstack_free obstack_free
+# define __obstack_free _obstack_free
 #endif
 extern void __obstack_free (struct obstack *, void *);
 
@@ -227,26 +281,26 @@
 /* To prevent prototype warnings provide complete argument list.  */
 #define obstack_init(h)							      \
   _obstack_begin ((h), 0, 0,						      \
-		  (void *(*)(long))obstack_chunk_alloc,			      \
+		  (void *(*) (size_t)) obstack_chunk_alloc,		\
 		  (void (*)(void *))obstack_chunk_free)
 
 #define obstack_begin(h, size)						      \
   _obstack_begin ((h), (size), 0,					      \
-		  (void *(*)(long))obstack_chunk_alloc,			      \
+		  (void *(*) (size_t)) obstack_chunk_alloc,		\
 		  (void (*)(void *))obstack_chunk_free)
 
 #define obstack_specify_allocation(h, size, alignment, chunkfun, freefun)  \
   _obstack_begin ((h), (size), (alignment),				      \
-		  (void *(*)(long))(chunkfun),				      \
+		  (void *(*) (size_t)) (chunkfun),			\
 		  (void (*)(void *))(freefun))
 
 #define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
   _obstack_begin_1 ((h), (size), (alignment),				      \
-		    (void *(*)(void *, long))(chunkfun),		      \
+		    (void *(*) (void *, size_t)) (chunkfun),		\
 		    (void (*)(void *, void *))(freefun), (arg))
 
 #define obstack_chunkfun(h, newchunkfun) \
-  ((h)->chunkfun = (struct _obstack_chunk *(*)(void *, long))(newchunkfun))
+  ((h)->chunkfun = (struct _obstack_chunk *(*)(void *, size_t)) (newchunkfun))
 
 #define obstack_freefun(h, newfreefun) \
   ((h)->freefun = (void (*)(void *, struct _obstack_chunk *))(newfreefun))
@@ -258,7 +312,7 @@
 #define obstack_memory_used(h) _obstack_memory_used (h)
 
 #if defined __GNUC__
-# if ! (2 < __GNUC__ + (8 <= __GNUC_MINOR__))
+# if !defined __GNUC_MINOR__ || __GNUC__ * 1000 + __GNUC_MINOR__ < 2008
 #  define __extension__
 # endif
 
@@ -270,18 +324,20 @@
 # define obstack_object_size(OBSTACK)					      \
   __extension__								      \
     ({ struct obstack const *__o = (OBSTACK);				      \
-       (unsigned) (__o->next_free - __o->object_base); })
+     (__OBSTACK_SIZE_T) (__o->next_free - __o->object_base); })
 
+/* The local variable is named __o1 to avoid a shadowed variable
+   warning when invoked from other obstack macros.  */
 # define obstack_room(OBSTACK)						      \
   __extension__								      \
-    ({ struct obstack const *__o = (OBSTACK);				      \
-       (unsigned) (__o->chunk_limit - __o->next_free); })
+  ({ struct obstack const *__o1 = (OBSTACK);				\
+     (__OBSTACK_SIZE_T) (__o1->chunk_limit - __o1->next_free); })
 
 # define obstack_make_room(OBSTACK, length)				      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
-       int __len = (length);						      \
-       if (__o->chunk_limit - __o->next_free < __len)			      \
+     __OBSTACK_SIZE_T __len = (length);					\
+     if (obstack_room (__o) < __len)					\
 	 _obstack_newchunk (__o, __len);				      \
        (void) 0; })
 
@@ -296,8 +352,8 @@
 # define obstack_grow(OBSTACK, where, length)				      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
-       int __len = (length);						      \
-       if (__o->next_free + __len > __o->chunk_limit)			      \
+     __OBSTACK_SIZE_T __len = (length);					\
+     if (obstack_room (__o) < __len)					\
 	 _obstack_newchunk (__o, __len);				      \
        memcpy (__o->next_free, where, __len);				      \
        __o->next_free += __len;						      \
@@ -306,8 +362,8 @@
 # define obstack_grow0(OBSTACK, where, length)				      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
-       int __len = (length);						      \
-       if (__o->next_free + __len + 1 > __o->chunk_limit)		      \
+     __OBSTACK_SIZE_T __len = (length);					\
+     if (obstack_room (__o) < __len + 1)				\
 	 _obstack_newchunk (__o, __len + 1);				      \
        memcpy (__o->next_free, where, __len);				      \
        __o->next_free += __len;						      \
@@ -317,7 +373,7 @@
 # define obstack_1grow(OBSTACK, datum)					      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
-       if (__o->next_free + 1 > __o->chunk_limit)			      \
+     if (obstack_room (__o) < 1)					\
 	 _obstack_newchunk (__o, 1);					      \
        obstack_1grow_fast (__o, datum);					      \
        (void) 0; })
@@ -329,14 +385,14 @@
 # define obstack_ptr_grow(OBSTACK, datum)				      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
-       if (__o->next_free + sizeof (void *) > __o->chunk_limit)		      \
+     if (obstack_room (__o) < sizeof (void *))				\
 	 _obstack_newchunk (__o, sizeof (void *));			      \
-       obstack_ptr_grow_fast (__o, datum); })				      \
+     obstack_ptr_grow_fast (__o, datum); })
 
 # define obstack_int_grow(OBSTACK, datum)				      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
-       if (__o->next_free + sizeof (int) > __o->chunk_limit)		      \
+     if (obstack_room (__o) < sizeof (int))				\
 	 _obstack_newchunk (__o, sizeof (int));				      \
        obstack_int_grow_fast (__o, datum); })
 
@@ -359,8 +415,8 @@
 # define obstack_blank(OBSTACK, length)					      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
-       int __len = (length);						      \
-       if (__o->chunk_limit - __o->next_free < __len)			      \
+     __OBSTACK_SIZE_T __len = (length);					\
+     if (obstack_room (__o) < __len)					\
 	 _obstack_newchunk (__o, __len);				      \
        obstack_blank_fast (__o, __len);					      \
        (void) 0; })
@@ -383,19 +439,16 @@
        obstack_grow0 (__h, (where), (length));				      \
        obstack_finish (__h); })
 
-/* The local variable is named __o1 to avoid a name conflict
-   when obstack_blank is called.  */
 # define obstack_finish(OBSTACK)					      \
   __extension__								      \
     ({ struct obstack *__o1 = (OBSTACK);				      \
        void *__value = (void *) __o1->object_base;			      \
        if (__o1->next_free == __value)					      \
 	 __o1->maybe_empty_object = 1;					      \
-       __o1->next_free							      \
-	 = __PTR_ALIGN (__o1->object_base, __o1->next_free,		      \
+     __o1->next_free = __PTR_ALIGN (__o1->object_base, __o1->next_free,	\
 			__o1->alignment_mask);				      \
-       if (__o1->next_free - (char *) __o1->chunk			      \
-	   > __o1->chunk_limit - (char *) __o1->chunk)			      \
+     if ((size_t) (__o1->next_free - (char *) __o1->chunk)		\
+	 > (size_t) (__o1->chunk_limit - (char *) __o1->chunk))		\
 	 __o1->next_free = __o1->chunk_limit;				      \
        __o1->object_base = __o1->next_free;				      \
        __value; })
@@ -403,18 +456,20 @@
 # define obstack_free(OBSTACK, OBJ)					      \
   __extension__								      \
     ({ struct obstack *__o = (OBSTACK);					      \
-       void *__obj = (OBJ);						      \
-       if (__obj > (void *) __o->chunk && __obj < (void *) __o->chunk_limit)  \
+     void *__obj = (void *) (OBJ);					\
+     if (__obj > (void *) __o->chunk					\
+	 && __obj < (void *) __o->chunk_limit)				\
 	 __o->next_free = __o->object_base = (char *) __obj;		      \
-       else (__obstack_free) (__o, __obj); })
+     else								\
+       __obstack_free (__o, __obj); })
 
 #else /* not __GNUC__ */
 
 # define obstack_object_size(h) \
-  (unsigned) ((h)->next_free - (h)->object_base)
+  ((__OBSTACK_SIZE_T) ((h)->next_free - (h)->object_base))
 
 # define obstack_room(h)						      \
-  (unsigned) ((h)->chunk_limit - (h)->next_free)
+  ((__OBSTACK_SIZE_T) ((h)->chunk_limit - (h)->next_free))
 
 # define obstack_empty_p(h) \
   ((h)->chunk->prev == 0						      \
@@ -427,29 +482,28 @@
    in the arms of the conditional expression.
    Casting the third operand to void was tried before,
    but some compilers won't accept it.  */
-
 # define obstack_make_room(h, length)					      \
-  ((h)->temp.tempint = (length),					      \
-   (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit)		      \
-   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))
+  ((h)->temp.i = (length),						\
+   ((obstack_room (h) < (h)->temp.i)					\
+    ? (_obstack_newchunk ((h), (h)->temp.i), 0) : 0))
 
 # define obstack_grow(h, where, length)					      \
-  ((h)->temp.tempint = (length),					      \
-   (((h)->next_free + (h)->temp.tempint > (h)->chunk_limit)		      \
-   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0),		      \
-   memcpy ((h)->next_free, where, (h)->temp.tempint),			      \
-   (h)->next_free += (h)->temp.tempint)
+  ((h)->temp.i = (length),						\
+   ((obstack_room (h) < (h)->temp.i)					\
+    ? (_obstack_newchunk ((h), (h)->temp.i), 0) : 0),			\
+   memcpy ((h)->next_free, where, (h)->temp.i),				\
+   (h)->next_free += (h)->temp.i)
 
 # define obstack_grow0(h, where, length)				      \
-  ((h)->temp.tempint = (length),					      \
-   (((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit)		      \
-   ? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0),		      \
-   memcpy ((h)->next_free, where, (h)->temp.tempint),			      \
-   (h)->next_free += (h)->temp.tempint,					      \
+  ((h)->temp.i = (length),						\
+   ((obstack_room (h) < (h)->temp.i + 1)				\
+    ? (_obstack_newchunk ((h), (h)->temp.i + 1), 0) : 0),		\
+   memcpy ((h)->next_free, where, (h)->temp.i),				\
+   (h)->next_free += (h)->temp.i,					\
    *((h)->next_free)++ = 0)
 
 # define obstack_1grow(h, datum)					      \
-  ((((h)->next_free + 1 > (h)->chunk_limit)				      \
+  (((obstack_room (h) < 1)						\
     ? (_obstack_newchunk ((h), 1), 0) : 0),				      \
    obstack_1grow_fast (h, datum))
 
@@ -459,7 +513,7 @@
    obstack_ptr_grow_fast (h, datum))
 
 # define obstack_int_grow(h, datum)					      \
-  ((((h)->next_free + sizeof (int) > (h)->chunk_limit)			      \
+  (((obstack_room (h) < sizeof (int))					\
     ? (_obstack_newchunk ((h), sizeof (int)), 0) : 0),			      \
    obstack_int_grow_fast (h, datum))
 
@@ -470,10 +524,10 @@
   (((int *) ((h)->next_free += sizeof (int)))[-1] = (aint))
 
 # define obstack_blank(h, length)					      \
-  ((h)->temp.tempint = (length),					      \
-   (((h)->chunk_limit - (h)->next_free < (h)->temp.tempint)		      \
-   ? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0),		      \
-   obstack_blank_fast (h, (h)->temp.tempint))
+  ((h)->temp.i = (length),						\
+   ((obstack_room (h) < (h)->temp.i)					\
+    ? (_obstack_newchunk ((h), (h)->temp.i), 0) : 0),			\
+   obstack_blank_fast (h, (h)->temp.i))
 
 # define obstack_alloc(h, length)					      \
   (obstack_blank ((h), (length)), obstack_finish ((h)))
@@ -488,23 +542,21 @@
   (((h)->next_free == (h)->object_base					      \
     ? (((h)->maybe_empty_object = 1), 0)				      \
     : 0),								      \
-   (h)->temp.tempptr = (h)->object_base,				      \
-   (h)->next_free							      \
-     = __PTR_ALIGN ((h)->object_base, (h)->next_free,			      \
+   (h)->temp.p = (h)->object_base,					\
+   (h)->next_free = __PTR_ALIGN ((h)->object_base, (h)->next_free,	\
 		    (h)->alignment_mask),				      \
-   (((h)->next_free - (char *) (h)->chunk				      \
-     > (h)->chunk_limit - (char *) (h)->chunk)				      \
+   (((size_t) ((h)->next_free - (char *) (h)->chunk)			\
+     > (size_t) ((h)->chunk_limit - (char *) (h)->chunk))		\
    ? ((h)->next_free = (h)->chunk_limit) : 0),				      \
    (h)->object_base = (h)->next_free,					      \
-   (h)->temp.tempptr)
+   (h)->temp.p)
 
 # define obstack_free(h, obj)						      \
-  ((h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk,		      \
-   ((((h)->temp.tempint > 0						      \
-      && (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk))	      \
-    ? (void) ((h)->next_free = (h)->object_base				      \
-	      = (h)->temp.tempint + (char *) (h)->chunk)		      \
-    : (__obstack_free) (h, (h)->temp.tempint + (char *) (h)->chunk)))
+  ((h)->temp.p = (void *) (obj),					\
+   (((h)->temp.p > (void *) (h)->chunk					\
+     && (h)->temp.p < (void *) (h)->chunk_limit)			\
+    ? (void) ((h)->next_free = (h)->object_base = (char *) (h)->temp.p) \
+    : __obstack_free ((h), (h)->temp.p)))
 
 #endif /* not __GNUC__ */
 
@@ -512,4 +564,4 @@
 }       /* C++ */
 #endif
 
-#endif /* obstack.h */
+#endif /* _OBSTACK_H */
--- glibc-current/malloc/obstack.c	2014-07-12 13:18:12.805934386 +0930
+++ binutils-gdb/libiberty/obstack.c	2014-07-13 19:52:15.560418673 +0930
@@ -21,37 +21,19 @@
 # include <obstack.h>
 # include <shlib-compat.h>
 #else
-# include <config.h>
+# ifdef HAVE_CONFIG_H
+#  include "config.h"
+# endif
 # include "obstack.h"
 #endif
 
-/* NOTE BEFORE MODIFYING THIS FILE: This version number must be
-   incremented whenever callers compiled using an old obstack.h can no
-   longer properly call the functions in this obstack.c.  */
-#define OBSTACK_INTERFACE_VERSION 1
-
-/* Comment out all this code if we are using the GNU C Library, and are not
-   actually compiling the library itself, and the installed library
-   supports the same library interface we do.  This code is part of the GNU
-   C Library, but also included in many other GNU distributions.  Compiling
-   and linking in this code is a waste when using the GNU C library
-   (especially if it is a shared library).  Rather than having every GNU
-   program understand 'configure --with-gnu-libc' and omit the object
-   files, it is simpler to just do this in the source for each such file.  */
+/* NOTE BEFORE MODIFYING THIS FILE: __OBSTACK_INTERFACE_VERSION in
+   obstack.h must be incremented whenever callers compiled using an old
+   obstack.h can no longer properly call the functions in this file.  */
 
-#include <stdio.h>              /* Random thing to get __GNU_LIBRARY__.  */
-#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
-# include <gnu-versions.h>
-# if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
-#  define ELIDE_CODE
-# endif
-#endif
+#ifndef __OBSTACK_ELIDE_CODE
 
 #include <stddef.h>
-
-#ifndef ELIDE_CODE
-
-
 # include <stdint.h>
 
 /* Determine default alignment.  */
@@ -75,34 +57,44 @@
   DEFAULT_ROUNDING = sizeof (union fooround)
 };
 
-/* When we copy a long block of data, this is the unit to do it with.
-   On some machines, copying successive ints does not work;
-   in such a case, redefine COPYING_UNIT to 'long' (if that works)
-   or 'char' as a last resort.  */
-# ifndef COPYING_UNIT
-#  define COPYING_UNIT int
+# ifdef _LIBC
+#  include <gnu-versions.h>
 # endif
 
-
 /* The functions allocating more room by calling 'obstack_chunk_alloc'
    jump to the handler pointed to by 'obstack_alloc_failed_handler'.
    This can be set to a user defined function which should either
    abort gracefully or use longjump - but shouldn't return.  This
    variable by default points to the internal function
    'print_and_abort'.  */
-static _Noreturn void print_and_abort (void);
+
+# if (!defined _LIBC							\
+      || _GNU_OBSTACK_INTERFACE_VERSION == __OBSTACK_INTERFACE_VERSION)
+
+#ifndef __attribute_noreturn__
+# if (defined __GNUC__ && defined __GNUC_MINOR__			\
+      && __GNUC__ * 1000 + __GNUC_MINOR__ >= 2007)
+#  define __attribute_noreturn__ __attribute__ ((__noreturn__))
+# else
+#  define __attribute_noreturn__
+# endif
+#endif
+static void __attribute_noreturn__ print_and_abort (void);
 void (*obstack_alloc_failed_handler) (void) = print_and_abort;
 
 /* Exit value used when 'print_and_abort' is used.  */
 # include <stdlib.h>
+#  ifndef EXIT_FAILURE
+#   define EXIT_FAILURE 1
+#   endif
 # ifdef _LIBC
 int obstack_exit_failure = EXIT_FAILURE;
 # else
-#  include "exitfail.h"
-#  define obstack_exit_failure exit_failure
+#   define obstack_exit_failure EXIT_FAILURE
+#  endif
 # endif
 
-# ifdef _LIBC
+# if defined _LIBC && __OBSTACK_INTERFACE_VERSION == 1
 #  if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4)
 /* A looong time ago (before 1994, anyway; we're not sure) this global variable
    was used by non-GNU-C macros to avoid multiple evaluation.  The GNU C
@@ -121,7 +113,7 @@
 # define CALL_CHUNKFUN(h, size) \
   (((h)->use_extra_arg)							      \
    ? (*(h)->chunkfun)((h)->extra_arg, (size))				      \
-   : (*(struct _obstack_chunk *(*)(long))(h)->chunkfun)((size)))
+   : (*(struct _obstack_chunk *(*) (size_t)) (h)->chunkfun) ((size)))
 
 # define CALL_FREEFUN(h, old_chunk) \
   do { \
@@ -140,11 +132,14 @@
    Return nonzero if successful, calls obstack_alloc_failed_handler if
    allocation fails.  */
 
-int
-_obstack_begin (struct obstack *h,
-		int size, int alignment,
-		void *(*chunkfun) (long),
-		void (*freefun) (void *))
+typedef struct _obstack_chunk * (*chunkfun_t) (void *, size_t);
+typedef void (*freefun_t) (void *, struct _obstack_chunk *);
+
+static int
+_obstack_begin_worker (struct obstack *h,
+		       __CHUNK_SIZE_T size, int alignment,
+		       chunkfun_t chunkfun, freefun_t freefun,
+		       void *arg, int use_extra_arg)
 {
   struct _obstack_chunk *chunk; /* points to new chunk */
 
@@ -167,19 +162,19 @@
       size = 4096 - extra;
     }
 
-  h->chunkfun = (struct _obstack_chunk * (*) (void *, long)) chunkfun;
-  h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
+  h->chunkfun = chunkfun;
+  h->freefun = freefun;
   h->chunk_size = size;
   h->alignment_mask = alignment - 1;
-  h->use_extra_arg = 0;
+  h->extra_arg = arg;
+  h->use_extra_arg = use_extra_arg;
 
   chunk = h->chunk = CALL_CHUNKFUN (h, h->chunk_size);
   if (!chunk)
     (*obstack_alloc_failed_handler) ();
   h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
 					       alignment - 1);
-  h->chunk_limit = chunk->limit
-    = (char *) chunk + h->chunk_size;
+  h->chunk_limit = chunk->limit = (char *) chunk + h->chunk_size;
   chunk->prev = 0;
   /* The initial chunk now contains no empty object.  */
   h->maybe_empty_object = 0;
@@ -188,51 +183,26 @@
 }
 
 int
-_obstack_begin_1 (struct obstack *h, int size, int alignment,
-		  void *(*chunkfun) (void *, long),
-		  void (*freefun) (void *, void *),
-		  void *arg)
-{
-  struct _obstack_chunk *chunk; /* points to new chunk */
-
-  if (alignment == 0)
-    alignment = DEFAULT_ALIGNMENT;
-  if (size == 0)
-    /* Default size is what GNU malloc can fit in a 4096-byte block.  */
+_obstack_begin (struct obstack *h,
+		__CHUNK_SIZE_T size, int alignment,
+		void *(*chunkfun) (size_t),
+		void (*freefun) (void *))
     {
-      /* 12 is sizeof (mhead) and 4 is EXTRA from GNU malloc.
-	 Use the values for range checking, because if range checking is off,
-	 the extra bytes won't be missed terribly, but if range checking is on
-	 and we used a larger request, a whole extra 4096 bytes would be
-	 allocated.
-
-	 These number are irrelevant to the new GNU malloc.  I suspect it is
-	 less sensitive to the size of the request.  */
-      int extra = ((((12 + DEFAULT_ROUNDING - 1) & ~(DEFAULT_ROUNDING - 1))
-		    + 4 + DEFAULT_ROUNDING - 1)
-		   & ~(DEFAULT_ROUNDING - 1));
-      size = 4096 - extra;
+  return _obstack_begin_worker (h, size, alignment,
+				(chunkfun_t) chunkfun, (freefun_t) freefun,
+				NULL, 0);
     }
 
-  h->chunkfun = (struct _obstack_chunk * (*)(void *,long)) chunkfun;
-  h->freefun = (void (*) (void *, struct _obstack_chunk *)) freefun;
-  h->chunk_size = size;
-  h->alignment_mask = alignment - 1;
-  h->extra_arg = arg;
-  h->use_extra_arg = 1;
-
-  chunk = h->chunk = CALL_CHUNKFUN (h, h->chunk_size);
-  if (!chunk)
-    (*obstack_alloc_failed_handler) ();
-  h->next_free = h->object_base = __PTR_ALIGN ((char *) chunk, chunk->contents,
-					       alignment - 1);
-  h->chunk_limit = chunk->limit
-    = (char *) chunk + h->chunk_size;
-  chunk->prev = 0;
-  /* The initial chunk now contains no empty object.  */
-  h->maybe_empty_object = 0;
-  h->alloc_failed = 0;
-  return 1;
+int
+_obstack_begin_1 (struct obstack *h,
+		  __CHUNK_SIZE_T size, int alignment,
+		  void *(*chunkfun) (void *, size_t),
+		  void (*freefun) (void *, void *),
+		  void *arg)
+{
+  return _obstack_begin_worker (h, size, alignment,
+				(chunkfun_t) chunkfun, (freefun_t) freefun,
+				arg, 1);
 }
 
 /* Allocate a new current chunk for the obstack *H
@@ -242,14 +212,12 @@
    to the beginning of the new one.  */
 
 void
-_obstack_newchunk (struct obstack *h, int length)
+_obstack_newchunk (struct obstack *h, __OBSTACK_SIZE_T length)
 {
   struct _obstack_chunk *old_chunk = h->chunk;
   struct _obstack_chunk *new_chunk;
-  long new_size;
-  long obj_size = h->next_free - h->object_base;
-  long i;
-  long already;
+  size_t new_size;
+  size_t obj_size = h->next_free - h->object_base;
   char *object_base;
 
   /* Compute size for new chunk.  */
@@ -269,25 +237,8 @@
   object_base =
     __PTR_ALIGN ((char *) new_chunk, new_chunk->contents, h->alignment_mask);
 
-  /* Move the existing object to the new chunk.
-     Word at a time is fast and is safe if the object
-     is sufficiently aligned.  */
-  if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT)
-    {
-      for (i = obj_size / sizeof (COPYING_UNIT) - 1;
-	   i >= 0; i--)
-	((COPYING_UNIT *) object_base)[i]
-	  = ((COPYING_UNIT *) h->object_base)[i];
-      /* We used to copy the odd few remaining bytes as one extra COPYING_UNIT,
-	 but that can cross a page boundary on a machine
-	 which does not do strict alignment for COPYING_UNITS.  */
-      already = obj_size / sizeof (COPYING_UNIT) * sizeof (COPYING_UNIT);
-    }
-  else
-    already = 0;
-  /* Copy remaining bytes one by one.  */
-  for (i = already; i < obj_size; i++)
-    object_base[i] = h->object_base[i];
+  /* Move the existing object to the new chunk.  */
+  memcpy (object_base, h->object_base, obj_size);
 
   /* If the object just copied was the only data in OLD_CHUNK,
      free that chunk and remove it from the chain.
@@ -371,40 +322,43 @@
     abort ();
 }
 
-# ifdef _LIBC
-/* Older versions of libc used a function _obstack_free intended to be
-   called by non-GCC compilers.  */
-strong_alias (obstack_free, _obstack_free)
+# if defined _LIBC && __OBSTACK_INTERFACE_VERSION == 1
+/* Older versions of libc declared both _obstack_free and obstack_free.  */
+strong_alias (__obstack_free, obstack_free)
 # endif
 
-int
+__OBSTACK_SIZE_T
 _obstack_memory_used (struct obstack *h)
 {
   struct _obstack_chunk *lp;
-  int nbytes = 0;
+  __OBSTACK_SIZE_T nbytes = 0;
 
   for (lp = h->chunk; lp != 0; lp = lp->prev)
-    {
       nbytes += lp->limit - (char *) lp;
-    }
+
   return nbytes;
 }
 
+# if (!defined _LIBC							\
+      || _GNU_OBSTACK_INTERFACE_VERSION == __OBSTACK_INTERFACE_VERSION)
 /* Define the error handler.  */
-# ifdef _LIBC
+#  if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC
 #  include <libintl.h>
-# else
-#  include "gettext.h"
+#   ifndef _
+#    define _(Str) gettext (Str)
 # endif
+#  else
 # ifndef _
-#  define _(msgid) gettext (msgid)
+#    define _(Str) (Str)
+#   endif
 # endif
 
 # ifdef _LIBC
 #  include <libio/iolibio.h>
 # endif
 
-static _Noreturn void
+static void
+__attribute_noreturn__
 print_and_abort (void)
 {
   /* Don't change any of these strings.  Yes, it would be possible to add
@@ -419,5 +373,6 @@
 # endif
   exit (obstack_exit_failure);
 }
+# endif
 
-#endif  /* !ELIDE_CODE */
+#endif	/* !__OBSTACK_ELIDE_CODE */
diff --git a/libiberty/configure.ac b/libiberty/configure.ac
index 3380819..716664a 100644
--- a/libiberty/configure.ac
+++ b/libiberty/configure.ac
@@ -272,8 +272,10 @@ AC_HEADER_TIME
 
 libiberty_AC_DECLARE_ERRNO
 
-# Determine the size of an int for struct fibnode.
+# Determine the size of an int for struct fibnode and both int and size_t
+# for obstack.h.
 AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([size_t])
 
 # Look for a 64-bit type.
 AC_MSG_CHECKING([for a 64-bit type])
diff --git a/libiberty/obstacks.texi b/libiberty/obstacks.texi
index adcd810..5cab523 100644
--- a/libiberty/obstacks.texi
+++ b/libiberty/obstacks.texi
@@ -168,7 +168,7 @@ The most direct way to allocate an object in an obstack is with
 
 @comment obstack.h
 @comment GNU
-@deftypefun {void *} obstack_alloc (struct obstack *@var{obstack-ptr}, int @var{size})
+@deftypefun {void *} obstack_alloc (struct obstack *@var{obstack-ptr}, size_t @var{size})
 This allocates an uninitialized block of @var{size} bytes in an obstack
 and returns its address.  Here @var{obstack-ptr} specifies which obstack
 to allocate the block in; it is the address of the @code{struct obstack}
@@ -202,7 +202,7 @@ To allocate a block with specified contents, use the function
 
 @comment obstack.h
 @comment GNU
-@deftypefun {void *} obstack_copy (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var{size})
+@deftypefun {void *} obstack_copy (struct obstack *@var{obstack-ptr}, void *@var{address}, size_t @var{size})
 This allocates a block and initializes it by copying @var{size}
 bytes of data starting at @var{address}.  It calls
 @code{obstack_alloc_failed_handler} if allocation of memory by
@@ -211,7 +211,7 @@ bytes of data starting at @var{address}.  It calls
 
 @comment obstack.h
 @comment GNU
-@deftypefun {void *} obstack_copy0 (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var{size})
+@deftypefun {void *} obstack_copy0 (struct obstack *@var{obstack-ptr}, void *@var{address}, size_t @var{size})
 Like @code{obstack_copy}, but appends an extra byte containing a null
 character.  This extra byte is not counted in the argument @var{size}.
 @end deftypefun
@@ -222,7 +222,7 @@ example of its use:
 
 @smallexample
 char *
-obstack_savestring (char *addr, int size)
+obstack_savestring (char *addr, size_t size)
 @{
   return obstack_copy0 (&myobstack, addr, size);
 @}
@@ -347,14 +347,14 @@ already added to the growing object will become part of the other object.
 
 @comment obstack.h
 @comment GNU
-@deftypefun void obstack_blank (struct obstack *@var{obstack-ptr}, int @var{size})
+@deftypefun void obstack_blank (struct obstack *@var{obstack-ptr}, size_t @var{size})
 The most basic function for adding to a growing object is
 @code{obstack_blank}, which adds space without initializing it.
 @end deftypefun
 
 @comment obstack.h
 @comment GNU
-@deftypefun void obstack_grow (struct obstack *@var{obstack-ptr}, void *@var{data}, int @var{size})
+@deftypefun void obstack_grow (struct obstack *@var{obstack-ptr}, void *@var{data}, size_t @var{size})
 To add a block of initialized space, use @code{obstack_grow}, which is
 the growing-object analogue of @code{obstack_copy}.  It adds @var{size}
 bytes of data to the growing object, copying the contents from
@@ -363,7 +363,7 @@ bytes of data to the growing object, copying the contents from
 
 @comment obstack.h
 @comment GNU
-@deftypefun void obstack_grow0 (struct obstack *@var{obstack-ptr}, void *@var{data}, int @var{size})
+@deftypefun void obstack_grow0 (struct obstack *@var{obstack-ptr}, void *@var{data}, size_t @var{size})
 This is the growing-object analogue of @code{obstack_copy0}.  It adds
 @var{size} bytes copied from @var{data}, followed by an additional null
 character.
@@ -413,7 +413,7 @@ declared as follows:
 
 @comment obstack.h
 @comment GNU
-@deftypefun int obstack_object_size (struct obstack *@var{obstack-ptr})
+@deftypefun size_t obstack_object_size (struct obstack *@var{obstack-ptr})
 This function returns the current size of the growing object, in bytes.
 Remember to call this function @emph{before} finishing the object.
 After it is finished, @code{obstack_object_size} will return zero.
@@ -456,7 +456,7 @@ in the current chunk.  It is declared as follows:
 
 @comment obstack.h
 @comment GNU
-@deftypefun int obstack_room (struct obstack *@var{obstack-ptr})
+@deftypefun size_t obstack_room (struct obstack *@var{obstack-ptr})
 This returns the number of bytes that can be added safely to the current
 growing object (or to an object about to be started) in obstack
 @var{obstack} using the fast growth functions.
@@ -490,7 +490,7 @@ containing the value of @var{data} to the growing object in obstack
 
 @comment obstack.h
 @comment GNU
-@deftypefun void obstack_blank_fast (struct obstack *@var{obstack-ptr}, int @var{size})
+@deftypefun void obstack_blank_fast (struct obstack *@var{obstack-ptr}, size_t @var{size})
 The function @code{obstack_blank_fast} adds @var{size} bytes to the
 growing object in obstack @var{obstack-ptr} without initializing them.
 @end deftypefun
@@ -511,11 +511,11 @@ Here is an example:
 @smallexample
 @group
 void
-add_string (struct obstack *obstack, const char *ptr, int len)
+add_string (struct obstack *obstack, const char *ptr, size_t len)
 @{
   while (len > 0)
     @{
-      int room = obstack_room (obstack);
+      size_t room = obstack_room (obstack);
       if (room == 0)
         @{
           /* @r{Not enough room. Add one character slowly,}
@@ -570,7 +570,7 @@ returns the same value as @code{obstack_base}.
 
 @comment obstack.h
 @comment GNU
-@deftypefun int obstack_object_size (struct obstack *@var{obstack-ptr})
+@deftypefun size_t obstack_object_size (struct obstack *@var{obstack-ptr})
 This function returns the size in bytes of the currently growing object.
 This is equivalent to
 
@@ -661,7 +661,7 @@ not to waste too much memory in the portion of the last chunk not yet used.
 
 @comment obstack.h
 @comment GNU
-@deftypefn Macro int obstack_chunk_size (struct obstack *@var{obstack-ptr})
+@deftypefn Macro size_t obstack_chunk_size (struct obstack *@var{obstack-ptr})
 This returns the chunk size of the given obstack.
 @end deftypefn
 
@@ -689,15 +689,15 @@ argument.
 @item void obstack_init (struct obstack *@var{obstack-ptr})
 Initialize use of an obstack.  @xref{Creating Obstacks}.
 
-@item void *obstack_alloc (struct obstack *@var{obstack-ptr}, int @var{size})
+@item void *obstack_alloc (struct obstack *@var{obstack-ptr}, size_t @var{size})
 Allocate an object of @var{size} uninitialized bytes.
 @xref{Allocation in an Obstack}.
 
-@item void *obstack_copy (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var{size})
+@item void *obstack_copy (struct obstack *@var{obstack-ptr}, void *@var{address}, size_t @var{size})
 Allocate an object of @var{size} bytes, with contents copied from
 @var{address}.  @xref{Allocation in an Obstack}.
 
-@item void *obstack_copy0 (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var{size})
+@item void *obstack_copy0 (struct obstack *@var{obstack-ptr}, void *@var{address}, size_t @var{size})
 Allocate an object of @var{size}+1 bytes, with @var{size} of them copied
 from @var{address}, followed by a null character at the end.
 @xref{Allocation in an Obstack}.
@@ -706,15 +706,15 @@ from @var{address}, followed by a null character at the end.
 Free @var{object} (and everything allocated in the specified obstack
 more recently than @var{object}).  @xref{Freeing Obstack Objects}.
 
-@item void obstack_blank (struct obstack *@var{obstack-ptr}, int @var{size})
+@item void obstack_blank (struct obstack *@var{obstack-ptr}, size_t @var{size})
 Add @var{size} uninitialized bytes to a growing object.
 @xref{Growing Objects}.
 
-@item void obstack_grow (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var{size})
+@item void obstack_grow (struct obstack *@var{obstack-ptr}, void *@var{address}, size_t @var{size})
 Add @var{size} bytes, copied from @var{address}, to a growing object.
 @xref{Growing Objects}.
 
-@item void obstack_grow0 (struct obstack *@var{obstack-ptr}, void *@var{address}, int @var{size})
+@item void obstack_grow0 (struct obstack *@var{obstack-ptr}, void *@var{address}, size_t @var{size})
 Add @var{size} bytes, copied from @var{address}, to a growing object,
 and then add another byte containing a null character.  @xref{Growing
 Objects}.
@@ -727,11 +727,11 @@ Add one byte containing @var{data-char} to a growing object.
 Finalize the object that is growing and return its permanent address.
 @xref{Growing Objects}.
 
-@item int obstack_object_size (struct obstack *@var{obstack-ptr})
+@item size_t obstack_object_size (struct obstack *@var{obstack-ptr})
 Get the current size of the currently growing object.  @xref{Growing
 Objects}.
 
-@item void obstack_blank_fast (struct obstack *@var{obstack-ptr}, int @var{size})
+@item void obstack_blank_fast (struct obstack *@var{obstack-ptr}, size_t @var{size})
 Add @var{size} uninitialized bytes to a growing object without checking
 that there is enough room.  @xref{Extra Fast Growing}.
 
@@ -739,7 +739,7 @@ that there is enough room.  @xref{Extra Fast Growing}.
 Add one byte containing @var{data-char} to a growing object without
 checking that there is enough room.  @xref{Extra Fast Growing}.
 
-@item int obstack_room (struct obstack *@var{obstack-ptr})
+@item size_t obstack_room (struct obstack *@var{obstack-ptr})
 Get the amount of room now available for growing the current object.
 @xref{Extra Fast Growing}.
 
@@ -747,7 +747,7 @@ Get the amount of room now available for growing the current object.
 The mask used for aligning the beginning of an object.  This is an
 lvalue.  @xref{Obstacks Data Alignment}.
 
-@item int obstack_chunk_size (struct obstack *@var{obstack-ptr})
+@item size_t obstack_chunk_size (struct obstack *@var{obstack-ptr})
 The size for allocating chunks.  This is an lvalue.  @xref{Obstack Chunks}.
 
 @item void *obstack_base (struct obstack *@var{obstack-ptr})
diff --git a/binutils/configure.ac b/binutils/configure.ac
index ff0d4dc..8a2b04c 100644
--- a/binutils/configure.ac
+++ b/binutils/configure.ac
@@ -186,6 +186,10 @@ fi
 AC_CHECK_DECLS([environ, fprintf, getc_unlocked, getenv,
 		sbrk, snprintf, stpcpy, strnlen, strstr, vsnprintf])
 
+# Determine the size of int and size_t for obstack.h.
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([size_t])
+
 # Link in zlib if we can.  This allows us to read compressed debug
 # sections.  This is used only by readelf.c (objdump uses bfd for
 # reading compressed sections).
diff --git a/gas/config/bfin-parse.y b/gas/config/bfin-parse.y
index fe742ad..435beea 100644
--- a/gas/config/bfin-parse.y
+++ b/gas/config/bfin-parse.y
@@ -20,7 +20,6 @@
 %{
 
 #include "as.h"
-#include <obstack.h>
 
 #include "bfin-aux.h"  /* Opcode generating auxiliaries.  */
 #include "libbfd.h"
diff --git a/gas/config/obj-aout.c b/gas/config/obj-aout.c
index 28369c0..93ea904 100644
--- a/gas/config/obj-aout.c
+++ b/gas/config/obj-aout.c
@@ -23,7 +23,6 @@
 #include "as.h"
 #undef NO_RELOC
 #include "aout/aout64.h"
-#include "obstack.h"
 
 void
 obj_aout_frob_symbol (symbolS *sym, int *punt ATTRIBUTE_UNUSED)
diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c
index 79c8f88..4e7b9b7 100644
--- a/gas/config/obj-coff.c
+++ b/gas/config/obj-coff.c
@@ -22,7 +22,6 @@
 
 #include "as.h"
 #include "safe-ctype.h"
-#include "obstack.h"
 #include "subsegs.h"
 #include "struc-symbol.h"
 
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index e59f27b..e2ef99e 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -266,7 +266,7 @@ elf_file_symbol (const char *s, int appfile)
       || (symbol_rootP->bsym->flags & BSF_FILE) == 0)
     {
       symbolS *sym;
-      unsigned int name_length;
+      size_t name_length;
 
       sym = symbol_new (s, absolute_section, 0, NULL);
       symbol_set_frag (sym, &zero_address_frag);
diff --git a/gas/config/obj-som.c b/gas/config/obj-som.c
index 47acab8..55a9b6a 100644
--- a/gas/config/obj-som.c
+++ b/gas/config/obj-som.c
@@ -24,7 +24,6 @@
 #include "as.h"
 #include "subsegs.h"
 #include "aout/stab_gnu.h"
-#include "obstack.h"
 
 static int version_seen = 0;
 static int copyright_seen = 0;
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index c7ace79..0a65b9d 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -1681,7 +1681,7 @@ symbol_locate (symbolS * symbolP,
 	       valueT valu,	/* Symbol value.  */
 	       fragS * frag)	/* Associated fragment.  */
 {
-  unsigned int name_length;
+  size_t name_length;
   char *preserved_copy_of_name;
 
   name_length = strlen (name) + 1;	/* +1 for \0.  */
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index 2f13238..fd3910b 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -3379,7 +3379,7 @@ symbol_locate (symbolS *    symbolP,
 	       valueT	    valu,	/* Symbol value.  */
 	       fragS *	    frag)	/* Associated fragment.	 */
 {
-  unsigned int name_length;
+  size_t name_length;
   char * preserved_copy_of_name;
 
   name_length = strlen (name) + 1;   /* +1 for \0.  */
diff --git a/gas/config/tc-bfin.c b/gas/config/tc-bfin.c
index 8366cbf..447a477 100644
--- a/gas/config/tc-bfin.c
+++ b/gas/config/tc-bfin.c
@@ -948,7 +948,7 @@ int ninsns;
 int count_insns;
 
 static void *
-allocate (int n)
+allocate (size_t n)
 {
   return obstack_alloc (&mempool, n);
 }
diff --git a/gas/config/tc-i960.c b/gas/config/tc-i960.c
index 7595e1d..91469eb 100644
--- a/gas/config/tc-i960.c
+++ b/gas/config/tc-i960.c
@@ -64,7 +64,6 @@
 #include "as.h"
 
 #include "safe-ctype.h"
-#include "obstack.h"
 
 #include "opcode/i960.h"
 
diff --git a/gas/config/tc-mmix.c b/gas/config/tc-mmix.c
index 7740ee2..82f48ae 100644
--- a/gas/config/tc-mmix.c
+++ b/gas/config/tc-mmix.c
@@ -3007,7 +3007,7 @@ mmix_handle_mmixal (void)
 	 it the same alignment and address as the associated instruction.  */
 
       /* Make room for the label including the ending nul.  */
-      int len_0 = s - label + 1;
+      size_t len_0 = s - label + 1;
 
       /* Save this label on the MMIX symbol obstack.  Saving it on an
 	 obstack is needless for "IS"-pseudos, but it's harmless and we
diff --git a/gas/config/tc-rl78.c b/gas/config/tc-rl78.c
index 0cd7e5b..f2382b7 100644
--- a/gas/config/tc-rl78.c
+++ b/gas/config/tc-rl78.c
@@ -20,7 +20,6 @@
 
 #include "as.h"
 #include "struc-symbol.h"
-#include "obstack.h"
 #include "safe-ctype.h"
 #include "dwarf2dbg.h"
 #include "libbfd.h"
diff --git a/gas/config/tc-rx.c b/gas/config/tc-rx.c
index c4842f9..0d7e1d5 100644
--- a/gas/config/tc-rx.c
+++ b/gas/config/tc-rx.c
@@ -20,7 +20,6 @@
 
 #include "as.h"
 #include "struc-symbol.h"
-#include "obstack.h"
 #include "safe-ctype.h"
 #include "dwarf2dbg.h"
 #include "libbfd.h"
diff --git a/gas/config/tc-score.c b/gas/config/tc-score.c
index e8c8b6d..72597a0 100644
--- a/gas/config/tc-score.c
+++ b/gas/config/tc-score.c
@@ -6315,7 +6315,7 @@ s3_build_score_ops_hsh (void)
   for (i = 0; i < sizeof (s3_score_insns) / sizeof (struct s3_asm_opcode); i++)
     {
       const struct s3_asm_opcode *insn = s3_score_insns + i;
-      unsigned len = strlen (insn->template_name);
+      size_t len = strlen (insn->template_name);
       struct s3_asm_opcode *new_opcode;
       char *template_name;
       new_opcode = (struct s3_asm_opcode *)
@@ -6344,7 +6344,7 @@ s3_build_dependency_insn_hsh (void)
   for (i = 0; i < sizeof (s3_insn_to_dependency_table) / sizeof (s3_insn_to_dependency_table[0]); i++)
     {
       const struct s3_insn_to_dependency *tmp = s3_insn_to_dependency_table + i;
-      unsigned len = strlen (tmp->insn_name);
+      size_t len = strlen (tmp->insn_name);
       struct s3_insn_to_dependency *new_i2n;
 
       new_i2n = (struct s3_insn_to_dependency *)
diff --git a/gas/config/tc-score7.c b/gas/config/tc-score7.c
index 7bf0ad6..ae15a04 100644
--- a/gas/config/tc-score7.c
+++ b/gas/config/tc-score7.c
@@ -5090,7 +5090,7 @@ s7_build_score_ops_hsh (void)
   for (i = 0; i < sizeof (s7_score_insns) / sizeof (struct s7_asm_opcode); i++)
     {
       const struct s7_asm_opcode *insn = s7_score_insns + i;
-      unsigned len = strlen (insn->template_name);
+      size_t len = strlen (insn->template_name);
       struct s7_asm_opcode *new_opcode;
       char *template_name;
       new_opcode = (struct s7_asm_opcode *)
@@ -5119,7 +5119,7 @@ s7_build_dependency_insn_hsh (void)
   for (i = 0; i < ARRAY_SIZE (s7_insn_to_dependency_table); i++)
     {
       const struct s7_insn_to_dependency *tmp = s7_insn_to_dependency_table + i;
-      unsigned len = strlen (tmp->insn_name);
+      size_t len = strlen (tmp->insn_name);
       struct s7_insn_to_dependency *new_i2d;
 
       new_i2d = (struct s7_insn_to_dependency *)
diff --git a/gas/config/tc-tic4x.c b/gas/config/tc-tic4x.c
index 7559ad5..904a68c 100644
--- a/gas/config/tc-tic4x.c
+++ b/gas/config/tc-tic4x.c
@@ -43,7 +43,6 @@
 #include "safe-ctype.h"
 #include "opcode/tic4x.h"
 #include "subsegs.h"
-#include "obstack.h"
 
 /* OK, we accept a syntax similar to the other well known C30
    assembly tools.  With TIC4X_ALT_SYNTAX defined we are more
diff --git a/gas/configure.ac b/gas/configure.ac
index cc4fc54..5a93d82 100644
--- a/gas/configure.ac
+++ b/gas/configure.ac
@@ -735,6 +735,10 @@ dnl AC_C_CONST
 AC_FUNC_ALLOCA
 AC_C_INLINE
 
+# Determine the size of int and size_t for obstack.h.
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([size_t])
+
 # VMS doesn't have unlink.
 AC_CHECK_FUNCS(unlink remove, break)
 AC_CHECK_FUNCS(sbrk setlocale)
diff --git a/gas/expr.c b/gas/expr.c
index b39c70d..eb7255f 100644
--- a/gas/expr.c
+++ b/gas/expr.c
@@ -27,7 +27,6 @@
 
 #include "as.h"
 #include "safe-ctype.h"
-#include "obstack.h"
 
 #ifdef HAVE_LIMITS_H
 #include <limits.h>
diff --git a/gas/frags.c b/gas/frags.c
index e14099d..defa853 100644
--- a/gas/frags.c
+++ b/gas/frags.c
@@ -94,12 +94,12 @@ frag_alloc (struct obstack *ob)
    do not return. Do not set up any fields of *now_frag.  */
 
 void
-frag_grow (unsigned int nchars)
+frag_grow (size_t nchars)
 {
   if (obstack_room (&frchain_now->frch_obstack) < nchars)
     {
-      long oldc;
-      long newc;
+      size_t oldc;
+      size_t newc;
 
       /* Try to allocate a bit more than needed right now.  But don't do
          this if we would waste too much memory.  Especially necessary
@@ -111,8 +111,8 @@ frag_grow (unsigned int nchars)
       newc += SIZEOF_STRUCT_FRAG;
 
       /* Check for possible overflow.  */
-      if (newc < 0)
-        as_fatal (_("can't extend frag %u chars"), nchars);
+      if (newc < nchars)
+        as_fatal (_("can't extend frag %lu chars"), (unsigned long) nchars);
 
       /* Force to allocate at least NEWC bytes, but not less than the
          default.  */
@@ -152,7 +152,7 @@ frag_grow (unsigned int nchars)
    of frchain_now.  */
 
 void
-frag_new (int old_frags_var_max_size
+frag_new (size_t old_frags_var_max_size
 	  /* Number of chars (already allocated on obstack frags) in
 	     variable_length part of frag.  */)
 {
@@ -204,7 +204,7 @@ frag_new (int old_frags_var_max_size
    frag_now_growth past the new chars.  */
 
 char *
-frag_more (int nchars)
+frag_more (size_t nchars)
 {
   register char *retval;
 
@@ -219,8 +219,8 @@ frag_more (int nchars)
    new frag.  */
 
 static void
-frag_var_init (relax_stateT type, int max_chars, int var,
-               relax_substateT subtype, symbolS *symbol, offsetT offset,
+frag_var_init (relax_stateT type, size_t max_chars, size_t var,
+	       relax_substateT subtype, symbolS *symbol, offsetT offset,
                char *opcode)
 {
   frag_now->fr_var = var;
@@ -250,8 +250,9 @@ frag_var_init (relax_stateT type, int max_chars, int var,
    to write into.  */
 
 char *
-frag_var (relax_stateT type, int max_chars, int var, relax_substateT subtype,
-	  symbolS *symbol, offsetT offset, char *opcode)
+frag_var (relax_stateT type, size_t max_chars, size_t var,
+	  relax_substateT subtype, symbolS *symbol, offsetT offset,
+	  char *opcode)
 {
   register char *retval;
 
@@ -267,7 +268,7 @@ frag_var (relax_stateT type, int max_chars, int var, relax_substateT subtype,
 	No call to frag_grow is done.  */
 
 char *
-frag_variant (relax_stateT type, int max_chars, int var,
+frag_variant (relax_stateT type, size_t max_chars, size_t var,
 	      relax_substateT subtype, symbolS *symbol, offsetT offset,
 	      char *opcode)
 {
@@ -291,7 +292,7 @@ frag_wane (register fragS *fragP)
 
 /* Return the number of bytes by which the current frag can be grown.  */
 
-int
+size_t
 frag_room (void)
 {
   return obstack_room (&frchain_now->frch_obstack);
@@ -336,7 +337,7 @@ frag_align (int alignment, int fill_character, int max)
 
 void
 frag_align_pattern (int alignment, const char *fill_pattern,
-		    int n_fill, int max)
+		    size_t n_fill, int max)
 {
   char *p;
 
diff --git a/gas/frags.h b/gas/frags.h
index 2f9e1b5..bdc3c9d 100644
--- a/gas/frags.h
+++ b/gas/frags.h
@@ -127,27 +127,27 @@ extern void frag_append_1_char (int);
 
 void frag_init (void);
 fragS *frag_alloc (struct obstack *);
-void frag_grow (unsigned int nchars);
-char *frag_more (int nchars);
+void frag_grow (size_t nchars);
+char *frag_more (size_t nchars);
 void frag_align (int alignment, int fill_character, int max);
 void frag_align_pattern (int alignment, const char *fill_pattern,
-			 int n_fill, int max);
+			 size_t n_fill, int max);
 void frag_align_code (int alignment, int max);
-void frag_new (int old_frags_var_max_size);
+void frag_new (size_t old_frags_var_max_size);
 void frag_wane (fragS * fragP);
-int frag_room (void);
+size_t frag_room (void);
 
 char *frag_variant (relax_stateT type,
-		    int max_chars,
-		    int var,
+		    size_t max_chars,
+		    size_t var,
 		    relax_substateT subtype,
 		    symbolS * symbol,
 		    offsetT offset,
 		    char *opcode);
 
 char *frag_var (relax_stateT type,
-		int max_chars,
-		int var,
+		size_t max_chars,
+		size_t var,
 		relax_substateT subtype,
 		symbolS * symbol,
 		offsetT offset,
diff --git a/gas/listing.c b/gas/listing.c
index 0192dd0..57425fe 100644
--- a/gas/listing.c
+++ b/gas/listing.c
@@ -89,7 +89,6 @@
 
 #include "as.h"
 #include "filenames.h"
-#include "obstack.h"
 #include "safe-ctype.h"
 #include "input-file.h"
 #include "subsegs.h"
diff --git a/gas/symbols.c b/gas/symbols.c
index 9da0468..6af8604 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -104,7 +104,7 @@ symbol_new (const char *name, segT segment, valueT valu, fragS *frag)
 static char *
 save_symbol_name (const char *name)
 {
-  unsigned int name_length;
+  size_t name_length;
   char *ret;
 
   name_length = strlen (name) + 1;	/* +1 for \0.  */
diff --git a/gdb/charset.c b/gdb/charset.c
index 6f413a2..05d8fee 100644
--- a/gdb/charset.c
+++ b/gdb/charset.c
@@ -503,7 +503,7 @@ convert_between_encodings (const char *from, const char *to,
       old_size = obstack_object_size (output);
       obstack_blank (output, space_request);
 
-      outp = obstack_base (output) + old_size;
+      outp = (char *) obstack_base (output) + old_size;
       outleft = space_request;
 
       r = iconv (desc, &inp, &inleft, &outp, &outleft);
diff --git a/gdb/configure.ac b/gdb/configure.ac
index a2ac15f..d53506b 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -664,6 +664,10 @@ AC_SUBST(READLINE_TEXI_INCFLAG)
 # This is typedeffed to GDB_CORE_ADDR in jit-reader.h
 TARGET_PTR=
 
+# Determine the size of int and size_t for obstack.h.
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([size_t])
+
 AC_CHECK_SIZEOF(unsigned long long)
 AC_CHECK_SIZEOF(unsigned long)
 AC_CHECK_SIZEOF(unsigned __int128)
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 3e1d6ed..93b95b3 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -208,8 +208,8 @@ cp_print_value_fields (struct type *type, struct type *real_type,
     fprintf_filtered (stream, "<No data fields>");
   else
     {
-      int statmem_obstack_initial_size = 0;
-      int stat_array_obstack_initial_size = 0;
+      size_t statmem_obstack_initial_size = 0;
+      size_t stat_array_obstack_initial_size = 0;
       struct type *vptr_basetype = NULL;
       int vptr_fieldno;
 
@@ -370,7 +370,7 @@ cp_print_value_fields (struct type *type, struct type *real_type,
 
       if (dont_print_statmem == 0)
 	{
-	  int obstack_final_size =
+	  size_t obstack_final_size =
            obstack_object_size (&dont_print_statmem_obstack);
 
 	  if (obstack_final_size > statmem_obstack_initial_size)
@@ -387,7 +387,7 @@ cp_print_value_fields (struct type *type, struct type *real_type,
 
 	  if (last_set_recurse != recurse)
 	    {
-	      int obstack_final_size =
+	      size_t obstack_final_size =
 		obstack_object_size (&dont_print_stat_array_obstack);
 	      
 	      if (obstack_final_size > stat_array_obstack_initial_size)
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index e302ebb..a66cbef 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -221,7 +221,7 @@ record_text_segment_lowaddr (bfd *abfd, asection *section, void *data)
 static void
 internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
 		     asection *section, unsigned int entries,
-		     unsigned int size, CORE_ADDR text_offset)
+		     size_t size, CORE_ADDR text_offset)
 {
   /* We will read the unwind entries into temporary memory, then
      fill in the actual unwind table.  */
@@ -320,7 +320,7 @@ static void
 read_unwind_info (struct objfile *objfile)
 {
   asection *unwind_sec, *stub_unwind_sec;
-  unsigned unwind_size, stub_unwind_size, total_size;
+  size_t unwind_size, stub_unwind_size, total_size;
   unsigned index, unwind_entries;
   unsigned stub_entries, total_entries;
   CORE_ADDR text_offset;
diff --git a/gdb/jit.c b/gdb/jit.c
index a1983c9..bc31c7a 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -637,7 +637,8 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
   struct symtab *symtab;
   struct gdb_block *gdb_block_iter, *gdb_block_iter_tmp;
   struct block *block_iter;
-  int actual_nblocks, i, blockvector_size;
+  int actual_nblocks, i;
+  size_t blockvector_size;
   CORE_ADDR begin, end;
   struct blockvector *bv;
 
@@ -650,9 +651,9 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
   /* Copy over the linetable entry if one was provided.  */
   if (stab->linetable)
     {
-      int size = ((stab->linetable->nitems - 1)
-                  * sizeof (struct linetable_entry)
-                  + sizeof (struct linetable));
+      size_t size = ((stab->linetable->nitems - 1)
+		     * sizeof (struct linetable_entry)
+		     + sizeof (struct linetable));
       LINETABLE (symtab) = obstack_alloc (&objfile->objfile_obstack, size);
       memcpy (LINETABLE (symtab), stab->linetable, size);
     }
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index de2e166..eb606fa 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -143,9 +143,11 @@ print_objfile_statistics (void)
     if (OBJSTAT (objfile, sz_strtab) > 0)
       printf_filtered (_("  Space used by a.out string tables: %d\n"),
 		       OBJSTAT (objfile, sz_strtab));
-    printf_filtered (_("  Total memory used for objfile obstack: %d\n"),
+    printf_filtered (_("  Total memory used for objfile obstack: %lu\n"),
+		     (unsigned long)
 		     obstack_memory_used (&objfile->objfile_obstack));
-    printf_filtered (_("  Total memory used for BFD obstack: %d\n"),
+    printf_filtered (_("  Total memory used for BFD obstack: %lu\n"),
+		     (unsigned long)
 		     obstack_memory_used (&objfile->per_bfd->storage_obstack));
     printf_filtered (_("  Total memory used for psymbol cache: %d\n"),
 		     bcache_memory_used (psymbol_bcache_get_bcache
diff --git a/gdb/utils.c b/gdb/utils.c
index 6f47cb0..f4cb9bc 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3096,7 +3096,7 @@ gdb_sign_extend (LONGEST value, int bit)
 void *
 hashtab_obstack_allocate (void *data, size_t size, size_t count)
 {
-  unsigned int total = size * count;
+  size_t total = size * count;
   void *ptr = obstack_alloc ((struct obstack *) data, total);
 
   memset (ptr, 0, total);
diff --git a/ld/configure.ac b/ld/configure.ac
index c81ccfe..19ab480 100644
--- a/ld/configure.ac
+++ b/ld/configure.ac
@@ -267,6 +267,10 @@ else
 fi
 AC_SUBST(STRINGIFY)
 
+# Determine the size of int and size_t for obstack.h.
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([size_t])
+
 # target-specific stuff:
 
 all_targets=
Three gcc changes for obstack update

1) Current glibc obstack.h casts the return of obstack_base() to
   void*,  with the result that a few places in gcc need a (char *)
   cast.
2) My 64-bit obstack support corrects the obstack_chunk_alloc
   parameter, which was "long", to "size_t".  This means a number of
   places in gcc currently specifying the old prototype are now wrong.
   I'd argue they are wrong anyway, since there are convenience macros
   that avoid any need for user code to type cast allocation and free
   functions.
3) An optimisation in my new obstack.h depends on SIZEOF_INT and
   SIZEOF_SIZE_T being defined, thus the config additions anywhare
   obstack.h is used.  

Bootstrapped and regression tested x86_64-linux and powerpc-linux,
with both the new obstack.{h,c} and the old versions.

I'd like to commit (1) and (2) now, leaving (3) until after the 64-bit
obstack changes go in.  OK for mainline gcc?

gcc/
	* gengtype.h (obstack_chunk_alloc, obstack_chunk_free): Remove cast.
	* coretypes.h (obstack_chunk_alloc, obstack_chunk_free): Likewise.
	(gcc_obstack_init): Use obstack_specify_allocation in place of
	_obstack_begin.
	* genautomata.c (next_sep_el): Cast result of obstack_base to (char *).
	(regexp_representation): Likewise.
	* godump.c (go_output_type): Likewise.
	* configure.ac: Check size of size_t.
	* configure: Regenerate.
	* config.in: Regenerate.
gcc/java/
	* mangle.c (finish_mangling): Cast result of obstack_base to (char *).
	* typeck.c (build_java_argument_signature): Likewise.
	(build_java_signature): Likewise.
gcc/objc/
	* objc-encoding.c (encode_array): Cast result of obstack_base.
	(encode_type): Likewise.
libcpp/
	* symtab.c (ht_create): Use obstack_specify_allocation in place of
	_obstack_begin.
	* files.c (_cpp_init_files): Likewise.
	* init.c (cpp_create_reader): Likewise.
	* identifiers.c (_cpp_init_hashtable): Likewise.
	* configure.ac: Check size of size_t.
	* configure: Regenerate.
	* config.in: Regenerate.
libvtv/
	* vtv-malloc.c: Include config.h.
	* configure.ac: Generate config.h.  Check size of int and size_t.
	* configure: Regenerate.
	* config.in: Generate.
libsanitizer/
	* configure.ac: Check size of int and size_t.
	* configure: Regenerate.
	* config.in: Regenerate.

Index: gcc/gengtype.h
===================================================================
--- gcc/gengtype.h	(revision 212477)
+++ gcc/gengtype.h	(working copy)
@@ -20,8 +20,8 @@
 #ifndef GCC_GENGTYPE_H
 #define GCC_GENGTYPE_H
 
-#define obstack_chunk_alloc    ((void *(*) (long)) xmalloc)
-#define obstack_chunk_free     ((void (*) (void *)) free)
+#define obstack_chunk_alloc    xmalloc
+#define obstack_chunk_free     free
 #define OBSTACK_CHUNK_SIZE     0
 
 /* Sets of accepted source languages like C, C++, Ada... are
Index: gcc/coretypes.h
===================================================================
--- gcc/coretypes.h	(revision 212477)
+++ gcc/coretypes.h	(working copy)
@@ -158,13 +158,13 @@ struct basic_block_def;
 typedef struct basic_block_def *basic_block;
 typedef const struct basic_block_def *const_basic_block;
 
-#define obstack_chunk_alloc	((void *(*) (long)) xmalloc)
-#define obstack_chunk_free	((void (*) (void *)) free)
+#define obstack_chunk_alloc	xmalloc
+#define obstack_chunk_free	free
 #define OBSTACK_CHUNK_SIZE	0
-#define gcc_obstack_init(OBSTACK)			\
-  _obstack_begin ((OBSTACK), OBSTACK_CHUNK_SIZE, 0,	\
-		  obstack_chunk_alloc,			\
-		  obstack_chunk_free)
+#define gcc_obstack_init(OBSTACK)				\
+  obstack_specify_allocation ((OBSTACK), OBSTACK_CHUNK_SIZE, 0,	\
+			      obstack_chunk_alloc,		\
+			      obstack_chunk_free)
 
 /* enum reg_class is target specific, so it should not appear in
    target-independent code or interfaces, like the target hook declarations
Index: gcc/genautomata.c
===================================================================
--- gcc/genautomata.c	(revision 212477)
+++ gcc/genautomata.c	(working copy)
@@ -1178,7 +1178,7 @@ next_sep_el (const char **pstr, int sep, int par_f
 	}
     }
   obstack_1grow (&irp, '\0');
-  out_str = obstack_base (&irp);
+  out_str = (char *) obstack_base (&irp);
   obstack_finish (&irp);
 
   *pstr = p;
@@ -6873,7 +6873,7 @@ regexp_representation (regexp_t regexp)
 {
   form_regexp (regexp);
   obstack_1grow (&irp, '\0');
-  return obstack_base (&irp);
+  return (char *) obstack_base (&irp);
 }
 
 /* The function frees memory allocated for last formed string
@@ -9289,7 +9289,7 @@ initiate_automaton_gen (char **argv)
   obstack_grow (&irp, STANDARD_OUTPUT_DESCRIPTION_FILE_SUFFIX,
 		strlen (STANDARD_OUTPUT_DESCRIPTION_FILE_SUFFIX) + 1);
   obstack_1grow (&irp, '\0');
-  output_description_file_name = obstack_base (&irp);
+  output_description_file_name = (char *) obstack_base (&irp);
   obstack_finish (&irp);
 }
 
Index: gcc/godump.c
===================================================================
--- gcc/godump.c	(revision 212477)
+++ gcc/godump.c	(working copy)
@@ -921,7 +921,7 @@ go_output_type (struct godump_container *container
 
   ob = &container->type_obstack;
   obstack_1grow (ob, '\0');
-  fputs (obstack_base (ob), go_dump_file);
+  fputs ((char *) obstack_base (ob), go_dump_file);
   obstack_free (ob, obstack_base (ob));
 }
 
Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac	(revision 212477)
+++ gcc/configure.ac	(working copy)
@@ -311,6 +311,7 @@ AC_CHECK_SIZEOF(short)
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
 AC_CHECK_TYPES([long long], [AC_CHECK_SIZEOF(long long)])
+AC_CHECK_SIZEOF(size_t)
 GCC_STDINT_TYPES
 if test x"$ac_cv_c_uint64_t" = x"no" -o x"$ac_cv_c_int64_t" = x"no"; then
   AC_MSG_ERROR([uint64_t or int64_t not found])
Index: gcc/java/mangle.c
===================================================================
--- gcc/java/mangle.c	(revision 212477)
+++ gcc/java/mangle.c	(working copy)
@@ -711,7 +711,7 @@ finish_mangling (void)
   compression_table = NULL_TREE;
   compression_next = 0;
   obstack_1grow (mangle_obstack, '\0');
-  result = get_identifier (obstack_base (mangle_obstack));
+  result = get_identifier ((char *) obstack_base (mangle_obstack));
   obstack_free (mangle_obstack, obstack_base (mangle_obstack));
 
   return result;
Index: gcc/java/typeck.c
===================================================================
--- gcc/java/typeck.c	(revision 212477)
+++ gcc/java/typeck.c	(working copy)
@@ -477,7 +477,7 @@ build_java_argument_signature (tree type)
 	}
       obstack_1grow (&temporary_obstack, '\0');
 
-      sig = get_identifier (obstack_base (&temporary_obstack));
+      sig = get_identifier ((char *) obstack_base (&temporary_obstack));
       TYPE_ARGUMENT_SIGNATURE (type) = sig;
       obstack_free (&temporary_obstack, obstack_base (&temporary_obstack));
     }
@@ -554,7 +554,7 @@ build_java_signature (tree type)
 	    obstack_grow0 (&temporary_obstack,
 			   IDENTIFIER_POINTER (t), IDENTIFIER_LENGTH (t));
 
-	    sig = get_identifier (obstack_base (&temporary_obstack));
+	    sig = get_identifier ((char *) obstack_base (&temporary_obstack));
 	    obstack_free (&temporary_obstack,
 			  obstack_base (&temporary_obstack));
 	  }
Index: gcc/objc/objc-encoding.c
===================================================================
--- gcc/objc/objc-encoding.c	(revision 212477)
+++ gcc/objc/objc-encoding.c	(working copy)
@@ -380,7 +380,7 @@ encode_array (tree type, int curtype, int format)
 	 identifier.
       */
       {
-	char *enc = obstack_base (&util_obstack) + curtype;
+	char *enc = (char *) obstack_base (&util_obstack) + curtype;
 	if (memchr (enc, '=',
 		    obstack_object_size (&util_obstack) - curtype) == NULL)
 	  {
@@ -729,7 +729,7 @@ encode_type (tree type, int curtype, int format)
 	 to be rearranged for compatibility with gcc-3.3.  */
       if (code == POINTER_TYPE && obstack_object_size (&util_obstack) >= 3)
 	{
-	  char *enc = obstack_base (&util_obstack) + curtype;
+	  char *enc = (char *) obstack_base (&util_obstack) + curtype;
 
 	  /* Rewrite "in const" from "nr" to "rn".  */
 	  if (curtype >= 1 && !strncmp (enc - 1, "nr", 2))
Index: libcpp/symtab.c
===================================================================
--- libcpp/symtab.c	(revision 212477)
+++ libcpp/symtab.c	(working copy)
@@ -61,9 +61,7 @@ ht_create (unsigned int order)
   table = XCNEW (cpp_hash_table);
 
   /* Strings need no alignment.  */
-  _obstack_begin (&table->stack, 0, 0,
-		  (void *(*) (long)) xmalloc,
-		  (void (*) (void *)) free);
+  obstack_specify_allocation (&table->stack, 0, 0, xmalloc, free);
 
   obstack_alignment_mask (&table->stack) = 0;
 
Index: libcpp/files.c
===================================================================
--- libcpp/files.c	(revision 212477)
+++ libcpp/files.c	(working copy)
@@ -1267,9 +1267,8 @@ _cpp_init_files (cpp_reader *pfile)
   pfile->nonexistent_file_hash = htab_create_alloc (127, htab_hash_string,
 						    nonexistent_file_hash_eq,
 						    NULL, xcalloc, free);
-  _obstack_begin (&pfile->nonexistent_file_ob, 0, 0,
-		  (void *(*) (long)) xmalloc,
-		  (void (*) (void *)) free);
+  obstack_specify_allocation (&pfile->nonexistent_file_ob, 0, 0,
+			      xmalloc, free);
 }
 
 /* Finalize everything in this source file.  */
Index: libcpp/init.c
===================================================================
--- libcpp/init.c	(revision 212477)
+++ libcpp/init.c	(working copy)
@@ -260,9 +260,7 @@ cpp_create_reader (enum c_lang lang, cpp_hash_tabl
   _cpp_expand_op_stack (pfile);
 
   /* Initialize the buffer obstack.  */
-  _obstack_begin (&pfile->buffer_ob, 0, 0,
-		  (void *(*) (long)) xmalloc,
-		  (void (*) (void *)) free);
+  obstack_specify_allocation (&pfile->buffer_ob, 0, 0, xmalloc, free);
 
   _cpp_init_files (pfile);
 
Index: libcpp/identifiers.c
===================================================================
--- libcpp/identifiers.c	(revision 212477)
+++ libcpp/identifiers.c	(working copy)
@@ -54,9 +54,7 @@ _cpp_init_hashtable (cpp_reader *pfile, cpp_hash_t
       table = ht_create (13);	/* 8K (=2^13) entries.  */
       table->alloc_node = alloc_node;
 
-      _obstack_begin (&pfile->hash_ob, 0, 0,
-		      (void *(*) (long)) xmalloc,
-		      (void (*) (void *)) free);
+      obstack_specify_allocation (&pfile->hash_ob, 0, 0, xmalloc, free);
     }
 
   table->pfile = pfile;
Index: libcpp/configure.ac
===================================================================
--- libcpp/configure.ac	(revision 212477)
+++ libcpp/configure.ac	(working copy)
@@ -71,6 +71,7 @@ fi
 AC_STRUCT_TM
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(size_t)
 define(libcpp_UNLOCKED_FUNCS, clearerr_unlocked feof_unlocked dnl
   ferror_unlocked fflush_unlocked fgetc_unlocked fgets_unlocked dnl
   fileno_unlocked fprintf_unlocked fputc_unlocked fputs_unlocked dnl
Index: libvtv/vtv_malloc.cc
===================================================================
--- libvtv/vtv_malloc.cc	(revision 212477)
+++ libvtv/vtv_malloc.cc	(working copy)
@@ -31,6 +31,7 @@
    in vtv_rts.cc.  We use the existing obstack implementation in our
    memory allocation scheme.  */
 
+#include "config.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/mman.h>
Index: libvtv/configure.ac
===================================================================
--- libvtv/configure.ac	(revision 212477)
+++ libvtv/configure.ac	(working copy)
@@ -5,6 +5,7 @@ AC_PREREQ([2.64])
 AC_INIT([GNU Vtable Verification Runtime Library], 1.0,,[libvtv])
 #AC_INIT(package-unused, version-unused, libvtv)
 AC_CONFIG_SRCDIR([vtv_rts.h])
+AC_CONFIG_HEADER([config.h])
 
 # -------
 # Options
@@ -119,6 +120,10 @@ AC_CHECK_TOOL(AS, as)
 AC_CHECK_TOOL(AR, ar)
 AC_CHECK_TOOL(RANLIB, ranlib, :)
 
+# Get size of int and size_t for obstack.h.
+AC_CHECK_SIZEOF(int)
+AC_CHECK_SIZEOF(size_t)
+
 # Configure libtool
 AC_LIBTOOL_DLOPEN
 AM_PROG_LIBTOOL
Index: libsanitizer/configure.ac
===================================================================
--- libsanitizer/configure.ac	(revision 212477)
+++ libsanitizer/configure.ac	(working copy)
@@ -76,6 +76,8 @@ esac
 AC_SUBST(enable_shared)
 AC_SUBST(enable_static)
 
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([size_t])
 AC_CHECK_SIZEOF([void *])
 
 if test "${multilib}" = "yes"; then

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]