From patchwork Mon Nov 15 18:27:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 47696 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7BD73857C5E for ; Mon, 15 Nov 2021 18:27:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7BD73857C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637000873; bh=T+FAWxeDq7O2aIP22r+XFlKJgJh2gDrrMw0UMSNvNVk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=erfqlqIYYbTRhH4JBcapZD3HxtmE59FjjeVS1z7UkAEt7hy85ucFxvSijNGyUScpV GnmsAHP7hOmMkpP/H7xUZvzKGYQu0PJWxgX9NaeGdzxnljFGIZ7p6xyDTF3P1TP0cM GHoE1uO8AB668f7etytWyDmpOsDiut6Qctgq7nEQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9DAEC3858405 for ; Mon, 15 Nov 2021 18:27:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9DAEC3858405 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-216-TOYIgYJsPEGh8PK0f2ntVA-1; Mon, 15 Nov 2021 13:27:19 -0500 X-MC-Unique: TOYIgYJsPEGh8PK0f2ntVA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85FBC1573D for ; Mon, 15 Nov 2021 18:27:18 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.194.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE32586B4D for ; Mon, 15 Nov 2021 18:27:17 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH] elf: Install a symbolic link to ld.so as /usr/bin/ld.so Date: Mon, 15 Nov 2021 19:27:16 +0100 Message-ID: <87ilwtff5n.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This makes ld.so features such as --preload, --audit, and --list-diagnostics more accessible to end users because they do not need to know the ABI name of the dynamic loader. A Python helper script is used to compute the symbolic link target instead of relying on ln -rs, which was added in coreutils 8.16 (released in 2012). Tested on i686-linux-gnu and x86_64-linux-gnu. Manually checked that the relative symbolic links work. --- NEWS | 4 ++++ elf/Makefile | 8 ++++++- elf/install-ld.so-symlink.py | 57 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index f10971b180..2f56f3db28 100644 --- a/NEWS +++ b/NEWS @@ -68,6 +68,10 @@ Major new features: to be used by compilers for optimizing usage of 'memcmp' when its return value is only used for its boolean status. +* A symbolic link to the dynamic linker is now installed under + /usr/bin/ld.so (or ${bindir}/ld.so if glibc is not configured with + --prefix=/usr). + Deprecated and removed features, and other changes affecting compatibility: * The r_version update in the debugger interface makes the glibc binary diff --git a/elf/Makefile b/elf/Makefile index 72004484db..99038adb6d 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -110,7 +110,7 @@ endif ifeq (yes,$(build-shared)) extra-objs = $(all-rtld-routines:%=%.os) sofini.os interp.os generated += librtld.os dl-allobjs.os ld.so ldd -install-others = $(inst_rtlddir)/$(rtld-installed-name) +install-others = $(inst_rtlddir)/$(rtld-installed-name) $(inst_bindir)/ld.so install-bin-script = ldd endif @@ -682,6 +682,12 @@ $(inst_rtlddir)/$(rtld-installed-name): $(objpfx)ld.so $(+force) $(make-target-directory) $(do-install-program) +# Creates the relative /usr/bin/ld.so symbolic link. +$(inst_bindir)/ld.so: install-ld.so-symlink.py $(+force) + $(make-target-directory) + $(PYTHON) $< --create-at=$@ --bindir=$(bindir) \ + --rtlddir=$(rtlddir) --rtld-installed-name=$(rtld-installed-name) + # Special target called by parent to install just the dynamic linker. .PHONY: ldso_install ldso_install: $(inst_rtlddir)/$(rtld-installed-name) diff --git a/elf/install-ld.so-symlink.py b/elf/install-ld.so-symlink.py new file mode 100644 index 0000000000..7c1b52d463 --- /dev/null +++ b/elf/install-ld.so-symlink.py @@ -0,0 +1,57 @@ +#!/usr/bin/python +# Installs the relative symbolic link for /usr/bin/ld.so. +# Copyright (C) 2021 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 +# . + +""" +Create a relative symbolic link for ld.so. +""" + +def main(): + """Entry point when called as the main program.""" + + import argparse + import os.path + import sys + + def get_parser(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--create-at', required=True, + help='pathname of the symbolic link to create') + parser.add_argument('--bindir', required=True, + help='Installation bindir variable') + parser.add_argument('--rtlddir', required=True, + help='ld.so installation directory') + parser.add_argument('--rtld-installed-name', required=True, + help='ld.so file name') + return parser + parser = get_parser() + args = parser.parse_args() + + symlink_path = os.path.join(args.bindir, 'ld.so') + symlink_target = os.path.join(args.rtlddir, args.rtld_installed_name) + relative_target = os.path.relpath(symlink_target, args.bindir) + print('{}: {} symbolic link pointing to {} (absolute {})'.format( + args.create_at, symlink_path, relative_target, symlink_target)) + try: + os.unlink(args.create_at) + except: + pass + os.symlink(relative_target, args.create_at) + +if __name__ == '__main__': + main()