From patchwork Wed Jul 13 12:17:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 13773 Received: (qmail 53661 invoked by alias); 13 Jul 2016 12:18:07 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 53584 invoked by uid 89); 13 Jul 2016 12:18:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=7012, yes, $, ifeq, sln X-HELO: mx1.redhat.com Date: Wed, 13 Jul 2016 14:17:47 +0200 To: libc-alpha@sourceware.org Subject: [PATCH] sln: Install as a hard link to ldconfig User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20160713121747.6F56A401AE80B@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) Implementing and sln and ldconfig with the same binary saves around 850 KiB from a glibc installation. The sln program is implicitly tested during the build, so no test case is needed. 2016-07-13 Florian Weimer Use the same binary for ldconfig and sln. * elf/sln.h: New file. * elf/sln.c (run_sln): New function. (PACKAGE): Remove. (sln_main): Renamed from main. * elf/ldconfig.c (main): Call sln_main if run_sln. * elf/Makefile (others): Remove sln. (others-static, install-rootsbin, sln-modules, extra-objs): Remove. (ldconfig-modules): Add sln. (install-others-programs): Likewise. (sln): Create as hard link to ldconfig. (/sbin/sln): Create as hard link to /sbin/ldconfig. diff --git a/elf/Makefile b/elf/Makefile index 593403c..38ef328 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -70,12 +70,8 @@ install-others = $(inst_rtlddir)/$(rtld-installed-name) install-bin-script = ldd endif -others = sprof sln +others = sprof install-bin = sprof -others-static = sln -install-rootsbin = sln -sln-modules := static-stubs -extra-objs += $(sln-modules:=.o) ifeq (yes,$(use-ldconfig)) ifeq (yes,$(build-shared)) @@ -83,8 +79,15 @@ others-static += ldconfig others += ldconfig install-rootsbin += ldconfig -ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon static-stubs +ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon static-stubs sln extra-objs += $(ldconfig-modules:=.o) + +# Install sln as a hard link to ldconfig. +install-others-programs += $(inst_rootsbindir)/sln +$(objpfx)sln: $(objpfx)ldconfig + ln -f $< $@ +$(inst_rootsbindir)/sln: $(inst_rootsbindir)/ldconfig + ln -f $< $@ endif endif @@ -466,8 +469,6 @@ $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \ $(objpfx)sprof: $(libdl) -$(objpfx)sln: $(sln-modules:%=$(objpfx)%.o) - $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o) SYSCONF-FLAGS := -D'SYSCONFDIR="$(sysconfdir)"' diff --git a/elf/ldconfig.c b/elf/ldconfig.c index 467ca82..972737c 100644 --- a/elf/ldconfig.c +++ b/elf/ldconfig.c @@ -44,6 +44,8 @@ #include +#include "sln.h" + #ifdef _DL_FIRST_PLATFORM # define _DL_FIRST_EXTRA (_DL_FIRST_PLATFORM + _DL_PLATFORMS_COUNT) #else @@ -1275,6 +1277,9 @@ main (int argc, char **argv) /* Set the text message domain. */ textdomain (_libc_intl_domainname); + if (run_sln (argv[0])) + return sln_main (argc, argv); + /* Parse and process arguments. */ int remaining; argp_parse (&argp, argc, argv, 0, &remaining, NULL); diff --git a/elf/sln.c b/elf/sln.c index fa4ccec..c6889d7 100644 --- a/elf/sln.c +++ b/elf/sln.c @@ -1,4 +1,4 @@ -/* `sln' program to create symbolic links between files. +/* sln helper to create symbolic links between files, invoked from ldconfig. Copyright (C) 1998-2016 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -31,21 +31,29 @@ #include "../version.h" -#define PACKAGE _libc_intl_domainname +#include "sln.h" static int makesymlink (const char *src, const char *dest); static int makesymlinks (const char *file); static void usage (void); +/* Check if we have to run sln. */ +bool +run_sln (const char *argv0) +{ + const char *slash = strrchr (argv0, '/'); + const char *progname; + if (slash == NULL) + progname = argv0; + else + progname = slash + 1; + return strcmp (progname, "sln") == 0; +} + +/* Invoked from ldconfig. */ int -main (int argc, char **argv) +sln_main (int argc, char **argv) { - /* Set locale via LC_ALL. */ - setlocale (LC_ALL, ""); - - /* Set the text message domain. */ - textdomain (PACKAGE); - switch (argc) { case 2: diff --git a/elf/sln.h b/elf/sln.h new file mode 100644 index 0000000..a3a16ab --- /dev/null +++ b/elf/sln.h @@ -0,0 +1,30 @@ +/* Interface of the sln command-line tool. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef SLN_H +#define SLN_H + +#include + +/* Return true if main should invoke sln_main. */ +bool run_sln (const char *argv0); + +/* Main routine of the sln command. */ +int sln_main (int argc, char **argv); + +#endif /* SLN_H */