bca718
commit 130ac68ca25c9aa65e027e3e37337bc048205c69
bca718
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
bca718
Date:   Wed Nov 19 12:16:00 2014 +0530
bca718
bca718
    Auto-generate libc-modules.h
bca718
    
bca718
    Remove libc-modules.h from the tree and auto-generate it from
bca718
    soversions.i and the list of modules in the built-modules variable
bca718
    defined in Makeconfig.  Macros generated have increasing numbered
bca718
    values, with built-modules having lower values starting from 1,
bca718
    following which a separator value LIBS_BEGIN is added and then finally
bca718
    the library names from soversions.i are appended to the list.  This
bca718
    allows us to conveniently differentiate between the versioned
bca718
    libraries and other built modules, which is needed in errno.h and
bca718
    netdb.h to decide whether to use an internal symbol or an external
bca718
    one.
bca718
    
bca718
    Verified that generated code remains unchanged on x86_64.
bca718
    
bca718
    	* Makeconfig (built-modules): List non-library modules to be
bca718
    	built.
bca718
    	(module-cppflags): Include libc-modules.h for
bca718
    	everything except shlib-versions.v.i.
bca718
    	(CPPFLAGS): Use it.
bca718
    	(before-compile): Add libc-modules.h.
bca718
    	($(common-objpfx)libc-modules.h,
bca718
    	$(common-objpfx)libc-modules.stmp): New targets.
bca718
    	(common-generated): Add libc-modules.h and libc-modules.stmp.
bca718
    	($(common-objpfx)Versions.v.i): Depend on libc-modules.h.
bca718
    	* include/libc-symbols.h: Don't include libc-modules.h.
bca718
    	* include/libc-modules.h: Remove file.
bca718
    	* scripts/gen-libc-modules.awk: New script to generate
bca718
    	libc-modules.h.
bca718
    	* sysdeps/unix/Makefile ($(common-objpfx)sysd-syscalls):
bca718
    	Depend on libc-modules.stmp.
bca718
bca718
commit 8a257e2cb50cd8e8e3e2368d80bf325ea4086cf9
bca718
Author: Roland McGrath <roland@hack.frob.com>
bca718
Date:   Thu Apr 9 14:42:29 2015 -0700
bca718
bca718
    Omit libc-modules.h for all .v.i files.
bca718
bca718
Index: glibc-2.17-c758a686/Makeconfig
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/Makeconfig
bca718
+++ glibc-2.17-c758a686/Makeconfig
bca718
@@ -730,19 +730,34 @@ endif	# $(+cflags) == ""
bca718
 # of many little headers in the include directory.
bca718
 libio-include = -I$(..)libio
bca718
 
bca718
+# List of non-library modules that we build.
bca718
+built-modules = iconvprogs iconvdata ldconfig lddlibc4 libmemusage \
bca718
+		libSegFault libpcprofile librpcsvc locale-programs \
bca718
+		memusagestat nonlib nscd extramodules libnldbl
bca718
+
bca718
 in-module = $(subst -,_,$(firstword $(libof-$(basename $(@F))) \
bca718
 				    $(libof-$(
bca718
 				    $(libof-$(@F)) \
bca718
 				    libc))
bca718
 
bca718
+module-cppflags-real = -include $(common-objpfx)libc-modules.h \
bca718
+		       -DIN_MODULE=MODULE_$(in-module)
bca718
+
bca718
+# We don't need libc-modules.h and the MODULE_NAME definition for .v.i
bca718
+# files.  These targets don't (and will likely never need to) use the IS_IN
bca718
+# facility.  In fact, shlib-versions should not use it because that will
bca718
+# create a circular dependency as libc-modules.h is generated from
bca718
+# shlib-versions.
bca718
+module-cppflags = $(if $(filter %.v.i,$(@F)),,$(module-cppflags-real))
bca718
+
bca718
 # These are the variables that the implicit compilation rules use.
bca718
 # Note that we can't use -std=* in CPPFLAGS, because it overrides
bca718
 # the implicit -lang-asm and breaks cpp behavior for .S files--notably
bca718
 # it causes cpp to stop predefining __ASSEMBLER__.
bca718
 CPPFLAGS = $(CPPUNDEFS) $(CPPFLAGS-config) $($(subdir)-CPPFLAGS) \
bca718
-	   $(+includes) $(defines) \
bca718
+	   $(+includes) $(defines) $(module-cppflags) \
bca718
 	   -include $(..)include/libc-symbols.h $(sysdep-CPPFLAGS) \
bca718
-	   $(CPPFLAGS-$(suffix $@)) -DIN_MODULE=MODULE_$(in-module) \
bca718
+	   $(CPPFLAGS-$(suffix $@)) \
bca718
 	   $(foreach lib,$(libof-$(basename $(@F))) \
bca718
 			 $(libof-$(
bca718
 	   $(CPPFLAGS-$(
bca718
@@ -922,6 +937,23 @@ endif
bca718
 postclean-generated += soversions.mk soversions.i \
bca718
 		       shlib-versions.v shlib-versions.v.i
bca718
 
bca718
+before-compile += $(common-objpfx)libc-modules.h
bca718
+ifeq ($(soversions.mk-done),t)
bca718
+# Generate a header with macro definitions for use with the IS_IN macro.
bca718
+# These are the possible values for the IN_MODULE macro defined when building
bca718
+# sources, to identify which module the translation unit is going to be built
bca718
+# into.
bca718
+$(common-objpfx)libc-modules.h: $(common-objpfx)libc-modules.stmp; @:
bca718
+$(common-objpfx)libc-modules.stmp: $(..)scripts/gen-libc-modules.awk \
bca718
+				   $(common-objpfx)soversions.i
bca718
+	$(AWK) -v buildlist="$(subst -,_,$(built-modules))" -f $^ > ${@:stmp=T}
bca718
+	$(move-if-change) ${@:stmp=T} ${@:stmp=h}
bca718
+	touch $@
bca718
+
bca718
+endif
bca718
+
bca718
+common-generated += libc-modules.h libc-modules.stmp
bca718
+
bca718
 # Generate the header containing the names of all shared libraries.
bca718
 # We use a stamp file to avoid unnecessary recompilations.
bca718
 before-compile += $(common-objpfx)gnu/lib-names.h
bca718
Index: glibc-2.17-c758a686/include/libc-modules.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/include/libc-modules.h
bca718
+++ /dev/null
bca718
@@ -1,41 +0,0 @@
bca718
-/* Valid values for the IN_MODULE macro, which is defined for each source file
bca718
-   during compilation to indicate which module it is to be built into.
bca718
-
bca718
-   TODO: This file should eventually be auto-generated.  */
bca718
-#define MODULE_libc		1
bca718
-#define MODULE_libpthread	2
bca718
-#define MODULE_rtld		3
bca718
-#define MODULE_libdl		4
bca718
-#define MODULE_libm		5
bca718
-#define MODULE_iconvprogs	6
bca718
-#define MODULE_iconvdata	7
bca718
-#define MODULE_lddlibc4		8
bca718
-#define MODULE_locale_programs	9
bca718
-#define MODULE_memusagestat	10
bca718
-#define MODULE_libutil		12
bca718
-#define MODULE_libBrokenLocale	13
bca718
-#define MODULE_libmemusage	15
bca718
-#define MODULE_libresolv	16
bca718
-#define MODULE_libnss_db	17
bca718
-#define MODULE_libnss_files	18
bca718
-#define	MODULE_libnss_dns	19
bca718
-#define MODULE_libnss_compat	20
bca718
-#define MODULE_libnss_hesiod	21
bca718
-#define MODULE_libnss_nis	22
bca718
-#define MODULE_libnss_nisplus	23
bca718
-#define MODULE_libanl		24
bca718
-#define MODULE_librt		25
bca718
-#define MODULE_libSegFault	26
bca718
-#define MODULE_libthread_db	27
bca718
-#define MODULE_libcidn		28
bca718
-#define MODULE_libcrypt		29
bca718
-#define MODULE_libnsl		30
bca718
-#define MODULE_libpcprofile	31
bca718
-#define MODULE_librpcsvc	32
bca718
-#define MODULE_nscd		33
bca718
-#define MODULE_ldconfig 	34
bca718
-#define MODULE_libnldbl 	35
bca718
-
bca718
-/* Catch-all for test modules and other binaries.  */
bca718
-#define MODULE_nonlib		98
bca718
-#define MODULE_extramodules	99
bca718
Index: glibc-2.17-c758a686/include/libc-symbols.h
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/include/libc-symbols.h
bca718
+++ glibc-2.17-c758a686/include/libc-symbols.h
bca718
@@ -20,9 +20,6 @@
bca718
 #ifndef _LIBC_SYMBOLS_H
bca718
 #define _LIBC_SYMBOLS_H	1
bca718
 
bca718
-/* Pull in definitions for the MODULE_* macros.  */
bca718
-#include <libc-modules.h>
bca718
-
bca718
 #define IS_IN(lib) (IN_MODULE == MODULE_##lib)
bca718
 
bca718
 /* This file's macros are included implicitly in the compilation of every
bca718
Index: glibc-2.17-c758a686/scripts/gen-libc-modules.awk
bca718
===================================================================
bca718
--- /dev/null
bca718
+++ glibc-2.17-c758a686/scripts/gen-libc-modules.awk
bca718
@@ -0,0 +1,34 @@
bca718
+# Generate a header file that defines the MODULE_* macros for each library and
bca718
+# module we build in glibc.  The library names are pulled in from soversions.i
bca718
+# and the additional modules are passed in the BUILDLIST variable.
bca718
+BEGIN {
bca718
+  # BUILDLIST is set from the build-list variable in Makeconfig and is a space
bca718
+  # separated list of non-library modules that we build in glibc.
bca718
+  num = split (buildlist, libs, " ")
bca718
+  # Separate the built modules from the libraries.
bca718
+  libs[++num] = "LIBS_BEGIN"
bca718
+}
bca718
+
bca718
+# Skip over comments.
bca718
+$1 == "#" {
bca718
+  next
bca718
+}
bca718
+
bca718
+# We have only one special case in soversions.i parsing, which is to replace ld
bca718
+# with rtld since that's what we call it throughout the sources.
bca718
+match (FILENAME, ".*soversions.i") {
bca718
+  name = $2
bca718
+  if (name == "ld")
bca718
+    name = "rtld"
bca718
+
bca718
+  # Library names are not duplicated in soversions.i.
bca718
+  libs[++num] = name
bca718
+}
bca718
+
bca718
+# Finally, print out the header file.
bca718
+END {
bca718
+  printf ("/* AUTOGENERATED BY gen-libc-modules.awk, DO NOT EDIT.  */\n\n")
bca718
+  for (l in libs) {
bca718
+    printf ("#define MODULE_%s %d\n", libs[l], l)
bca718
+  }
bca718
+}
bca718
Index: glibc-2.17-c758a686/sysdeps/unix/Makefile
bca718
===================================================================
bca718
--- glibc-2.17-c758a686.orig/sysdeps/unix/Makefile
bca718
+++ glibc-2.17-c758a686/sysdeps/unix/Makefile
bca718
@@ -77,7 +77,8 @@ compile-syscall = $(COMPILE.S) -o $@ -x
bca718
 
bca718
 ifndef avoid-generated
bca718
 $(common-objpfx)sysd-syscalls: $(..)sysdeps/unix/make-syscalls.sh \
bca718
-			       $(wildcard $(+sysdep_dirs:%=%/syscalls.list))
bca718
+			       $(wildcard $(+sysdep_dirs:%=%/syscalls.list)) \
bca718
+			       $(common-objpfx)libc-modules.stmp
bca718
 	for dir in $(+sysdep_dirs); do \
bca718
 	  test -f $$dir/syscalls.list && \
bca718
 	  { sysdirs='$(sysdirs)' \