From patchwork Tue Sep 1 20:37:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1355352 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=wFl5o0En; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BgzQl3Ym3z9sTh for ; Wed, 2 Sep 2020 06:37:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D459D395CC33; Tue, 1 Sep 2020 20:37:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D459D395CC33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1598992647; bh=TpUcdzXfVyvIX+JYgJSzclJO7JxLrm2t6o2zAwqeOv8=; 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=wFl5o0En5NLCC4B1JCPwXhrfyVo0UeBXxka8LjhNWYGXT/kSsTaFNo/LvgI2KqbUJ o34wJIthC7w969dBWKmUN5pLcS0xXB0PURL63fduJ+HyI97u3ld2Pfczg4cNj2J/e+ DfwpvzpAJkt/VIksLN8a/sqd1M/2IUj6jMSpgeNw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by sourceware.org (Postfix) with ESMTPS id 9AC7A395C820 for ; Tue, 1 Sep 2020 20:37:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9AC7A395C820 Received: by mail-qv1-xf41.google.com with SMTP id cy2so1195615qvb.0 for ; Tue, 01 Sep 2020 13:37:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TpUcdzXfVyvIX+JYgJSzclJO7JxLrm2t6o2zAwqeOv8=; b=ptFLtKnccGDuqFwUvuRqzpexxtZH3YLH9XkYc+l8o+V0Rc8vUV5GmwbZPgJoT8sOAQ XGsiKC+ilGiTV+AjHeaw59zEgXAl6t0vyOTOZruhXWyyPYllDPc/Wm+bdjrMxzTj1ZwJ idEoeKbRjvYO8vac1MuZaFN2/inFM4vx5u5TyxegIkpJVmaqzvDjDM2Y+YCgXaZPgi1b SA2DsToTVXzxLuhJprWVoR7grheF7gEoq1vpRXNea8XQyG7M97BocQNCAeqEsPBmHdxp DK2TssanqXVO073QbYK/wTWgAMhd7Sa2oPG6rDSfqDppS46eqnn2Qeis+XIapZTGKw2J 6YPg== X-Gm-Message-State: AOAM530Pgv4O4b4P3tGCl+ULX2ztDR41qyW1BirnYquT7r1eCWbTkXSe B1SzTBTeHLOWYn6I3d273ghTyGqf6OpeMQ== X-Google-Smtp-Source: ABdhPJy76nVqCgw4+S0sAiejOGQB50idueqSiyNfX8YHOuqmvfQtwHafKyRyPKYUsMD2FamxNL2NrQ== X-Received: by 2002:a0c:8f01:: with SMTP id z1mr3765845qvd.223.1598992644836; Tue, 01 Sep 2020 13:37:24 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id z29sm2940176qtj.79.2020.09.01.13.37.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 13:37:24 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 5/5] io: Reorganize the getcwd implementation Date: Tue, 1 Sep 2020 17:37:04 -0300 Message-Id: <20200901203704.172996-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200901203704.172996-1-adhemerval.zanella@linaro.org> References: <20200901203704.172996-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@sourceware.org Sender: "Libc-alpha" Changes from previous version: - Do not build the generic version for loader. --- The generic implementation uses two internal symbols: __getcwd_system (which might be overriden by the system) and __getcwd_generic (the generic implementation shared with gnulib). The Linux implementation is moved to __getcwd_system and generic POSIX implementation is moved to __getcwd_generic. This change aims to make the code sync with gnulib easier and simplify the Linux override implementation. The dl-fxstatat64 is not required anymore and adding it explicit issue a duplicate symbol in libc.so linking. Hurd still overrides the getcwd altogether and one possibility would to be move its implementation to __getcwd_system and reimplement the __getcwd_generic to be a empty one. Checked on x86_64-linux-gnu and i686-linux-gnu. --- include/unistd.h | 2 ++ io/Makefile | 2 +- sysdeps/posix/getcwd.c => io/getcwd-generic.c | 7 +---- io/getcwd-system.c | 28 +++++++++++++++++++ io/getcwd.c | 16 +++++++---- sysdeps/unix/sysv/linux/Makefile | 3 +- sysdeps/unix/sysv/linux/alpha/dl-fxstatat64.c | 1 - sysdeps/unix/sysv/linux/dl-fxstatat64.c | 1 - sysdeps/unix/sysv/linux/dl-getcwd.c | 1 - .../sysv/linux/{getcwd.c => getcwd-system.c} | 23 ++------------- .../sysv/linux/sparc/sparc64/dl-fxstatat64.c | 1 - .../sysv/linux/wordsize-64/dl-fxstatat64.c | 1 - 12 files changed, 46 insertions(+), 40 deletions(-) rename sysdeps/posix/getcwd.c => io/getcwd-generic.c (99%) create mode 100644 io/getcwd-system.c delete mode 100644 sysdeps/unix/sysv/linux/alpha/dl-fxstatat64.c delete mode 100644 sysdeps/unix/sysv/linux/dl-fxstatat64.c delete mode 100644 sysdeps/unix/sysv/linux/dl-getcwd.c rename sysdeps/unix/sysv/linux/{getcwd.c => getcwd-system.c} (76%) delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/dl-fxstatat64.c delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/dl-fxstatat64.c diff --git a/include/unistd.h b/include/unistd.h index f48da2c7a3..792cfdff0b 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -76,6 +76,8 @@ extern int __lchown (const char *__file, __uid_t __owner, __gid_t __group); extern int __chdir (const char *__path) attribute_hidden; extern int __fchdir (int __fd) attribute_hidden; +extern char *__getcwd_generic (char *__buf, size_t __size) attribute_hidden; +extern char *__getcwd_system (char *__buf, size_t __size) attribute_hidden; extern char *__getcwd (char *__buf, size_t __size); libc_hidden_proto (__getcwd) extern int __rmdir (const char *__path) attribute_hidden; diff --git a/io/Makefile b/io/Makefile index cf380f3516..57cb778790 100644 --- a/io/Makefile +++ b/io/Makefile @@ -46,7 +46,7 @@ routines := \ close dup dup2 dup3 pipe pipe2 \ creat creat64 \ chdir fchdir \ - getcwd getwd getdirname \ + getcwd getwd getcwd-system getdirname \ chown fchown lchown fchownat \ ttyname ttyname_r isatty \ link linkat symlink symlinkat readlink readlinkat \ diff --git a/sysdeps/posix/getcwd.c b/io/getcwd-generic.c similarity index 99% rename from sysdeps/posix/getcwd.c rename to io/getcwd-generic.c index 3958bcecba..3b4be6bdaa 100644 --- a/sysdeps/posix/getcwd.c +++ b/io/getcwd-generic.c @@ -153,7 +153,7 @@ getcwd_nothrow (char *buf, size_t size) if BUF is NULL, an array is allocated with 'malloc'; the array is SIZE bytes long, unless SIZE == 0, in which case it is as big as necessary. */ -GETCWD_RETURN_TYPE +char * __getcwd_generic (char *buf, size_t size) { /* Lengths of big file name components and entire file names, and a @@ -486,8 +486,3 @@ __getcwd_generic (char *buf, size_t size) } return NULL; } - -#if defined _LIBC && !defined GETCWD_RETURN_TYPE -libc_hidden_def (__getcwd) -weak_alias (__getcwd, getcwd) -#endif diff --git a/io/getcwd-system.c b/io/getcwd-system.c new file mode 100644 index 0000000000..b0ae6271ab --- /dev/null +++ b/io/getcwd-system.c @@ -0,0 +1,28 @@ +/* Architecture specific getcwd implementation. Generic implementation. + Copyright (C) 2020 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 + +/* This function is called by the generic 'getcwd' implementation to allow + a system to implement if the it provides a faster or simpler way to obtain + the current direction (e.g. through a syscall). */ +char * +__getcwd_system (char *buf, size_t size) +{ + return NULL; +} diff --git a/io/getcwd.c b/io/getcwd.c index 0fabd98131..0e0a790368 100644 --- a/io/getcwd.c +++ b/io/getcwd.c @@ -19,6 +19,11 @@ #include #include +/* The rtld does not need to handle path larger than PATH_MAX. */ +#if !IS_IN(rtld) +#include +#endif + /* Get the pathname of the current working directory, and put it in SIZE bytes of BUF. Returns NULL if the directory couldn't be determined or SIZE was too small. @@ -29,11 +34,12 @@ char * __getcwd (char *buf, size_t size) { - __set_errno (ENOSYS); - return NULL; + char *r = __getcwd_system (buf, size); +#if !IS_IN(rtld) + if (r == NULL) + r = __getcwd_generic (buf, size); +#endif + return r; } libc_hidden_def (__getcwd) weak_alias (__getcwd, getcwd) - -stub_warning (__getcwd) -stub_warning (getcwd) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 5079f33655..3abb39e865 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -281,8 +281,7 @@ tests += tst-fallocate tst-fallocate64 tst-o_path-locks endif ifeq ($(subdir),elf) -sysdep-rtld-routines += dl-brk dl-sbrk dl-getcwd dl-openat64 dl-opendir \ - dl-fxstatat64 +sysdep-rtld-routines += dl-brk dl-sbrk dl-openat64 dl-opendir libof-lddlibc4 = lddlibc4 diff --git a/sysdeps/unix/sysv/linux/alpha/dl-fxstatat64.c b/sysdeps/unix/sysv/linux/alpha/dl-fxstatat64.c deleted file mode 100644 index 330b33f7c7..0000000000 --- a/sysdeps/unix/sysv/linux/alpha/dl-fxstatat64.c +++ /dev/null @@ -1 +0,0 @@ -#include "fxstatat.c" diff --git a/sysdeps/unix/sysv/linux/dl-fxstatat64.c b/sysdeps/unix/sysv/linux/dl-fxstatat64.c deleted file mode 100644 index d229d0ea0f..0000000000 --- a/sysdeps/unix/sysv/linux/dl-fxstatat64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/dl-getcwd.c b/sysdeps/unix/sysv/linux/dl-getcwd.c deleted file mode 100644 index 4bd5657f1e..0000000000 --- a/sysdeps/unix/sysv/linux/dl-getcwd.c +++ /dev/null @@ -1 +0,0 @@ -#include "getcwd.c" diff --git a/sysdeps/unix/sysv/linux/getcwd.c b/sysdeps/unix/sysv/linux/getcwd-system.c similarity index 76% rename from sysdeps/unix/sysv/linux/getcwd.c rename to sysdeps/unix/sysv/linux/getcwd-system.c index 5ef0b092ec..571b9688cd 100644 --- a/sysdeps/unix/sysv/linux/getcwd.c +++ b/sysdeps/unix/sysv/linux/getcwd-system.c @@ -17,25 +17,13 @@ License along with the GNU C Library; if not, see . */ -#include -#include +#include #include #include -#include - #include -#include - -#if !IS_IN (rtld) -/* The generic implementation is used for valid paths larger than - PATH_MAX (where the syscall returns a positive value with errno - set to ENAMETOOLONG). */ -#define GETCWD_RETURN_TYPE static char * -#include -#endif char * -__getcwd (char *buf, size_t size) +__getcwd_system (char *buf, size_t size) { char *r = NULL; int len; @@ -73,12 +61,5 @@ __getcwd (char *buf, size_t size) if (len > 0 && r[0] == '/') return r; -#if !IS_IN (rtld) - if (len >=0 || errno == ENAMETOOLONG) - return __getcwd_generic (buf, size); -#endif - return NULL; } -libc_hidden_def (__getcwd) -weak_alias (__getcwd, getcwd) diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/dl-fxstatat64.c b/sysdeps/unix/sysv/linux/sparc/sparc64/dl-fxstatat64.c deleted file mode 100644 index 330b33f7c7..0000000000 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/dl-fxstatat64.c +++ /dev/null @@ -1 +0,0 @@ -#include "fxstatat.c" diff --git a/sysdeps/unix/sysv/linux/wordsize-64/dl-fxstatat64.c b/sysdeps/unix/sysv/linux/wordsize-64/dl-fxstatat64.c deleted file mode 100644 index 330b33f7c7..0000000000 --- a/sysdeps/unix/sysv/linux/wordsize-64/dl-fxstatat64.c +++ /dev/null @@ -1 +0,0 @@ -#include "fxstatat.c"