glibc 64-bit obstack support

Message ID 1406354233-7664-7-git-send-email-amodra@gmail.com
State Superseded
Headers

Commit Message

Alan Modra July 26, 2014, 5:57 a.m. UTC
  And >2G on 32-bit.

	* include/gnu-versions.h (_GNU_OBSTACK_INTERFACE_VERSION): Bump.
	* include/obstack.h: Add _obstack2_newchunk hidden proto.
	* malloc/obstack.h: Import from gnulib.
	* malloc/obstack.c: Likewise.
	* malloc/obstackv1.c: New file.
	* malloc/Makefile (routines): Add obstackv1.
	(CFLAGS-obstackv1.c): Define.
	(malloc/Versions): Add _obstack2 functions.
	* config.h.in (SIZEOF_INT, SIZEOF_SIZE_T): Add.
	* configure.in: AC_CHECK_SIZEOF int and size_t.
	* configure: Regenerate.
  

Comments

Roland McGrath July 28, 2014, 7:36 p.m. UTC | #1
This is definitely not going to make it into glibc-2.20, so you might want
to wait until we're out of release freeze to worry too much about the
glibc-oriented bits.  Meanwhile, you can iron out your other cleanups with
gnulib folks.

For glibc you need to do some more work to make the provision of
compatibility symbols clean.  The entire compatibility build needs
to be protected with a SHLIB_COMPAT test.  The compatibility symbols
need to be made unavailable at link time, using versioned_symbol macros.
  
Alan Modra July 29, 2014, 12:55 a.m. UTC | #2
On Mon, Jul 28, 2014 at 12:36:21PM -0700, Roland McGrath wrote:
> This is definitely not going to make it into glibc-2.20, so you might want
> to wait until we're out of release freeze to worry too much about the
> glibc-oriented bits.

That's fine.  I figured the patch wasn't 2.20 material.  I copied the
series to libc-alpha because patch 4/5 touches rather a lot of glibc
specific support, and I'd already posted a previous attempt to
libc-alpha to explore the possibility of switching to using size_t
without bumping __OBSTACK_INTERFACE_VERSION.

>  Meanwhile, you can iron out your other cleanups with
> gnulib folks.
> 
> For glibc you need to do some more work to make the provision of
> compatibility symbols clean.  The entire compatibility build needs
> to be protected with a SHLIB_COMPAT test.  The compatibility symbols
> need to be made unavailable at link time, using versioned_symbol macros.

Yes, I realised this after posting the patch.  I'm starting to
question my sanity in attempting to fix this obstack problem properly.
It would have been so much easier to just fix the gdb bug I ran into:

https://sourceware.org/bugzilla/show_bug.cgi?id=17133

Oh well.  At least I have a working knowledge of glibc internals that
makes it reasonably easy to fix the compat issue.  BTW, this obstack
problem has been known since at least 2007, and I suspect the main
reason it has remained unfixed is the number of hoops that need to be
negotiated before a patch can be committed..  It's not just gnulib
and glibc, but eg. to update the ancient obstack.h in libiberty, gcc,
gdb and gas all needed fixes to remove improper use of obstack
internals.

https://sourceware.org/bugzilla/show_bug.cgi?id=14483
https://bugzilla.redhat.com/show_bug.cgi?id=231832
  
Pedro Alves July 29, 2014, 10:32 a.m. UTC | #3
On 07/29/2014 01:55 AM, Alan Modra wrote:

> Oh well.  At least I have a working knowledge of glibc internals that
> makes it reasonably easy to fix the compat issue.  BTW, this obstack
> problem has been known since at least 2007, and I suspect the main
> reason it has remained unfixed is the number of hoops that need to be
> negotiated before a patch can be committed..  It's not just gnulib
> and glibc, but eg. to update the ancient obstack.h in libiberty, gcc,
> gdb and gas all needed fixes to remove improper use of obstack
> internals.

/me cheers for Alan's bravery.

Thanks a lot for working on this.

> https://sourceware.org/bugzilla/show_bug.cgi?id=14483
> https://bugzilla.redhat.com/show_bug.cgi?id=231832
  

Patch

diff --git a/config.h.in b/config.h.in
index 2dcd135..0996130 100644
--- a/config.h.in
+++ b/config.h.in
@@ -200,6 +200,12 @@ 
 /* Define if the linker defines __ehdr_start.  */
 #undef HAVE_EHDR_START
 
+/* The size of "int", as computed by sizeof.  */
+#undef SIZEOF_INT
+
+/* The size of "size_t", as computed by sizeof.  */
+#undef SIZEOF_SIZE_T
+
 /*
  */
 
diff --git a/configure.ac b/configure.ac
index 566ecb2..53ee319 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1824,6 +1824,10 @@  AC_CHECK_SIZEOF(long double, 0)
 sizeof_long_double=$ac_cv_sizeof_long_double
 AC_SUBST(sizeof_long_double)
 
+dnl Determine the size of int and size_t for obstack.h.
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([size_t],,[#include <stddef.h>])
+
 CPPUNDEFS=
 dnl Check for silly hacked compilers predefining _FORTIFY_SOURCE.
 dnl Since we are building the implementations of the fortified functions here,
diff --git a/include/gnu-versions.h b/include/gnu-versions.h
index 6ffbd47..99caf5b 100644
--- a/include/gnu-versions.h
+++ b/include/gnu-versions.h
@@ -43,7 +43,7 @@ 
    remember, if any of these versions change, the libc.so major version
    number must change too (so avoid it)!  */
 
-#define _GNU_OBSTACK_INTERFACE_VERSION	1 /* vs malloc/obstack.c */
+#define _GNU_OBSTACK_INTERFACE_VERSION	2 /* vs malloc/obstack.c */
 #define _GNU_REGEX_INTERFACE_VERSION	1 /* vs posix/regex.c */
 #define _GNU_GLOB_INTERFACE_VERSION	1 /* vs posix/glob.c */
 #define _GNU_GETOPT_INTERFACE_VERSION	2 /* vs posix/getopt.c and
diff --git a/include/obstack.h b/include/obstack.h
index 349d59b..655a853 100644
--- a/include/obstack.h
+++ b/include/obstack.h
@@ -1,3 +1,6 @@ 
 #include <malloc/obstack.h>
 
 libc_hidden_proto (_obstack_newchunk)
+#ifdef __OBSTACK_ALIAS_VER2
+libc_hidden_proto (_obstack2_newchunk)
+#endif
diff --git a/malloc/Makefile b/malloc/Makefile
index 9e93523..accc584 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -30,7 +30,7 @@  tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \
 	 tst-pvalloc tst-memalign tst-mallopt
 test-srcs = tst-mtrace
 
-routines = malloc morecore mcheck mtrace obstack
+routines = malloc morecore mcheck mtrace obstack obstackv1
 
 install-lib := libmcheck.a
 non-lib.a := libmcheck.a
@@ -104,6 +104,7 @@  include ../Rules
 
 CFLAGS-mcheck-init.c = $(PIC-ccflag)
 CFLAGS-obstack.c = $(uses-callbacks)
+CFLAGS-obstackv1.c = $(uses-callbacks)
 
 $(objpfx)libmcheck.a: $(objpfx)mcheck-init.o
 	-rm -f $@
diff --git a/malloc/Versions b/malloc/Versions
index 7ca9bdf..09fb9dd 100644
--- a/malloc/Versions
+++ b/malloc/Versions
@@ -61,6 +61,10 @@  libc {
   GLIBC_2.16 {
     aligned_alloc;
   }
+  GLIBC_2.20 {
+    _obstack2_allocated_p; _obstack2_begin; _obstack2_begin_1;
+    _obstack2_free; _obstack2_memory_used; _obstack2_newchunk;
+  }
   GLIBC_PRIVATE {
     # Internal startup hook for libpthread.
     __libc_malloc_pthread_startup;
diff --git a/malloc/obstackv1.c b/malloc/obstackv1.c
new file mode 100644
index 0000000..65e82b5
--- /dev/null
+++ b/malloc/obstackv1.c
@@ -0,0 +1,2 @@ 
+#define __OBSTACK_INTERFACE_VERSION 1
+#include "obstack.c"