64-bit obstack support
Alan Modra
amodra@gmail.com
Fri Jul 11 15:40:00 GMT 2014
This is a work in progress to support 64-bit obstacks.
- Get rid of "int" and "long" size parameters and vars in obstacks,
that limit obstacks to 2G on both 32-bit and 64-bit hosts.
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).
- Steal lots of fixes from glibc.
- 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.
There are two configury issues yet to resolve but I figure it's time
to get some eyes on this code. One issue is the FIXME regarding
__OBSTACK_ELIDE_CODE. The other is that I've removed the use of
gettext.h and exitfail.h since I haven't looked at what is involved in
using then yet.
Comments?
Include/
PR 17133
* obstack.h: Import current glibc file. On top of that..
Formatting. Include config.h.
(__OBSTACK_INTERFACE_VERSION): Define.
(__OBSTACK_ELIDE_CODE): Define.
(__OBSTACK_SIZE_T, __CHUNK_SIZE_T): Define.
(__PTR_INT_TYPE): Rename from PTR_INT_TYPE.
(struct obstack): Make chunk_size a __CHUNK_SIZE_T, and temp union
with size_t. Correct chunkfun prototype to take a size_t arg.
(_obstack_newchunk): Update prototype.
(_obstack_begin, _obstack_begin_1, _obstack_memory_used): Likewise.
(_obstack_free): Rename from 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): Rename __o1 to __o. Use unsigned comparision when
comparing aligned next_free against chunk_limit.
(obstack_free): Cast OBJ to remove possible const qualifier.
Call _obstack_free function.
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.
Call _obstack_free function.
libiberty/
PR 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.
(print_and_abort, obstack_alloc_failed_handler): Conditionally define.
(_obstack_compat): Likewise.
(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. Update loop for unsigned type of control var.
(obstack_free): Rename to _obstack_free.
(obstack_free): Only define alias for version 1 interface.
(_obstack_memory_used): Return and use __OBSTACK_SIZE_T local.
* obstacks.texi: Update function signatures.
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.
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.
--- glibc-current/malloc/obstack.h 2014-04-01 13:34:57.090573684 +1030
+++ binutils-gdb/include/obstack.h 2014-07-12 00:34:44.834835688 +0930
@@ -108,16 +108,62 @@
extern "C" {
#endif
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#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>
+/* FIXME: Add configury magic to also define __OBSTACK_ELIDE_CODE when
+ _GNU_OBSTACK_INTERFACE_VERSION is 1 and sizeof(size_t) == sizeof(int). */
+# if _GNU_OBSTACK_INTERFACE_VERSION == __OBSTACK_INTERFACE_VERSION
+# 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
+# ifndef __OBSTACK_ELIDE_CODE
+/* Ensure code from obstack.c doesn't get called from shared
+ libraries that want glibc OBSTACK_INTERFACE_VERSION 1 code. */
+# 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
@@ -128,16 +174,18 @@
/* Similiar 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
struct _obstack_chunk /* Lives at front of each chunk. */
{
@@ -148,21 +196,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 */
@@ -177,16 +225,14 @@
/* 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 void _obstack_free (struct obstack *, void *);
+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 *);
-
-void obstack_free (struct obstack *__obstack, void *__glibc_block);
-
+extern __OBSTACK_SIZE_T _obstack_memory_used (struct obstack *);
/* Error handler called when `obstack_chunk_alloc' failed to allocate
more memory. This can be set to a user defined function which
@@ -218,26 +264,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))
@@ -264,18 +310,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; })
@@ -290,8 +338,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; \
@@ -300,8 +348,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; \
@@ -311,7 +359,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; })
@@ -323,14 +371,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); })
@@ -351,8 +399,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; })
@@ -375,38 +423,37 @@
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->alignment_mask); \
- if (__o1->next_free - (char *) __o1->chunk \
- > __o1->chunk_limit - (char *) __o1->chunk) \
- __o1->next_free = __o1->chunk_limit; \
- __o1->object_base = __o1->next_free; \
+ ({ struct obstack *__o = (OBSTACK); \
+ void *__value = (void *) __o->object_base; \
+ if (__o->next_free == __value) \
+ __o->maybe_empty_object = 1; \
+ __o->next_free = __PTR_ALIGN (__o->object_base, __o->next_free, \
+ __o->alignment_mask); \
+ if ((size_t) (__o->next_free - (char *) __o->chunk) \
+ > (size_t) (__o->chunk_limit - (char *) __o->chunk)) \
+ __o->next_free = __o->chunk_limit; \
+ __o->object_base = __o->next_free; \
__value; })
# 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 \
@@ -419,29 +466,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))
@@ -451,7 +497,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))
@@ -462,10 +508,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)))
@@ -480,26 +526,26 @@
(((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)) \
- ? (((h)->next_free = (h)->object_base \
- = (h)->temp.tempint + (char *) (h)->chunk), 0) \
- : ((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0)))
+ ((h)->temp.p = (void *) (obj), \
+ (((h)->temp.p > (void *) __o->chunk \
+ && (h)->temp.p < (void *) (h)->chunk_limit) \
+ ? ((h)->next_free = (h)->object_base = (char *) (h)->temp.p, 0) \
+ : (_obstack_free ((h), (h)->temp.p), 0)))
+
#endif /* not __GNUC__ */
#ifdef __cplusplus
} /* C++ */
#endif
-#endif /* obstack.h */
+
+#endif /* _OBSTACK_H */
--- glibc-current/malloc/obstack.c 2014-04-01 13:34:57.090573684 +1030
+++ binutils-gdb/libiberty/obstack.c 2014-07-12 00:21:40.594619764 +0930
@@ -28,33 +28,14 @@
# 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
-
-
# if HAVE_INTTYPES_H
# include <inttypes.h>
# endif
@@ -92,25 +73,35 @@
# endif
+# 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'. */
+
+# if (!defined _LIBC \
+ || _GNU_OBSTACK_INTERFACE_VERSION == __OBSTACK_INTERFACE_VERSION)
static void 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
@@ -129,7 +120,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 { \
@@ -148,11 +139,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 */
@@ -175,19 +169,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;
@@ -196,51 +190,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
@@ -250,14 +219,14 @@
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;
+ size_t i;
+ size_t already;
char *object_base;
/* Compute size for new chunk. */
@@ -282,8 +251,7 @@
is sufficiently aligned. */
if (h->alignment_mask + 1 >= DEFAULT_ALIGNMENT)
{
- for (i = obj_size / sizeof (COPYING_UNIT) - 1;
- i >= 0; i--)
+ for (i = obj_size / sizeof (COPYING_UNIT); i-- != 0; )
((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,
@@ -350,7 +318,7 @@
# undef obstack_free
void
-obstack_free (struct obstack *h, void *obj)
+_obstack_free (struct obstack *h, void *obj)
{
struct _obstack_chunk *lp; /* below addr of any objects in this chunk */
struct _obstack_chunk *plp; /* point to previous chunk if any */
@@ -379,33 +347,35 @@
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
@@ -435,4 +405,6 @@
# endif
exit (obstack_exit_failure);
}
-#endif /* !ELIDE_CODE */
+# endif
+
+#endif /* !__OBSTACK_ELIDE_CODE */
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/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/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..2146379 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"), 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/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..5ab2766 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -143,9 +143,9 @@ 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: %ld\n"),
obstack_memory_used (&objfile->objfile_obstack));
- printf_filtered (_(" Total memory used for BFD obstack: %d\n"),
+ printf_filtered (_(" Total memory used for BFD obstack: %ld\n"),
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);
--
Alan Modra
Australia Development Lab, IBM
More information about the Gdb
mailing list