[RFC] Fix static-only build of glibc [BZ #20845]

Message ID 20210309205916.74906-1-carlos.seo@linaro.org
State Superseded
Headers
Series [RFC] Fix static-only build of glibc [BZ #20845] |

Commit Message

Carlos Seo March 9, 2021, 8:59 p.m. UTC
  The following patch fixes the build when configuring with '--disable-shared'.

However, a second phase for properly fixing this will be required, as the tests need to be triaged (i.e. what should be running and what should not when building with --disable-shared). My proposal is to first fix the build (this patch) and then start looking at the tests and fixing those in subsequent patches. Does that sound reasonable?

Thanks,

Carlos

--- >8 ---
This fixes the build when configuring with --disable-shared.

'make' passes on x86_64-linux-gnu, aarch64-linux-gnu and powerpc64le-linux-gnu.
---
 Makeconfig                               |  5 +---
 Makefile                                 |  4 +++
 Makerules                                |  8 +++---
 include/shlib-compat.h                   | 34 +++++++++++++-----------
 nscd/nscd.c                              |  2 +-
 nss/nss_module.c                         |  3 +++
 support/Makefile                         |  4 +++
 sysdeps/unix/sysv/linux/aarch64/Makefile |  2 --
 sysdeps/unix/sysv/linux/powerpc/Makefile |  2 --
 9 files changed, 37 insertions(+), 27 deletions(-)
  

Comments

Joseph Myers March 9, 2021, 9:33 p.m. UTC | #1
On Tue, 9 Mar 2021, Carlos Eduardo Seo via Libc-alpha wrote:

> 'make' passes on x86_64-linux-gnu, aarch64-linux-gnu and 
> powerpc64le-linux-gnu.

Another key piece of validation is that a default build, without 
--disable-shared, is unaffected.

* The installation tree should be byte-for-byte identical before and after 
this patch, at least after stripping binaries if there are otherwise 
issues with line numbers in debug info, and eliminating timestamps in .a 
files as needed.  If any differences remain, they should be clearly 
explained.

* The testsuite should also complete with unchanged results in a default 
build.
  
Florian Weimer March 15, 2021, 1:42 p.m. UTC | #2
* Carlos Eduardo Seo via Libc-alpha:

> The following patch fixes the build when configuring with '--disable-shared'.
>
> However, a second phase for properly fixing this will be required, as
> the tests need to be triaged (i.e. what should be running and what
> should not when building with --disable-shared). My proposal is to
> first fix the build (this patch) and then start looking at the tests
> and fixing those in subsequent patches. Does that sound reasonable?

Could you split this up by root cause, and mention them in the commit
message?

Some parts are easy to review, others, not so.  And for the latter
category, it would help to have some rationale for the change.

Thanks,
Florian
  
Szabolcs Nagy March 15, 2021, 2:22 p.m. UTC | #3
The 03/09/2021 17:59, Carlos Eduardo Seo via Libc-alpha wrote:
> The following patch fixes the build when configuring with '--disable-shared'.
...
> diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
> index 3f22f71bef..41b284df17 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/Makefile
> +++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
> @@ -1,9 +1,7 @@
>  ifeq ($(subdir),elf)
> -ifeq ($(build-shared),yes)
>  # This is needed for DSO loading from static binaries.
>  sysdep-dl-routines += dl-static
>  endif
> -endif
>  
>  ifeq ($(subdir),misc)
>  sysdep_headers += sys/elf.h

this one is ok to fix separately:

dl-static.o defines _dl_static_init which is used for static linking.

(i think the same problem in other targets can be fixed together,
this is a fairly obvious change.)
  
Carlos Seo March 15, 2021, 3:24 p.m. UTC | #4
> On 15 Mar 2021, at 11:22, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote:
> 
> The 03/09/2021 17:59, Carlos Eduardo Seo via Libc-alpha wrote:
>> The following patch fixes the build when configuring with '--disable-shared'.
> ...
>> diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
>> index 3f22f71bef..41b284df17 100644
>> --- a/sysdeps/unix/sysv/linux/aarch64/Makefile
>> +++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
>> @@ -1,9 +1,7 @@
>> ifeq ($(subdir),elf)
>> -ifeq ($(build-shared),yes)
>> # This is needed for DSO loading from static binaries.
>> sysdep-dl-routines += dl-static
>> endif
>> -endif
>> 
>> ifeq ($(subdir),misc)
>> sysdep_headers += sys/elf.h
> 
> this one is ok to fix separately:
> 
> dl-static.o defines _dl_static_init which is used for static linking.
> 
> (i think the same problem in other targets can be fixed together,
> this is a fairly obvious change.)

OK, I'll send a patch for this separately later today.
  
Carlos Seo March 15, 2021, 3:25 p.m. UTC | #5
> On 15 Mar 2021, at 10:42, Florian Weimer <fweimer@redhat.com> wrote:
> 
> Could you split this up by root cause, and mention them in the commit
> message?
> 
> Some parts are easy to review, others, not so.  And for the latter
> category, it would help to have some rationale for the change.
> 

OK, I'll respin this and send it again after I fix the issue Szabolcs mentioned.
  

Patch

diff --git a/Makeconfig b/Makeconfig
index 0a4811b5e5..b884de1d77 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -1092,8 +1092,6 @@  subdir-srcdirs = $(foreach dir,$(subdirs),\
 	sed '/^[ 	]*#/d;/^[ 	]*$$/d' $< > $@T
 	mv -f $@T $@
 
-ifeq (yes, $(build-shared))
-
 # To generate a header to support more than one ABI for different
 # architecture variants, the CPU/Makefile defines abi-variants to be a
 # list of names for those variants (e.g. 32 64), and, for each variant,
@@ -1176,7 +1174,6 @@  endif
 
 # Generate version maps, but wait until sysdep-subdirs is known
 ifeq ($(sysd-sorted-done),t)
-ifeq ($(build-shared),yes)
 -include $(common-objpfx)sysd-versions
 -include $(common-objpfx)Versions.mk
 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
@@ -1226,12 +1223,12 @@  $(common-objpfx)versions.stmp: $(common-objpfx)Versions.all \
 	mv -f $(common-objpfx)sysd-versionsT $(common-objpfx)sysd-versions
 	touch $@
 endif # avoid-generated
-endif # $(build-shared) = yes
 endif # sysd-sorted-done
 
 # The name under which the run-time dynamic linker is installed.
 # We are currently going for the convention that `/lib/ld.so.1'
 # names the SVR4/ELF ABI-compliant dynamic linker.
+ifeq ($(build-shared),yes)
 ifndef rtld-installed-name
 ifdef ld.so-version
 rtld-installed-name = $(ld.so-version)
diff --git a/Makefile b/Makefile
index 50f99ca611..5cd7b01340 100644
--- a/Makefile
+++ b/Makefile
@@ -583,11 +583,15 @@  endef
 # (which we do not build) that GCC-compiled programs depend on.
 
 
+ifeq (yes, $(build-shared))
 ifeq (,$(CXX))
 LINKS_DSO_PROGRAM = links-dso-program-c
 else
 LINKS_DSO_PROGRAM = links-dso-program
 endif
+else
+LINKS_DSO_PROGRAM =
+endif
 
 $(tests-container) $(addsuffix /tests,$(subdirs)) : \
 		$(objpfx)testroot.pristine/install.stamp
diff --git a/Makerules b/Makerules
index ca9885436e..52e7357d76 100644
--- a/Makerules
+++ b/Makerules
@@ -93,7 +93,6 @@  before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
 			       $(before-compile))
 
 # Even before that, we need abi-versions.h which is generated right here.
-ifeq ($(build-shared),yes)
 ifndef avoid-generated
 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
@@ -113,7 +112,6 @@  before-compile := $(common-objpfx)first-versions.h \
 $(common-objpfx)first-versions.h: $(common-objpfx)versions.stmp
 $(common-objpfx)ldbl-compat-choose.h: $(common-objpfx)versions.stmp
 endif # avoid-generated
-endif # $(build-shared) = yes
 
 ifndef avoid-generated
 ifneq (,$(CXX))
@@ -280,6 +278,7 @@  $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.py \
 vpath %.sym $(sysdirs)
 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
 
+ifeq (yes, $(build-shared))
 tests-internal += $(gen-as-const-headers:%.sym=test-as-const-%)
 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.py $(..)Makerules \
@@ -288,6 +287,7 @@  $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.py $(..)Makerules \
 	 $(PYTHON) $< --test $(filter %.sym,$^)) > $@T
 	mv -f $@T $@
 endif
+endif
 
 ifeq (yes,$(build-shared))
 # Generate the header containing the names of all shared libraries.
@@ -1049,6 +1049,7 @@  $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
 endef
 endif
 
+ifeq ($(build-shared),yes)
 ifdef libc.so-version
 # For a library specified to be version N, install three files:
 # libc.so	->	libc.so.N	(e.g. libc.so.6)
@@ -1102,7 +1103,8 @@  else
 install: $(inst_slibdir)/libc.so
 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
 	$(do-install-program)
-endif
+endif # libc.so-version
+endif # build-shared
 
 ifneq (,$(versioned))
 # Produce three sets of rules as above for all the smaller versioned libraries.
diff --git a/include/shlib-compat.h b/include/shlib-compat.h
index 28baef1ea4..af8019e43a 100644
--- a/include/shlib-compat.h
+++ b/include/shlib-compat.h
@@ -104,21 +104,6 @@ 
   _compat_symbol_unique (lib, name, _compat_symbol_unique_alias (name), \
                          version)
 
-#else
-
-/* Not compiling ELF shared libraries at all, so never any old versions.  */
-# define SHLIB_COMPAT(lib, introduced, obsoleted)	0
-
-/* No versions to worry about, just make this the global definition.  */
-# define versioned_symbol(lib, local, symbol, version) \
-  weak_alias (local, symbol)
-
-/* This should not appear outside `#if SHLIB_COMPAT (...)'.  */
-# define compat_symbol(lib, local, symbol, version) ...
-# define compat_symbol_unique(lib, name, version) ...
-
-#endif
-
 /* Use compat_symbol_reference for a reference *or* definition of a
    specific version of a symbol.  Definitions are primarily used to
    ensure tests reference the exact compat symbol required, or define an
@@ -146,4 +131,23 @@ 
    (!(ABI_##lib##_##obsoleted - 0)					      \
        || ((ABI_##lib##_##introduced - 0) < (ABI_##lib##_##obsoleted - 0)))
 
+#else
+
+/* Not compiling ELF shared libraries at all, so never any old versions.  */
+# define SHLIB_COMPAT(lib, introduced, obsoleted)	0
+
+/* No versions to worry about, just make this the global definition.  */
+# define versioned_symbol(lib, local, symbol, version) \
+  weak_alias (local, symbol)
+
+/* This should not appear outside `#if SHLIB_COMPAT (...)'.  */
+# define compat_symbol(lib, local, symbol, version) ...
+# define compat_symbol_unique(lib, name, version) ...
+
+# define compat_symbol_reference(lib, local, symbol, version)
+
+# define TEST_COMPAT(lib, introduced, obsoleted)	0
+
+#endif /* SHARED */
+
 #endif	/* shlib-compat.h */
diff --git a/nscd/nscd.c b/nscd/nscd.c
index 3ca7c522c2..359df91b4b 100644
--- a/nscd/nscd.c
+++ b/nscd/nscd.c
@@ -314,7 +314,7 @@  main (int argc, char **argv)
 # endif
 #endif
 
-#ifdef USE_NSCD
+#if defined SHARED && defined USE_NSCD
   /* Make sure we do not get recursive calls.  */
   __nss_disable_nscd (register_traced_file);
 #endif
diff --git a/nss/nss_module.c b/nss/nss_module.c
index 60c070c851..7bf0196f40 100644
--- a/nss/nss_module.c
+++ b/nss/nss_module.c
@@ -55,6 +55,9 @@  __libc_lock_define (static, nss_module_list_lock);
 static bool is_nscd;
 /* The callback passed to the init functions when nscd is used.  */
 static void (*nscd_init_cb) (size_t, struct traced_file *);
+#else
+# define is_nscd (0)
+# define nscd_init_cb (NULL)
 #endif
 
 /* Allocate the service NAME with length NAME_LENGTH.  If the service
diff --git a/support/Makefile b/support/Makefile
index 8d63fbd5da..b7079e5591 100644
--- a/support/Makefile
+++ b/support/Makefile
@@ -211,12 +211,16 @@  CFLAGS-support_paths.c = \
 # -fexcess-precision=standard.
 CFLAGS-timespec.c += -fexcess-precision=standard
 
+ifeq (yes, $(build-shared))
 ifeq (,$(CXX))
 LINKS_DSO_PROGRAM = links-dso-program-c
 else
 LINKS_DSO_PROGRAM = links-dso-program
 LDLIBS-links-dso-program = -lstdc++ -lgcc -lgcc_s $(libunwind)
 endif
+else
+LINKS_DSO_PROGRAM =
+endif
 
 ifeq (yes,$(have-selinux))
 LDLIBS-$(LINKS_DSO_PROGRAM) += -lselinux
diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
index 3f22f71bef..41b284df17 100644
--- a/sysdeps/unix/sysv/linux/aarch64/Makefile
+++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
@@ -1,9 +1,7 @@ 
 ifeq ($(subdir),elf)
-ifeq ($(build-shared),yes)
 # This is needed for DSO loading from static binaries.
 sysdep-dl-routines += dl-static
 endif
-endif
 
 ifeq ($(subdir),misc)
 sysdep_headers += sys/elf.h
diff --git a/sysdeps/unix/sysv/linux/powerpc/Makefile b/sysdeps/unix/sysv/linux/powerpc/Makefile
index a093cda68b..c567d6782a 100644
--- a/sysdeps/unix/sysv/linux/powerpc/Makefile
+++ b/sysdeps/unix/sysv/linux/powerpc/Makefile
@@ -13,10 +13,8 @@  gen-as-const-headers += ucontext_i.sym
 endif
 
 ifeq ($(subdir),elf)
-ifeq ($(build-shared),yes)
 # This is needed for DSO loading from static binaries.
 sysdep-dl-routines += dl-static
-endif
 # Otherwise tst-tls-dlinfo fails due to tst-tlsmod2.so using static tls.
 LDFLAGS-tst-tlsmod2.so += -Wl,--no-tls-get-addr-optimize
 endif