Message ID | 20220808032622.3804534-2-goldstein.w.n@gmail.com (mailing list archive) |
---|---|
State | Committed |
Commit | 483cfe1a6a33d6335b1901581b41040d2d412511 |
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> 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 924ED3858020 for <patchwork@sourceware.org>; Mon, 8 Aug 2022 03:26:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 924ED3858020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1659929214; bh=rztTGEC/ZR//vt+e9McjikR7opm/2EfCItcaWM4Iml8=; 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=soD/ERONt2fB+9EMyyaKeHMmeJ5OTBNC9pkVd7TNB1q7HQvditE7wtN5VQ6Bk6GzW npJjv7Wi5LN5RZOhgLot9RjMSOuip+9xZoRTHMGY7O6THrR92djeSKTmnOKr1FWCWY CQf0lncwiT5qm+dBYEApf3K6mQEOdj8efawVWG78= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id 582D93857360 for <libc-alpha@sourceware.org>; Mon, 8 Aug 2022 03:26:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 582D93857360 Received: by mail-pg1-x533.google.com with SMTP id q16so7488318pgq.6 for <libc-alpha@sourceware.org>; Sun, 07 Aug 2022 20:26:33 -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:cc:to:from:x-gm-message-state:from:to:cc; bh=rztTGEC/ZR//vt+e9McjikR7opm/2EfCItcaWM4Iml8=; b=kWcdxL8MoCl2Lsc15cwbn9wmD/ByNG1CVkGacYpZVTqHn4VBnLujLduxlFS4LTE13W slNIqXxU88mk/QY4/IVK9PgKiTJHO1dA0PJ9JmhL/cXiaMWO5knwzEWdxlo3U8hb26fj FIyx63AMVBAE2vGq3O1a4LYesxvOrUSOPHJZDX2kmufX4BWGAWgPnpOfNgJ2ZpXghuHv m79uSTWyP9k/GfSzM+uH0T9EP1ts0LH45/zc/FdV0qvHQL81K8RdNeb69WHNs0g3D7hu Zm9SehYcPmI7n7lvd0bguv1mP0uDbHt1YAuuIKe4SoHuCfXZ765LUQTbQt9kcxvKr+HT Tt4g== X-Gm-Message-State: ACgBeo09ibNCbR5MDnlisXpfFjL2/HfaPvFhw0U6sp8Nhwj+PH94okOI 35IEXD5TsVin1/LRl8oiUxi4+LNw9Zt7urch X-Google-Smtp-Source: AA6agR6f0hTHNiyQCMktgDk0cH0rNsSxL5W60Y2dMD/LjdY3igE1gNpatQE4VY1j9ytp7LqnxrZvSQ== X-Received: by 2002:a63:2d46:0:b0:41d:858b:52ff with SMTP id t67-20020a632d46000000b0041d858b52ffmr2346003pgt.516.1659929191671; Sun, 07 Aug 2022 20:26:31 -0700 (PDT) Received: from noah-tgl.. ([192.198.168.42]) by smtp.gmail.com with ESMTPSA id w8-20020a170902904800b0016d23e941f2sm7294579plz.258.2022.08.07.20.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 20:26:31 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v1] elf: Replace `strcpy` call with `memcpy` [BZ #29454] Date: Mon, 8 Aug 2022 11:26:22 +0800 Message-Id: <20220808032622.3804534-2-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220808032622.3804534-1-goldstein.w.n@gmail.com> References: <20220808032622.3804534-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Noah Goldstein via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Noah Goldstein <goldstein.w.n@gmail.com> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
[v1] elf: Replace `strcpy` call with `memcpy` [BZ #29454]
|
|
Checks
Context | Check | Description |
---|---|---|
dj/TryBot-apply_patch | success | Patch applied to master at the time it was sent |
dj/TryBot-32bit | success | Build for i686 |
Commit Message
Noah Goldstein
Aug. 8, 2022, 3:26 a.m. UTC
GCC normally does this optimization for us in strlen_pass::handle_builtin_strcpy but only for optimized build. To avoid needing to include strcpy.S in the rtld build to support the debug build, just do the optimization by hand. --- elf/dl-cache.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Comments
Hi, Le 08/08/2022 à 05:26, Noah Goldstein via Libc-alpha a écrit : > GCC normally does this optimization for us in > strlen_pass::handle_builtin_strcpy but only for optimized > build. To avoid needing to include strcpy.S in the rtld build to > support the debug build, just do the optimization by hand. It does fixes this build issue I had when using -Og (using gcc 11.2, on amd64): gcc -nostdlib -nostartfiles -shared -o .../build/elf/ld.so.new \ -Wl,-z,relro -Wl,-z,defs \ -Wl,-z,pack-relative-relocs \ .../build/elf/librtld.os -Wl,--version-script=.../build/ld.map \ -Wl,-soname=ld-linux-x86-64.so.2 /usr/bin/ld: .../build/elf/librtld.os: in function `_dl_load_cache_lookup': .../elf/dl-cache.c:513: undefined reference to `strcpy' collect2: error: ld returned 1 exit status make[2]: *** [Makefile:1347: .../build/elf/ld.so] Error 1 make[2]: Leaving directory '.../elf' make[1]: *** [Makefile:484: elf/subdir_lib] Error 2 make[1]: Leaving directory '...' make: *** [Makefile:9: all] Error 2 Thanks. > --- > elf/dl-cache.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/elf/dl-cache.c b/elf/dl-cache.c > index 8bbf110d02..b97c17b3a9 100644 > --- a/elf/dl-cache.c > +++ b/elf/dl-cache.c > @@ -509,8 +509,9 @@ _dl_load_cache_lookup (const char *name) > we are accessing. Therefore we must make the copy of the > mapping data without using malloc. */ > char *temp; > - temp = alloca (strlen (best) + 1); > - strcpy (temp, best); > + size_t best_len = strlen (best) + 1; > + temp = alloca (best_len); > + memcpy (temp, best, best_len); > return __strdup (temp); > } > Regards.
On Sun, Aug 7, 2022 at 8:26 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote: > > GCC normally does this optimization for us in > strlen_pass::handle_builtin_strcpy but only for optimized > build. To avoid needing to include strcpy.S in the rtld build to > support the debug build, just do the optimization by hand. > --- > elf/dl-cache.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/elf/dl-cache.c b/elf/dl-cache.c > index 8bbf110d02..b97c17b3a9 100644 > --- a/elf/dl-cache.c > +++ b/elf/dl-cache.c > @@ -509,8 +509,9 @@ _dl_load_cache_lookup (const char *name) > we are accessing. Therefore we must make the copy of the > mapping data without using malloc. */ > char *temp; > - temp = alloca (strlen (best) + 1); > - strcpy (temp, best); > + size_t best_len = strlen (best) + 1; > + temp = alloca (best_len); > + memcpy (temp, best, best_len); > return __strdup (temp); > } > > -- > 2.34.1 > LGTM. Thanks.
On Mon, Aug 8, 2022 at 10:24 PM H.J. Lu <hjl.tools@gmail.com> wrote: > > On Sun, Aug 7, 2022 at 8:26 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote: > > > > GCC normally does this optimization for us in > > strlen_pass::handle_builtin_strcpy but only for optimized > > build. To avoid needing to include strcpy.S in the rtld build to > > support the debug build, just do the optimization by hand. > > --- > > elf/dl-cache.c | 5 +++-- > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/elf/dl-cache.c b/elf/dl-cache.c > > index 8bbf110d02..b97c17b3a9 100644 > > --- a/elf/dl-cache.c > > +++ b/elf/dl-cache.c > > @@ -509,8 +509,9 @@ _dl_load_cache_lookup (const char *name) > > we are accessing. Therefore we must make the copy of the > > mapping data without using malloc. */ > > char *temp; > > - temp = alloca (strlen (best) + 1); > > - strcpy (temp, best); > > + size_t best_len = strlen (best) + 1; > > + temp = alloca (best_len); > > + memcpy (temp, best, best_len); > > return __strdup (temp); > > } > > > > -- > > 2.34.1 > > > > LGTM. > > Thanks. > > -- > H.J. Any objections to backporting this to 2.36?
diff --git a/elf/dl-cache.c b/elf/dl-cache.c index 8bbf110d02..b97c17b3a9 100644 --- a/elf/dl-cache.c +++ b/elf/dl-cache.c @@ -509,8 +509,9 @@ _dl_load_cache_lookup (const char *name) we are accessing. Therefore we must make the copy of the mapping data without using malloc. */ char *temp; - temp = alloca (strlen (best) + 1); - strcpy (temp, best); + size_t best_len = strlen (best) + 1; + temp = alloca (best_len); + memcpy (temp, best, best_len); return __strdup (temp); }