1ca5cce
commit 9f9503b56a8c7566c91d486a67be5d41792a87ca
1ca5cce
Author: Florian Weimer <fweimer@redhat.com>
1ca5cce
Date:   Wed Jul 13 14:06:00 2016 +0200
1ca5cce
1ca5cce
    sln: Install as a hard link to ldconfig
1ca5cce
    
1ca5cce
    Implementing and sln and ldconfig with the same binary saves
1ca5cce
    around 850 KiB from a glibc installation.
1ca5cce
    
1ca5cce
    The sln program is implicitly tested during the build, so no test
1ca5cce
    case is needed.
1ca5cce
c659285
Index: b/elf/Makefile
c659285
===================================================================
1ca5cce
--- a/elf/Makefile
1ca5cce
+++ b/elf/Makefile
8c898cd
@@ -97,12 +97,8 @@ install-others	= $(inst_rtlddir)/$(rtld-
1ca5cce
 install-bin-script = ldd
1ca5cce
 endif
1ca5cce
 
1ca5cce
-others		= sprof sln
1ca5cce
+others		= sprof
1ca5cce
 install-bin	= sprof
1ca5cce
-others-static   = sln
1ca5cce
-install-rootsbin = sln
1ca5cce
-sln-modules	:= static-stubs
1ca5cce
-extra-objs	+= $(sln-modules:=.o)
1ca5cce
 
1ca5cce
 ifeq (yes,$(use-ldconfig))
1ca5cce
 ifeq (yes,$(build-shared))
8c898cd
@@ -110,9 +106,17 @@ others-static	+= ldconfig
1ca5cce
 others		+= ldconfig
1ca5cce
 install-rootsbin += ldconfig
1ca5cce
 
1ca5cce
-ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon static-stubs
1ca5cce
+ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon static-stubs sln
1ca5cce
 extra-objs	+= $(ldconfig-modules:=.o)
8c898cd
 others-extras   = $(ldconfig-modules)
1ca5cce
+
1ca5cce
+# Install sln as a hard link to ldconfig.
1ca5cce
+install-others-programs += $(inst_rootsbindir)/sln
1ca5cce
+others: $(objpfx)sln
1ca5cce
+$(objpfx)sln: $(objpfx)ldconfig
1ca5cce
+	ln -f $< $@
1ca5cce
+$(inst_rootsbindir)/sln: $(inst_rootsbindir)/ldconfig
1ca5cce
+	ln -f $< $@
1ca5cce
 endif
1ca5cce
 endif
1ca5cce
 
8c898cd
@@ -548,8 +552,6 @@ $(objpfx)ldd: ldd.bash.in $(common-objpf
1ca5cce
 
1ca5cce
 $(objpfx)sprof: $(libdl)
1ca5cce
 
1ca5cce
-$(objpfx)sln: $(sln-modules:%=$(objpfx)%.o)
1ca5cce
-
1ca5cce
 $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
1ca5cce
 
1ca5cce
 SYSCONF-FLAGS := -D'SYSCONFDIR="$(sysconfdir)"'
c659285
Index: b/elf/ldconfig.c
c659285
===================================================================
1ca5cce
--- a/elf/ldconfig.c
1ca5cce
+++ b/elf/ldconfig.c
1ca5cce
@@ -44,6 +44,8 @@
1ca5cce
 
1ca5cce
 #include <dl-procinfo.h>
1ca5cce
 
1ca5cce
+#include "sln.h"
1ca5cce
+
1ca5cce
 #ifdef _DL_FIRST_PLATFORM
1ca5cce
 # define _DL_FIRST_EXTRA (_DL_FIRST_PLATFORM + _DL_PLATFORMS_COUNT)
1ca5cce
 #else
c659285
@@ -1285,6 +1287,9 @@ main (int argc, char **argv)
1ca5cce
   /* Set the text message domain.  */
1ca5cce
   textdomain (_libc_intl_domainname);
1ca5cce
 
1ca5cce
+  if (run_sln (argv[0]))
1ca5cce
+    return sln_main (argc, argv);
1ca5cce
+
1ca5cce
   /* Parse and process arguments.  */
1ca5cce
   int remaining;
1ca5cce
   argp_parse (&argp, argc, argv, 0, &remaining, NULL);
c659285
Index: b/elf/sln.c
c659285
===================================================================
1ca5cce
--- a/elf/sln.c
1ca5cce
+++ b/elf/sln.c
1ca5cce
@@ -1,4 +1,4 @@
1ca5cce
-/* `sln' program to create symbolic links between files.
1ca5cce
+/* sln helper to create symbolic links between files, invoked from ldconfig.
c659285
    Copyright (C) 1998-2017 Free Software Foundation, Inc.
1ca5cce
    This file is part of the GNU C Library.
1ca5cce
 
1ca5cce
@@ -31,21 +31,29 @@
1ca5cce
 
1ca5cce
 #include "../version.h"
1ca5cce
 
1ca5cce
-#define PACKAGE _libc_intl_domainname
1ca5cce
+#include "sln.h"
1ca5cce
 
1ca5cce
 static int makesymlink (const char *src, const char *dest);
1ca5cce
 static int makesymlinks (const char *file);
1ca5cce
 static void usage (void);
1ca5cce
 
1ca5cce
-int
1ca5cce
-main (int argc, char **argv)
1ca5cce
+/* Check if we have to run sln.  */
1ca5cce
+bool
1ca5cce
+run_sln (const char *argv0)
1ca5cce
 {
1ca5cce
-  /* Set locale via LC_ALL.  */
1ca5cce
-  setlocale (LC_ALL, "");
1ca5cce
-
1ca5cce
-  /* Set the text message domain.  */
1ca5cce
-  textdomain (PACKAGE);
1ca5cce
+  const char *slash = strrchr (argv0, '/');
1ca5cce
+  const char *progname;
1ca5cce
+  if (slash == NULL)
1ca5cce
+    progname = argv0;
1ca5cce
+  else
1ca5cce
+    progname = slash + 1;
1ca5cce
+  return strcmp (progname, "sln") == 0;
1ca5cce
+}
1ca5cce
 
1ca5cce
+/* Invoked from ldconfig.  */
1ca5cce
+int
1ca5cce
+sln_main (int argc, char **argv)
1ca5cce
+{
1ca5cce
   switch (argc)
1ca5cce
     {
1ca5cce
     case 2:
c659285
Index: b/elf/sln.h
c659285
===================================================================
1ca5cce
--- /dev/null
1ca5cce
+++ b/elf/sln.h
1ca5cce
@@ -0,0 +1,30 @@
1ca5cce
+/* Interface of the sln command-line tool.
1ca5cce
+   Copyright (C) 2016 Free Software Foundation, Inc.
1ca5cce
+   This file is part of the GNU C Library.
1ca5cce
+
1ca5cce
+   The GNU C Library is free software; you can redistribute it and/or
1ca5cce
+   modify it under the terms of the GNU Lesser General Public
1ca5cce
+   License as published by the Free Software Foundation; either
1ca5cce
+   version 2.1 of the License, or (at your option) any later version.
1ca5cce
+
1ca5cce
+   The GNU C Library is distributed in the hope that it will be useful,
1ca5cce
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
1ca5cce
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1ca5cce
+   Lesser General Public License for more details.
1ca5cce
+
1ca5cce
+   You should have received a copy of the GNU Lesser General Public
1ca5cce
+   License along with the GNU C Library; if not, see
1ca5cce
+   <http://www.gnu.org/licenses/>.  */
1ca5cce
+
1ca5cce
+#ifndef SLN_H
1ca5cce
+#define SLN_H
1ca5cce
+
1ca5cce
+#include <stdbool.h>
1ca5cce
+
1ca5cce
+/* Return true if main should invoke sln_main.  */
1ca5cce
+bool run_sln (const char *argv0);
1ca5cce
+
1ca5cce
+/* Main routine of the sln command.  */
1ca5cce
+int sln_main (int argc, char **argv);
1ca5cce
+
1ca5cce
+#endif  /* SLN_H */