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: 647876 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rqHsy2s5Pz9sxb for ; Wed, 13 Jul 2016 22:18:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=Sqw5wsmF; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= DJu1JI9KY3b5N3qypWNZBrpYCp8GLXqf5JzRiFbrly+0ZEgWkobc8ItYtpuPmcrZ 3mjbCSKghZvfMIA0lCL/jVMl/shi0XxTdaDskfvg2dfgK5YlmKTkG8NBfbamMdRH OBqA+T9INGDAselK799hI5IOdgLExzUJKNbQq6T7UrM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=B7MTV7 NZqqtxqL/L4wVY7Szpvwg=; b=Sqw5wsmFLNtT4BavZ+rQ0Yy4yX+mW2P8qms6Mj sHWKpqF4r31Gw8DOySjnES6qzW0aHnMe1nkLuMIogzxuZwJnuedmcfXZOTNyBU5j QW6wJzdcmVoJjI/RtZMzW2oiGB0KmaRZwj9hcbw5N1AAeVpEpCh4VPRMMpTiZgY3 ZkxjQ= 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 */