From patchwork Wed Oct 19 22:14:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 59089 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 B00DD3857BB6 for ; Wed, 19 Oct 2022 22:15:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B00DD3857BB6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666217707; bh=BKenFe6ocOSZC8JE47HZabOP9N0ffaztT87FUc3mj9A=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Zr/EEcJvtW6WC7/NeCD+V6R15i7mJUxD9370MVOWTxg15jlt35bPVh8ANz7UXyuFi 6d/P7Kq6bkzGaQpV+ujoGYk6co9bLCblZKGn3yjDum2zrAQme2WZqLg96r46spe5vZ iUw+7QvYnH/99yjuh2+i5pAhHOhCFBqDd4ZmETP0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 5369D3858C83 for ; Wed, 19 Oct 2022 22:14:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5369D3858C83 Received: by mail-ot1-x334.google.com with SMTP id p24-20020a9d6958000000b00661c528849eso10333415oto.9 for ; Wed, 19 Oct 2022 15:14:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BKenFe6ocOSZC8JE47HZabOP9N0ffaztT87FUc3mj9A=; b=qKiKcNkoyyaW5Eg2821f33OiW48qt++JKatah1eBd8yKgb8fYYmWj3Mo2LVTwwwtm1 U4/aoV0ylbb6rW4VEtN62BmfkuazBO/hQfq69kGF7NfUdVhN9LkA5+zmuVVGITrJbpL9 UpsCtiO4Wz3tgcMOrStsKorg/KgWbA93Dk0+Uy7uTXMNKX0Z22n/cjiU25ztpWPo4Jte ops7/D6pftIB0zaDyQMkKJrn/4d6ek303p8nn0Qlc2qsuIlMo/oZjPWqxlOOuNiFjUd8 DjydBcnKwTc4NNqB0ViqZA/ZJKRkYk2C7ChiX4boQTO4fYlJV5ltOTPUyITiaHvokJeM joyw== X-Gm-Message-State: ACrzQf3dZjYAPOxDzkmpbqjV/gPWpwlld6XQP0B0yUb0QTVrqyfxPaV2 tx6nImsAEnrgMR67pNwqs2HScJkeIAk2LjD0 X-Google-Smtp-Source: AMsMyM4b/Kp3Kj+ZAOgiZC1zHo4uY6SErMSqkbBLNvNh5Lr1kEAgLll/DgQixhyxBiD6aq0b3aonKw== X-Received: by 2002:a05:6830:4487:b0:661:dba8:cc61 with SMTP id r7-20020a056830448700b00661dba8cc61mr5177201otv.256.1666217680329; Wed, 19 Oct 2022 15:14:40 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:7d19:f1c1:9fb4:472a:ab68]) by smtp.gmail.com with ESMTPSA id m9-20020aca5809000000b00353fe4fb4casm7137927oib.48.2022.10.19.15.14.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 15:14:39 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 02/30] linux: Consolidate dl-origin.c Date: Wed, 19 Oct 2022 19:14:05 -0300 Message-Id: <20221019221433.1082017-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019221433.1082017-1-adhemerval.zanella@linaro.org> References: <20221019221433.1082017-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Use the generic implementation as the default, since the syscall is supported by all architectures. Also cleanup some headers and remove the INTERNAL_SYSCALL_ERROR_P usage (the INTERNAL_SYSCALL_CALL macro already returns an negative value if an error occurs). --- sysdeps/unix/sysv/linux/dl-origin.c | 14 ++-- sysdeps/unix/sysv/linux/generic/dl-origin.c | 79 --------------------- 2 files changed, 5 insertions(+), 88 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/generic/dl-origin.c diff --git a/sysdeps/unix/sysv/linux/dl-origin.c b/sysdeps/unix/sysv/linux/dl-origin.c index 9a76c78648..2fd1e5f400 100644 --- a/sysdeps/unix/sysv/linux/dl-origin.c +++ b/sysdeps/unix/sysv/linux/dl-origin.c @@ -17,15 +17,11 @@ . */ #include -#include -#include -#include -#include +#include +#include #include #include -#include - /* On Linux >= 2.1 systems which have the dcache implementation we can get the path of the application from the /proc/self/exe symlink. Try this first and fall back on the generic method if necessary. */ @@ -37,9 +33,9 @@ _dl_get_origin (void) char *result; int len; - len = INTERNAL_SYSCALL_CALL (readlink, "/proc/self/exe", linkval, - sizeof (linkval)); - if (! INTERNAL_SYSCALL_ERROR_P (len) && len > 0 && linkval[0] != '[') + len = INTERNAL_SYSCALL_CALL (readlinkat, AT_FDCWD, "/proc/self/exe", + linkval, sizeof (linkval)); + if (len > 0 && linkval[0] != '[') { /* We can use this value. */ assert (linkval[0] == '/'); diff --git a/sysdeps/unix/sysv/linux/generic/dl-origin.c b/sysdeps/unix/sysv/linux/generic/dl-origin.c deleted file mode 100644 index ed3ac3570c..0000000000 --- a/sysdeps/unix/sysv/linux/generic/dl-origin.c +++ /dev/null @@ -1,79 +0,0 @@ -/* Find path of executable. - Copyright (C) 1998-2022 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 - . */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/* On Linux >= 2.1 systems which have the dcache implementation we can get - the path of the application from the /proc/self/exe symlink. Try this - first and fall back on the generic method if necessary. */ - -const char * -_dl_get_origin (void) -{ - char linkval[PATH_MAX]; - char *result; - int len; - - len = INTERNAL_SYSCALL_CALL (readlinkat, AT_FDCWD, "/proc/self/exe", - linkval, sizeof (linkval)); - if (! INTERNAL_SYSCALL_ERROR_P (len) && len > 0 && linkval[0] != '[') - { - /* We can use this value. */ - assert (linkval[0] == '/'); - while (len > 1 && linkval[len - 1] != '/') - --len; - result = (char *) malloc (len + 1); - if (result == NULL) - result = (char *) -1; - else if (len == 1) - memcpy (result, "/", 2); - else - *((char *) __mempcpy (result, linkval, len - 1)) = '\0'; - } - else - { - result = (char *) -1; - /* We use the environment variable LD_ORIGIN_PATH. If it is set make - a copy and strip out trailing slashes. */ - if (GLRO(dl_origin_path) != NULL) - { - size_t len = strlen (GLRO(dl_origin_path)); - result = (char *) malloc (len + 1); - if (result == NULL) - result = (char *) -1; - else - { - char *cp = __mempcpy (result, GLRO(dl_origin_path), len); - while (cp > result + 1 && cp[-1] == '/') - --cp; - *cp = '\0'; - } - } - } - - return result; -}