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