Make obstack 64bit - to handle >2GB objects

Jan Kratochvil jan.kratochvil@redhat.com
Sat Jan 27 10:45:00 GMT 2007


Hi,

attaching proposed API change (UNTESTED).  The new interface should be
compatible in general with AFAIK only one little exception in the case of:
	printf ("%d", obstack_memory_used (&obstack));
->
	printf ("%zu", obstack_memory_used (&obstack));

The new 2.6 ABI would accept SIZE_T/PTR_INT_TYPE arguments while the legacy 2.5
ABI would be still backward compatible providing INTs for existing binaries.
The INT compatibility ABI would be a SIZE_T/PTR_INT_TYPE ABI wrapper only.

I would code the complete patch if this API/ABI change gets approved.


GDB currently fails on handling >2GB DWARF sections as it depends on glibc
obstack being currently limited to INT sized allocated objects.

While I have working GDB patch to upgrade its GDB static obstack to 64 bits
I believe the system glibc obstack should be updated anyway for other apps.
Also GDB would not have to start using its own incompatible static obstack.



Regards,
Jan
-------------- next part --------------
Index: malloc/obstack.c
===================================================================
RCS file: /cvs/glibc/libc/malloc/obstack.c,v
retrieving revision 1.30
diff -u -p -r1.30 obstack.c
--- malloc/obstack.c	11 Jan 2006 05:42:45 -0000	1.30
+++ malloc/obstack.c	22 Jan 2007 23:48:44 -0000
@@ -33,7 +33,7 @@
 /* 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
+#define OBSTACK_INTERFACE_VERSION 2
 
 /* 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
@@ -152,7 +152,7 @@ compat_symbol (libc, _obstack_compat, _o
 
 int
 _obstack_begin (struct obstack *h,
-		int size, int alignment,
+		size_t size, int alignment,
 		void *(*chunkfun) (long),
 		void (*freefun) (void *))
 {
@@ -198,7 +198,7 @@ _obstack_begin (struct obstack *h,
 }
 
 int
-_obstack_begin_1 (struct obstack *h, int size, int alignment,
+_obstack_begin_1 (struct obstack *h, size_t size, int alignment,
 		  void *(*chunkfun) (void *, long),
 		  void (*freefun) (void *, void *),
 		  void *arg)
@@ -252,7 +252,7 @@ _obstack_begin_1 (struct obstack *h, int
    to the beginning of the new one.  */
 
 void
-_obstack_newchunk (struct obstack *h, int length)
+_obstack_newchunk (struct obstack *h, PTR_INT_TYPE length)
 {
   register struct _obstack_chunk *old_chunk = h->chunk;
   register struct _obstack_chunk *new_chunk;
@@ -387,11 +387,11 @@ obstack_free (struct obstack *h, void *o
 strong_alias (obstack_free, _obstack_free)
 # endif
 
-int
+size_t
 _obstack_memory_used (struct obstack *h)
 {
   register struct _obstack_chunk* lp;
-  register int nbytes = 0;
+  register size_t nbytes = 0;
 
   for (lp = h->chunk; lp != 0; lp = lp->prev)
     {
Index: malloc/obstack.h
===================================================================
RCS file: /cvs/glibc/libc/malloc/obstack.h,v
retrieving revision 1.22
diff -u -p -r1.22 obstack.h
--- malloc/obstack.h	11 Jan 2006 05:42:41 -0000	1.22
+++ malloc/obstack.h	22 Jan 2007 23:48:45 -0000
@@ -179,13 +179,13 @@ struct obstack		/* control current objec
 
 /* 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,
+extern void _obstack_newchunk (struct obstack *, PTR_INT_TYPE);
+extern int _obstack_begin (struct obstack *, size_t, int,
 			    void *(*) (long), void (*) (void *));
-extern int _obstack_begin_1 (struct obstack *, int, int,
+extern int _obstack_begin_1 (struct obstack *, size_t, int,
 			     void *(*) (void *, long),
 			     void (*) (void *, void *), void *);
-extern int _obstack_memory_used (struct obstack *);
+extern size_t _obstack_memory_used (struct obstack *);
 
 void obstack_free (struct obstack *obstack, void *block);
 
@@ -276,7 +276,7 @@ extern int obstack_exit_failure;
 # define obstack_make_room(OBSTACK,length)				\
 __extension__								\
 ({ struct obstack *__o = (OBSTACK);					\
-   int __len = (length);						\
+   PTR_INT_TYPE __len = (length);					\
    if (__o->chunk_limit - __o->next_free < __len)			\
      _obstack_newchunk (__o, __len);					\
    (void) 0; })
@@ -292,7 +292,7 @@ __extension__								\
 # define obstack_grow(OBSTACK,where,length)				\
 __extension__								\
 ({ struct obstack *__o = (OBSTACK);					\
-   int __len = (length);						\
+   PTR_INT_TYPE __len = (length);					\
    if (__o->next_free + __len > __o->chunk_limit)			\
      _obstack_newchunk (__o, __len);					\
    memcpy (__o->next_free, where, __len);				\
@@ -302,7 +302,7 @@ __extension__								\
 # define obstack_grow0(OBSTACK,where,length)				\
 __extension__								\
 ({ struct obstack *__o = (OBSTACK);					\
-   int __len = (length);						\
+   PTR_INT_TYPE __len = (length);					\
    if (__o->next_free + __len + 1 > __o->chunk_limit)			\
      _obstack_newchunk (__o, __len + 1);				\
    memcpy (__o->next_free, where, __len);				\
@@ -353,7 +353,7 @@ __extension__								\
 # define obstack_blank(OBSTACK,length)					\
 __extension__								\
 ({ struct obstack *__o = (OBSTACK);					\
-   int __len = (length);						\
+   PTR_INT_TYPE __len = (length);					\
    if (__o->chunk_limit - __o->next_free < __len)			\
      _obstack_newchunk (__o, __len);					\
    obstack_blank_fast (__o, __len);					\


More information about the Libc-alpha mailing list