[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [patches] Cross-getconf



Joseph S. Myers wrote:

...

(It would have been very helpful if this patch submission had included a detailed explanation of what the usr/libexec/getconf files are used for and what controls how the set differs between targets and multilibs, to save me needing to work this out and write it all up as part of the review.)

Sorry, I'll try be more considerate next time.

What targets did you test this for? What targets did you compare to the results of a native build for?

Sorry for such a long delay with resubmitting the patch. I've fixed it right away but got around to properly test it only now.

This version of the patch differs only in processing of undefined _POSIX_V6_* macros (fixed as per your review):

1. First the macros are undefined,
2. then the statically defined macros are included from cross-getconf.h that is being generated from preprocessing confstr.c,
3. then the rest of the macros are defined to (-1).

The patch was tested on {i686, x86_64}-linux-gnu. For each target native and cross-compiled binaries under usr/libexec/getconf were the exactly the same [after stripping].


OK for trunk?

Thanks,

--
Maxim K.
CodeSourcery


2009-01-22  Maxim Kuvyrkov  <maxim@xxxxxxxxxxxxxxxx>

	Cross-getconf.

	* posix/confstr.c (confstr): Move code for case
	_CS_V6_WIDTH_RESTRICTED_ENVS to ...
	* posix/confstr.inc: New file.
	* posix/cross-getconf.c: New utility to mimic getconf for the
	purposes of cross-compiling EGLIBC.
	* posix/Makefile: Build cross-getconf and use it when cross-building
	EGLIBC.
Index: posix/confstr.c
===================================================================
--- posix/confstr.c	(revision 7775)
+++ posix/confstr.c	(working copy)
@@ -47,66 +47,9 @@ confstr (name, buf, len)
       break;
 
     case _CS_V6_WIDTH_RESTRICTED_ENVS:
-      /* We have to return a newline-separated list of named of
-	 programming environements in which the widths of blksize_t,
-	 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
-	 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
-	 wint_t types are no greater than the width of type long.
-
-	 Currently this means all environment which the system allows.  */
-      {
-	char restenvs[4 * sizeof "POSIX_V6_LPBIG_OFFBIG"];
-
-	string_len = 0;
-#ifndef _POSIX_V6_ILP32_OFF32
-        if (__sysconf (_SC_V6_ILP32_OFF32) > 0)
-#endif
-#if !defined _POSIX_V6_ILP32_OFF32 || _POSIX_V6_ILP32_OFF32 > 0
-          {
-            memcpy (restenvs + string_len, "POSIX_V6_ILP32_OFF32",
-                    sizeof "POSIX_V6_ILP32_OFF32" - 1);
-            string_len += sizeof "POSIX_V6_ILP32_OFF32" - 1;
-          }
-#endif
-#ifndef _POSIX_V6_ILP32_OFFBIG
-        if (__sysconf (_SC_V6_ILP32_OFFBIG) > 0)
-#endif
-#if !defined _POSIX_V6_ILP32_OFFBIG || _POSIX_V6_ILP32_OFFBIG > 0
-          {
-            if (string_len)
-              restenvs[string_len++] = '\n';
-            memcpy (restenvs + string_len, "POSIX_V6_ILP32_OFFBIG",
-                    sizeof "POSIX_V6_ILP32_OFFBIG" - 1);
-            string_len += sizeof "POSIX_V6_ILP32_OFFBIG" - 1;
-          }
-#endif
-#ifndef _POSIX_V6_LP64_OFF64
-        if (__sysconf (_SC_V6_LP64_OFF64) > 0)
-#endif
-#if !defined _POSIX_V6_LP64_OFF64 || _POSIX_V6_LP64_OFF64 > 0
-          {
-            if (string_len)
-              restenvs[string_len++] = '\n';
-            memcpy (restenvs + string_len, "POSIX_V6_LP64_OFF64",
-                    sizeof "POSIX_V6_LP64_OFF64" - 1);
-            string_len += sizeof "POSIX_V6_LP64_OFF64" - 1;
-          }
-#endif
-#ifndef _POSIX_V6_LPBIG_OFFBIG
-        if (__sysconf (_SC_V6_LPBIG_OFFBIG) > 0)
-#endif
-#if !defined _POSIX_V6_LPBIG_OFFBIG || _POSIX_V6_LPBIG_OFFBIG > 0
-          {
-            if (string_len)
-              restenvs[string_len++] = '\n';
-            memcpy (restenvs + string_len, "POSIX_V6_LPBIG_OFFBIG",
-                    sizeof "POSIX_V6_LPBIG_OFFBIG" - 1);
-            string_len += sizeof "POSIX_V6_LPBIG_OFFBIG" - 1;
-          }
-#endif
-        restenvs[string_len++] = '\0';
-	string = restenvs;
-      }
+      /* eglibc: We share code in confstr.inc with cross-getconf.c.  */
+#include "confstr.inc"
+      /* eglibc: end.  */
       break;
 
     case _CS_XBS5_ILP32_OFF32_CFLAGS:
Index: posix/confstr.inc
===================================================================
--- posix/confstr.inc	(revision 0)
+++ posix/confstr.inc	(revision 0)
@@ -0,0 +1,82 @@
+/* Copyright (C) 2008
+   Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/* eglibc: The following piece of code was extracted from
+   confstr.c to share it with cross-getconf.c.  */
+
+      /* We have to return a newline-separated list of named of
+	 programming environements in which the widths of blksize_t,
+	 cc_t, mode_t, nfds_t, pid_t, ptrdiff_t, size_t, speed_t,
+	 ssize_t, suseconds_t, tcflag_t, useconds_t, wchar_t, and
+	 wint_t types are no greater than the width of type long.
+
+	 Currently this means all environment which the system allows.  */
+      {
+	char restenvs[4 * sizeof "POSIX_V6_LPBIG_OFFBIG"];
+
+	string_len = 0;
+#ifndef _POSIX_V6_ILP32_OFF32
+        if (__sysconf (_SC_V6_ILP32_OFF32) > 0)
+#endif
+#if !defined _POSIX_V6_ILP32_OFF32 || _POSIX_V6_ILP32_OFF32 > 0
+          {
+            memcpy (restenvs + string_len, "POSIX_V6_ILP32_OFF32",
+                    sizeof "POSIX_V6_ILP32_OFF32" - 1);
+            string_len += sizeof "POSIX_V6_ILP32_OFF32" - 1;
+          }
+#endif
+#ifndef _POSIX_V6_ILP32_OFFBIG
+        if (__sysconf (_SC_V6_ILP32_OFFBIG) > 0)
+#endif
+#if !defined _POSIX_V6_ILP32_OFFBIG || _POSIX_V6_ILP32_OFFBIG > 0
+          {
+            if (string_len)
+              restenvs[string_len++] = '\n';
+            memcpy (restenvs + string_len, "POSIX_V6_ILP32_OFFBIG",
+                    sizeof "POSIX_V6_ILP32_OFFBIG" - 1);
+            string_len += sizeof "POSIX_V6_ILP32_OFFBIG" - 1;
+          }
+#endif
+#ifndef _POSIX_V6_LP64_OFF64
+        if (__sysconf (_SC_V6_LP64_OFF64) > 0)
+#endif
+#if !defined _POSIX_V6_LP64_OFF64 || _POSIX_V6_LP64_OFF64 > 0
+          {
+            if (string_len)
+              restenvs[string_len++] = '\n';
+            memcpy (restenvs + string_len, "POSIX_V6_LP64_OFF64",
+                    sizeof "POSIX_V6_LP64_OFF64" - 1);
+            string_len += sizeof "POSIX_V6_LP64_OFF64" - 1;
+          }
+#endif
+#ifndef _POSIX_V6_LPBIG_OFFBIG
+        if (__sysconf (_SC_V6_LPBIG_OFFBIG) > 0)
+#endif
+#if !defined _POSIX_V6_LPBIG_OFFBIG || _POSIX_V6_LPBIG_OFFBIG > 0
+          {
+            if (string_len)
+              restenvs[string_len++] = '\n';
+            memcpy (restenvs + string_len, "POSIX_V6_LPBIG_OFFBIG",
+                    sizeof "POSIX_V6_LPBIG_OFFBIG" - 1);
+            string_len += sizeof "POSIX_V6_LPBIG_OFFBIG" - 1;
+          }
+#endif
+        restenvs[string_len++] = '\0';
+	string = restenvs;
+      }
Index: posix/cross-getconf.c
===================================================================
--- posix/cross-getconf.c	(revision 0)
+++ posix/cross-getconf.c	(revision 0)
@@ -0,0 +1,83 @@
+/* Copyright (C) 2008 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+/* Undefine macros that should be defined in cross-getconf.h.  */
+#undef _POSIX_V6_ILP32_OFF32
+#undef _POSIX_V6_ILP32_OFFBIG
+#undef _POSIX_V6_LP64_OFF64
+#undef _POSIX_V6_LPBIG_OFFBIG
+
+#include "cross-getconf.h"
+
+/* Define macros cross-getconf.h doesn't define to (-1).
+   This will prevent using host's __sysconf in confstr.inc.  */
+#ifndef _POSIX_V6_ILP32_OFF32
+# define _POSIX_V6_ILP32_OFF32 (-1)
+#endif
+#ifndef _POSIX_V6_ILP32_OFFBIG
+# define _POSIX_V6_ILP32_OFFBIG (-1)
+#endif
+#ifndef _POSIX_V6_LP64_OFF64
+# define _POSIX_V6_LP64_OFF64 (-1)
+#endif
+#ifndef _POSIX_V6_LPBIG_OFFBIG
+# define _POSIX_V6_LPBIG_OFFBIG (-1)
+#endif
+
+/* Cross-getconf is a very simple program that assumes fixed
+   input and produces fixed output.  It handles only cases
+   that are necessary to cross-compile EGLIBC.  */
+
+void
+cross_getconf (void)
+{
+  const char *string = "";
+  size_t string_len = 1;
+
+#include "confstr.inc"
+
+  printf ("%.*s\n", (int) string_len, string);
+}
+
+int
+main (int argc, char *argv[])
+{
+  const char *getconf_dir;
+
+  if (argc != 2 || strcmp (argv[1], "_POSIX_V6_WIDTH_RESTRICTED_ENVS") != 0)
+    {
+      fprintf (stderr,
+	       "%s: the only supported argument value is "
+	       "_POSIX_V6_WIDTH_RESTRICTED_ENVS", argv[0]);
+      return 1;
+    }
+
+  getconf_dir = getenv ("GETCONF_DIR");
+  if (getconf_dir == NULL
+      || strcmp (getconf_dir, "/dev/null") != 0)
+    {
+      fprintf (stderr, "%s: GETCONF_DIR should be /dev/null\n", argv[0]);
+      return 1;
+    }
+
+  cross_getconf ();
+  return 0;
+}
Index: posix/Makefile
===================================================================
--- posix/Makefile	(revision 7775)
+++ posix/Makefile	(working copy)
@@ -341,11 +341,32 @@ $(inst_libexecdir)/getconf: $(inst_bindi
 	  mv -f $@/$$spec.new $@/$$spec; \
 	done < $(objpfx)getconf.speclist
 
-$(objpfx)getconf.speclist: $(objpfx)getconf
+# eglibc: If we are cross-compiling, build cross-getconf utility and use it
+# instead of getconf.
+
+# We moved a piece of confstr.c to confstr.inc to share the later with
+# cross-getconf.c.
+confstr.c: confstr.inc
+
 ifeq (no,$(cross-compiling))
-	LC_ALL=C GETCONF_DIR=/dev/null \
-	$(run-program-prefix) $< _POSIX_V6_WIDTH_RESTRICTED_ENVS > $@.new
+getconf-dep = $(objpfx)getconf
+getconf-cmd = $(run-program-prefix) $(objpfx)getconf
 else
-	> $@.new
+getconf-dep = $(objpfx)cross-getconf
+getconf-cmd = $(objpfx)cross-getconf
+
+# Get configuration defines for cross-getconf by preprocessing confstr.c.
+$(objpfx)cross-getconf.h: confstr.c
+	$(compile.c) -E -dM -o - | grep "define _POSIX_V6_ILP32_OFF32\|define _POSIX_V6_ILP32_OFFBIG\|define _POSIX_V6_LP64_OFF64\|define _POSIX_V6_LPBIG_OFFBIG" > $(objpfx)cross-getconf.h
+
+cross-getconf-CFLAGS = -O -I$(objpfx)
+
+$(objpfx)cross-getconf: cross-getconf.c $(objpfx)cross-getconf.h
+	$(native-compile)
 endif
+
+$(objpfx)getconf.speclist: $(getconf-dep)
+	LC_ALL=C GETCONF_DIR=/dev/null \
+		$(getconf-cmd) _POSIX_V6_WIDTH_RESTRICTED_ENVS > $@.new
 	mv -f $@.new $@
+# eglibc: end.