b1dca6
commit 9590a71adcf134c77f2d0f5711b0d6ab1b4193e6
b1dca6
Author: Florian Weimer <fweimer@redhat.com>
b1dca6
Date:   Thu Oct 8 10:57:10 2020 +0200
b1dca6
b1dca6
    elf: Move ld.so error/help output to _dl_usage
b1dca6
    
b1dca6
    Also add a comment to elf/Makefile, explaining why we cannot use
b1dca6
    config.status for autoconf template processing.
b1dca6
    
b1dca6
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
b1dca6
b1dca6
diff --git a/elf/Makefile b/elf/Makefile
b1dca6
index e2078f6bc325b7e0..e5666e5bf7817c3c 100644
b1dca6
--- a/elf/Makefile
b1dca6
+++ b/elf/Makefile
b1dca6
@@ -59,7 +59,7 @@ elide-routines.os = $(all-dl-routines) dl-support enbl-secure dl-origin \
b1dca6
 # ld.so uses those routines, plus some special stuff for being the program
b1dca6
 # interpreter and operating independent of libc.
b1dca6
 rtld-routines	= rtld $(all-dl-routines) dl-sysdep dl-environ dl-minimal \
b1dca6
-  dl-error-minimal dl-conflict dl-hwcaps
b1dca6
+  dl-error-minimal dl-conflict dl-hwcaps dl-usage
b1dca6
 all-rtld-routines = $(rtld-routines) $(sysdep-rtld-routines)
b1dca6
 
b1dca6
 CFLAGS-dl-runtime.c += -fexceptions -fasynchronous-unwind-tables
b1dca6
@@ -598,6 +598,12 @@ ldso_install: $(inst_rtlddir)/$(rtld-installed-name)
b1dca6
 endif
b1dca6
 
b1dca6
 
b1dca6
+# Workarounds for ${exec_prefix} expansion in configure variables.
b1dca6
+# config.status cannot be used directly for processing ldd.bash.in or
b1dca6
+# expanding variables such as sysconfdir because the expansion
b1dca6
+# contains the literal string ${exec_prefix}, which is not valid in C
b1dca6
+# headers or installed shell scripts.
b1dca6
+
b1dca6
 ldd-rewrite = -e 's%@RTLD@%$(rtlddir)/$(rtld-installed-name)%g' \
b1dca6
 	      -e 's%@VERSION@%$(version)%g' \
b1dca6
 	      -e 's|@PKGVERSION@|$(PKGVERSION)|g' \
b1dca6
@@ -635,6 +641,7 @@ libof-ldconfig = ldconfig
b1dca6
 CFLAGS-dl-cache.c += $(SYSCONF-FLAGS)
b1dca6
 CFLAGS-cache.c += $(SYSCONF-FLAGS)
b1dca6
 CFLAGS-rtld.c += $(SYSCONF-FLAGS)
b1dca6
+CFLAGS-dl-usage.c += $(SYSCONF-FLAGS)
b1dca6
 
b1dca6
 cpp-srcs-left := $(all-rtld-routines:=.os)
b1dca6
 lib := rtld
b1dca6
diff --git a/elf/dl-main.h b/elf/dl-main.h
b1dca6
index bcc9bcf2e8fee6e7..b01f433f9c8d9e1a 100644
b1dca6
--- a/elf/dl-main.h
b1dca6
+++ b/elf/dl-main.h
b1dca6
@@ -19,7 +19,9 @@
b1dca6
 #ifndef _DL_MAIN
b1dca6
 #define _DL_MAIN
b1dca6
 
b1dca6
+#include <ldsodefs.h>
b1dca6
 #include <limits.h>
b1dca6
+#include <stdlib.h>
b1dca6
 
b1dca6
 /* Length limits for names and paths, to protect the dynamic linker,
b1dca6
    particularly when __libc_enable_secure is active.  */
b1dca6
@@ -95,4 +97,7 @@ call_init_paths (const struct dl_main_state *state)
b1dca6
   _dl_init_paths (state->library_path);
b1dca6
 }
b1dca6
 
b1dca6
+/* Print ld.so usage information and exit.  */
b1dca6
+_Noreturn void _dl_usage (void) attribute_hidden;
b1dca6
+
b1dca6
 #endif /* _DL_MAIN */
b1dca6
diff --git a/elf/dl-usage.c b/elf/dl-usage.c
b1dca6
new file mode 100644
b1dca6
index 0000000000000000..f3d89d22b71d7d12
b1dca6
--- /dev/null
b1dca6
+++ b/elf/dl-usage.c
b1dca6
@@ -0,0 +1,51 @@
b1dca6
+/* Print usage information and help for ld.so.
b1dca6
+   Copyright (C) 1995-2020 Free Software Foundation, Inc.
b1dca6
+   This file is part of the GNU C Library.
b1dca6
+
b1dca6
+   The GNU C Library is free software; you can redistribute it and/or
b1dca6
+   modify it under the terms of the GNU Lesser General Public
b1dca6
+   License as published by the Free Software Foundation; either
b1dca6
+   version 2.1 of the License, or (at your option) any later version.
b1dca6
+
b1dca6
+   The GNU C Library is distributed in the hope that it will be useful,
b1dca6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b1dca6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b1dca6
+   Lesser General Public License for more details.
b1dca6
+
b1dca6
+   You should have received a copy of the GNU Lesser General Public
b1dca6
+   License along with the GNU C Library; if not, see
b1dca6
+   <https://www.gnu.org/licenses/>.  */
b1dca6
+
b1dca6
+#include <dl-cache.h>
b1dca6
+#include <dl-main.h>
b1dca6
+#include <ldsodefs.h>
b1dca6
+
b1dca6
+void
b1dca6
+_dl_usage (void)
b1dca6
+{
b1dca6
+  _dl_fatal_printf ("\
b1dca6
+Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]\n\
b1dca6
+You have invoked `ld.so', the helper program for shared library executables.\n\
b1dca6
+This program usually lives in the file `/lib/ld.so', and special directives\n\
b1dca6
+in executable files using ELF shared libraries tell the system's program\n\
b1dca6
+loader to load the helper program from this file.  This helper program loads\n\
b1dca6
+the shared libraries needed by the program executable, prepares the program\n\
b1dca6
+to run, and runs it.  You may invoke this helper program directly from the\n\
b1dca6
+command line to load and run an ELF executable file; this is like executing\n\
b1dca6
+that file itself, but always uses this helper program from the file you\n\
b1dca6
+specified, instead of the helper program file specified in the executable\n\
b1dca6
+file you run.  This is mostly of use for maintainers to test new versions\n\
b1dca6
+of this helper program; chances are you did not intend to run this program.\n\
b1dca6
+\n\
b1dca6
+  --list                list all dependencies and how they are resolved\n\
b1dca6
+  --verify              verify that given object really is a dynamically linked\n\
b1dca6
+                        object we can handle\n\
b1dca6
+  --inhibit-cache       Do not use " LD_SO_CACHE "\n\
b1dca6
+  --library-path PATH   use given PATH instead of content of the environment\n\
b1dca6
+                        variable LD_LIBRARY_PATH\n\
b1dca6
+  --inhibit-rpath LIST  ignore RUNPATH and RPATH information in object names\n\
b1dca6
+                        in LIST\n\
b1dca6
+  --audit LIST          use objects named in LIST as auditors\n\
b1dca6
+  --preload LIST        preload objects named in LIST\n\
b1dca6
+  --argv0 STRING        set argv[0] to STRING before running\n");
b1dca6
+}
b1dca6
diff --git a/elf/rtld.c b/elf/rtld.c
b1dca6
index fbfa441bf3b050ff..a12a56b550bbc837 100644
b1dca6
--- a/elf/rtld.c
b1dca6
+++ b/elf/rtld.c
b1dca6
@@ -1240,31 +1240,7 @@ dl_main (const ElfW(Phdr) *phdr,
b1dca6
       /* If we have no further argument the program was called incorrectly.
b1dca6
 	 Grant the user some education.  */
b1dca6
       if (_dl_argc < 2)
b1dca6
-	_dl_fatal_printf ("\
b1dca6
-Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]\n\
b1dca6
-You have invoked `ld.so', the helper program for shared library executables.\n\
b1dca6
-This program usually lives in the file `/lib/ld.so', and special directives\n\
b1dca6
-in executable files using ELF shared libraries tell the system's program\n\
b1dca6
-loader to load the helper program from this file.  This helper program loads\n\
b1dca6
-the shared libraries needed by the program executable, prepares the program\n\
b1dca6
-to run, and runs it.  You may invoke this helper program directly from the\n\
b1dca6
-command line to load and run an ELF executable file; this is like executing\n\
b1dca6
-that file itself, but always uses this helper program from the file you\n\
b1dca6
-specified, instead of the helper program file specified in the executable\n\
b1dca6
-file you run.  This is mostly of use for maintainers to test new versions\n\
b1dca6
-of this helper program; chances are you did not intend to run this program.\n\
b1dca6
-\n\
b1dca6
-  --list                list all dependencies and how they are resolved\n\
b1dca6
-  --verify              verify that given object really is a dynamically linked\n\
b1dca6
-			object we can handle\n\
b1dca6
-  --inhibit-cache       Do not use " LD_SO_CACHE "\n\
b1dca6
-  --library-path PATH   use given PATH instead of content of the environment\n\
b1dca6
-			variable LD_LIBRARY_PATH\n\
b1dca6
-  --inhibit-rpath LIST  ignore RUNPATH and RPATH information in object names\n\
b1dca6
-			in LIST\n\
b1dca6
-  --audit LIST          use objects named in LIST as auditors\n\
b1dca6
-  --preload LIST        preload objects named in LIST\n\
b1dca6
-  --argv0 STRING        set argv[0] to STRING before running\n");
b1dca6
+	_dl_usage ();
b1dca6
 
b1dca6
       ++_dl_skip_args;
b1dca6
       --_dl_argc;