diff mbox

[03/19] Auto-generate libc-modules.h

Message ID 1408618663-2281-4-git-send-email-siddhesh@redhat.com
State Superseded
Headers show

Commit Message

Siddhesh Poyarekar Aug. 21, 2014, 10:57 a.m. UTC
Remove libc-modules.h from the tree and auto-generate it from
soversions.i and a new file build.list.  Macros generated from
soversions.i have lower values starting from 1, while those from
build.list start from a special value MODULE_OTHER_BEGIN, which has a
high enough value (1000).  This allows us to conveniently
differentiate between the versioned libraries and other built modules,
which is needed in errno.h and netdb.h to decide whether to use an
internal symbol or an external one.

Verified that generated code remains unchanged on x86_64.

	* Makeconfig (MIN-CPPFLAGS): CPPFLAGS without libc-symbols.h
	and IN_MODULE definitions.
	(%.v.i): Use it.
	(before-compile): Add libc-modules.h.
	($(common-objpfx)libc-modules.h,
	$(common-objpfx)libc-modules.stmp): New targets.
	(common-generated): Add libc-modules.h and libc-modules.stmp.
	* build.list: New file.
	* include/libc-modules.h: Remove file.
	* scripts/gen-libc-modules.awk: New script to generate
	libc-modules.h.
	* sysdeps/unix/Makefile ($(common-objpfx)sysd-syscalls):
	Depend on libc-modules.stmp.
---
 Makeconfig                   | 39 +++++++++++++++++++++++++++++++++++----
 build.list                   | 15 +++++++++++++++
 include/libc-modules.h       | 37 -------------------------------------
 scripts/gen-libc-modules.awk | 40 ++++++++++++++++++++++++++++++++++++++++
 sysdeps/unix/Makefile        |  3 ++-
 5 files changed, 92 insertions(+), 42 deletions(-)
 create mode 100644 build.list
 delete mode 100644 include/libc-modules.h
 create mode 100644 scripts/gen-libc-modules.awk

Comments

Siddhesh Poyarekar Aug. 22, 2014, 6:42 p.m. UTC | #1
On Thu, Aug 21, 2014 at 04:27:27PM +0530, Siddhesh Poyarekar wrote:
> +# Minimal CPPFLAGS for the initial compilations, i.e. syscall stubs, %.v.i,
> +# etc.
> +MIN-CPPFLAGS = $(config-extra-cppflags) $(CPPUNDEFS) $(CPPFLAGS-config) \
> +	   $($(subdir)-CPPFLAGS) \
> +	   $(+includes) $(defines) $(sysdep-CPPFLAGS) \
> +	   $(CPPFLAGS-$(suffix $@)) \
> +	   $(foreach lib,$(libof-$(basename $(@F))) \
> +			 $(libof-$(<F)) $(libof-$(@F)),$(CPPFLAGS-$(lib))) \
> +	   $(CPPFLAGS-$(<F)) $(CPPFLAGS-$(@F)) $(CPPFLAGS-$(basename $(@F)))

This patch breaks ABI on s390x, alpha and m68k.  I've got an fix[1],
which I'll incorporate into this patch and post an update.

Siddhesh

[1] https://sourceware.org/ml/libc-alpha/2014-08/msg00386.html
diff mbox

Patch

diff --git a/Makeconfig b/Makeconfig
index 5c6de39..df26cd0 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -840,6 +840,15 @@  override CXXFLAGS = $(c++-sysincludes) \
 		    $(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
 		    $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))
 
+# Minimal CPPFLAGS for the initial compilations, i.e. syscall stubs, %.v.i,
+# etc.
+MIN-CPPFLAGS = $(config-extra-cppflags) $(CPPUNDEFS) $(CPPFLAGS-config) \
+	   $($(subdir)-CPPFLAGS) \
+	   $(+includes) $(defines) $(sysdep-CPPFLAGS) \
+	   $(CPPFLAGS-$(suffix $@)) \
+	   $(foreach lib,$(libof-$(basename $(@F))) \
+			 $(libof-$(<F)) $(libof-$(@F)),$(CPPFLAGS-$(lib))) \
+	   $(CPPFLAGS-$(<F)) $(CPPFLAGS-$(@F)) $(CPPFLAGS-$(basename $(@F)))
 # If everything is compiled with -fPIC (implicitly) we must tell this by
 # defining the PIC symbol.
 ifeq (yes,$(build-pic-default))
@@ -928,7 +937,7 @@  subdir-srcdirs = $(foreach dir,$(subdirs),\
 %.v.i: $(common-objpfx)config.h $(..)Makeconfig
 	sed '/^[ 	]*%/!s/#.*$$//;/^[ 	]*$$/d;s/^[ 	]*%/#/' \
 	    $(filter-out FORCE %.h $(..)Makeconfig,$^) \
-	| $(CC) -E -undef $(CPPFLAGS) -x assembler-with-cpp - \
+	| $(CC) -E -undef $(MIN-CPPFLAGS) -x assembler-with-cpp - \
 		   > $@T
 	mv -f $@T $@
 %.v: %.v.i
@@ -993,9 +1002,12 @@  endif
 postclean-generated += soversions.mk soversions.i \
 		       shlib-versions.v shlib-versions.v.i
 
-# Generate the header containing the names of all shared libraries.
+# Generate a header containing the names of all shared libraries and another
+# one containing macros that comprise valid values for the IN_MODULE and
+# MODULE_NAME macros..
 # We use a stamp file to avoid unnecessary recompilations.
-before-compile += $(common-objpfx)gnu/lib-names.h
+before-compile += $(common-objpfx)gnu/lib-names.h \
+		  $(common-objpfx)libc-modules.h
 ifeq ($(soversions.mk-done),t)
 $(common-objpfx)gnu/lib-names.h: $(common-objpfx)gnu/lib-names.stmp; @:
 $(common-objpfx)gnu/lib-names.stmp: $(..)scripts/lib-names.awk \
@@ -1028,9 +1040,28 @@  $(common-objpfx)gnu/lib-names.stmp: $(..)scripts/lib-names.awk \
 	} >  ${@:stmp=T}
 	$(move-if-change) ${@:stmp=T} ${@:stmp=h}
 	touch $@
+
+# Generate a header with macro definitions for use with the IS_IN macro.
+# These are the possible values for the IN_MODULE macro defined when building
+# sources, to identify which module the translation unit is going to be built
+# into.  This needs to be one of the first headers to be generated since
+# everything uses it.  We work around a one-time circular dependency with
+# sysd-rules by touching an empty header file since the sysd-rules don't use
+# the IN_MODULE macros even though it is defined in the compile command.  This
+# is only necessary the first time, i.e. when there is no
+# include/libc-modules.h.
+$(common-objpfx)libc-modules.h: $(common-objpfx)libc-modules.stmp; @:
+$(common-objpfx)libc-modules.stmp: $(..)scripts/gen-libc-modules.awk \
+				   $(common-objpfx)soversions.i \
+				   $(..)build.list
+	$(AWK) -f $^ > ${@:stmp=T}
+	$(move-if-change) ${@:stmp=T} ${@:stmp=h}
+	touch $@
+
 endif
 
-common-generated += gnu/lib-names.h gnu/lib-names.stmp
+common-generated += gnu/lib-names.h gnu/lib-names.stmp libc-modules.h \
+		    libc-modules.stmp
 
 # The name under which the run-time dynamic linker is installed.
 # We are currently going for the convention that `/lib/ld.so.1'
diff --git a/build.list b/build.list
new file mode 100644
index 0000000..eab57c7
--- /dev/null
+++ b/build.list
@@ -0,0 +1,15 @@ 
+iconvprogs
+iconvdata
+ldconfig
+lddlibc4
+libmemusage
+libSegFault
+libpcprofile
+librpcsvc
+libutil
+locale_programs
+memusagestat
+nonlib
+nscd
+extramodules
+libnldbl
diff --git a/include/libc-modules.h b/include/libc-modules.h
deleted file mode 100644
index d12fb90..0000000
--- a/include/libc-modules.h
+++ /dev/null
@@ -1,37 +0,0 @@ 
-#define MODULE_libc		1
-#define MODULE_libpthread	2
-#define MODULE_rtld		3
-#define MODULE_libdl		4
-#define MODULE_libm		5
-#define MODULE_iconvprogs	6
-#define MODULE_iconvdata	7
-#define MODULE_lddlibc4		8
-#define MODULE_locale_programs	9
-#define MODULE_memusagestat	10
-#define MODULE_libutil		12
-#define MODULE_libBrokenLocale	13
-#define MODULE_libmemusage	15
-#define MODULE_libresolv	16
-#define MODULE_libnss_db	17
-#define MODULE_libnss_files	18
-#define	MODULE_libnss_dns	19
-#define MODULE_libnss_compat	20
-#define MODULE_libnss_hesiod	21
-#define MODULE_libnss_nis	22
-#define MODULE_libnss_nisplus	23
-#define MODULE_libanl		24
-#define MODULE_librt		25
-#define MODULE_libSegFault	26
-#define MODULE_libthread_db	27
-#define MODULE_libcidn		28
-#define MODULE_libcrypt		29
-#define MODULE_libnsl		30
-#define MODULE_libpcprofile	31
-#define MODULE_librpcsvc	32
-#define MODULE_nscd		33
-#define MODULE_ldconfig 	34
-#define MODULE_libnldbl 	35
-
-/* Catch-all for test modules and other binaries.  */
-#define MODULE_nonlib		98
-#define MODULE_extramodules	99
diff --git a/scripts/gen-libc-modules.awk b/scripts/gen-libc-modules.awk
new file mode 100644
index 0000000..d3382b6
--- /dev/null
+++ b/scripts/gen-libc-modules.awk
@@ -0,0 +1,40 @@ 
+# Generate a header file that defines the MODULE_* macros for each library and
+# module we build in glibc.  The library names are pulled in from soversions.i
+# and the additional modules are mentioned one-per-line in build.list.
+BEGIN {
+  PROCINFO["sorted_in"] = "@val_type_asc"
+  shlibs = 1
+  others = 1000
+  libs["OTHERS_BEGIN"] = others++
+}
+
+# Skip over comments.
+$1 == "#" {
+  next
+}
+
+# build.list is simply one module per line.
+match (FILENAME, ".*build.list") {
+  libs[$0] = others++
+}
+
+# We have only one special case in soversions.i parsing, which is to replace ld
+# with rtld since that's what we call it throughout the sources.
+match (FILENAME, ".*soversions.i") {
+  name = $2
+  if (name == "ld")
+    name = "rtld"
+
+  if (!(name in libs)) {
+    libs[name] = shlibs++
+  }
+}
+
+# Finally, print out the header file.
+END {
+  printf ("/* AUTOGENERATED BY gen-libc-modules.awk, DO NOT EDIT.  */\n\n")
+  i = 1
+  for (l in libs) {
+    printf ("#define MODULE_%s %d\n", l, libs[l])
+  }
+}
diff --git a/sysdeps/unix/Makefile b/sysdeps/unix/Makefile
index 0e535b6..573e90d 100644
--- a/sysdeps/unix/Makefile
+++ b/sysdeps/unix/Makefile
@@ -79,7 +79,8 @@  compile-syscall = $(COMPILE.S) -o $@ -x assembler-with-cpp - \
 
 ifndef avoid-generated
 $(common-objpfx)sysd-syscalls: $(..)sysdeps/unix/make-syscalls.sh \
-			       $(wildcard $(+sysdep_dirs:%=%/syscalls.list))
+			       $(wildcard $(+sysdep_dirs:%=%/syscalls.list)) \
+			       $(common-objpfx)libc-modules.stmp
 	for dir in $(+sysdep_dirs); do \
 	  test -f $$dir/syscalls.list && \
 	  { sysdirs='$(sysdirs)' \