| Message ID | CAMe9rOq9G-5s6vm0BMTHiBDiRAjoBqH_F4XzSdb03s5rwe_GAg@mail.gmail.com |
|---|---|
| State | New |
| Headers |
Return-Path: <binutils-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 365383858408 for <patchwork@sourceware.org>; Tue, 23 Sep 2025 02:18:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 365383858408 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=IPzpNc4N X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-yx1-xb12f.google.com (mail-yx1-xb12f.google.com [IPv6:2607:f8b0:4864:20::b12f]) by sourceware.org (Postfix) with ESMTPS id 3D6F63858D1E for <binutils@sourceware.org>; Tue, 23 Sep 2025 02:16:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D6F63858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3D6F63858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758593789; cv=none; b=WbIO3OrGgZcV6HaSS/FANgP8c2pKwyJEOUVluFWBa6/QnE0z83duDQxVU8lCJ7BYOPAUJiABJatpR0EZC2aWIygZrHbepi/XV/xkCrGlZgDZF1M+FFldo4Azk6pXiGFi/J5W1QamQC40jnlSPxu/sdElf0Qe36WtFUc0IDjjfuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758593789; c=relaxed/simple; bh=VKd5Mm4g/kY3bnTXBIIlXmX0lP+TMrt7JIBSePH5cL4=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=MmXT5FFgbh7IXECRZPLI3UimtN9sCZA5zXxn5RnM4l/0BT/tbfUrWwqtCO76KxBuKO8fpMMHc4rjeAu67UDQcZBJyzIxLej9DXIz7jP+ObgICMtv1+Cim4NVc1GUiXhfM1zo9xnimKFjPVusT3jwKHYOV+7G4gk+JI3GDl5edRY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D6F63858D1E Received: by mail-yx1-xb12f.google.com with SMTP id 956f58d0204a3-6353e91a04aso1127339d50.2 for <binutils@sourceware.org>; Mon, 22 Sep 2025 19:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758593788; x=1759198588; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=GqJLtiX0N2qhSfPnWYFvcukrVhu62C8iKaYFpIkmc5g=; b=IPzpNc4NpBa8Il+Owr/SJNv+QZvb2eRA+iZ4PvTkwZ2cTKXymyMtgASkdtCyOhsiug RpBBaFeS7eafL1GlrUc2oqokWDv5QbDtjHq2wR72/MSyDNLERqJCJuvWcmJ0MvENjc0V 3FQVDiIkTj6zaAzlibJM+9BeBi4KQpiWgMjxrHD7n4dz5Kh8/MnyopCkMh98RuXq2b0H erV62IaA1E64CLbFBj9rWfm/WWMLSWEWUEQP6l/YPEgGYaT7WUIUb/iWSgmnWpOQ6fgT zxe0rIBoeEs/Hq0OHNzZbeb3y3vCSkEg2Dd7qrsj8ordYeClwv70iHifE0xZ+D+nWBCr dGWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758593788; x=1759198588; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=GqJLtiX0N2qhSfPnWYFvcukrVhu62C8iKaYFpIkmc5g=; b=P8YFKcbVNNGX1a0mjJ9ATzmiXwKqJlVUIP2nt5U/vhpbPFb6zUOXKivDee0B0wq7oo 9joZFLt3COFYC5PW8VD0ej2aFR69n1nUFc7WMMXIWzMw0go7yKi1NDrjyNaU384rmNl4 8Cft+WqmnHUlnljLpaGJJQb0nUwn+SwHz2LEU5vUYJeTbt+wdMrWGLCacj40QAc2K+Mh NjasKrXzknsK84oO47qXQzD+ZCT6Pi82Xk6bfwQMEmGzgl0o3q84lI1S5b65el4XrsUr abqCZHxjYSUZhnVJwG7fhSX/lbghhzZ8SBLDL42YtLmtNmO95giEZeB9GLCh4guq2vgl fN1A== X-Gm-Message-State: AOJu0YzVQfO65Wsf1JDZHsWajlr9OGrKPjTUissufdWfLoXxi2rwtZVi cxVWFJ+GIngBwv4AwvpUZkUWU2syCcksHwBdJD47H6F93vEwK5fsYdtWNct5P2Rl01EOi3uJ/Yr IJZFZuqgNVcBzXJVhpzxc49awPN+mvHdVhcu3Vj4= X-Gm-Gg: ASbGncs2TUYNw0dYnuTXgdJsCc++HKQhvZf5Ky+qhxRd/jZsyM7Mmlf0FeBKfRMR4ow jBSBQw014hKHvAKHWF0gs0E4tp3phcNKYVlrNgVGmK9NczFleZKHkstePE6n0ZmdsSbPAH5U7c/ cTO+hMy8GShnUTupA58fptKchbVjDKP719vTCp3XVDDXcaUusx9tbpJo2OLPWg4SgyyqJ1/l+cR Ia1Ewzz X-Google-Smtp-Source: AGHT+IFOSACXgfaePvn7jOAIZiHVDIl3I4afM81wwzYUdczcWRpaZymPx5f3od+Yiufh+VnYNsoOMo35VBRfwi/ym6c= X-Received: by 2002:a05:690e:d43:b0:633:f908:1f1a with SMTP id 956f58d0204a3-636047928bemr855872d50.37.1758593788145; Mon, 22 Sep 2025 19:16:28 -0700 (PDT) MIME-Version: 1.0 From: "H.J. Lu" <hjl.tools@gmail.com> Date: Tue, 23 Sep 2025 10:15:51 +0800 X-Gm-Features: AS18NWAKdlKkn1efayD3SouxRhkrWzovRxcAINFi3Z8NBlr7nKB5Q-phIvIQLjw Message-ID: <CAMe9rOq9G-5s6vm0BMTHiBDiRAjoBqH_F4XzSdb03s5rwe_GAg@mail.gmail.com> Subject: [PATCH 1/4] elf: Disallow the empty symbol name To: Binutils <binutils@sourceware.org>, Alan Modra <amodra@gmail.com>, Nick Clifton <nickc@redhat.com>, Jan Beulich <JBeulich@suse.com> Content-Type: multipart/mixed; boundary="0000000000000c29a7063f6e86b4" X-Spam-Status: No, score=-3014.9 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 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
[1/4] elf: Disallow the empty symbol name
|
|
Commit Message
H.J. Lu
Sept. 23, 2025, 2:15 a.m. UTC
Reject the empty symbol name, "". PR ld/33456 * elflink.c (elf_link_add_object_symbols): Disallow the empty symbol name.
Comments
On Tue, Sep 23, 2025 at 10:15:51AM +0800, H.J. Lu wrote: > Reject the empty symbol name, "". > > PR ld/33456 > * elflink.c (elf_link_add_object_symbols): Disallow the empty > symbol name. OK.
On 23.09.2025 13:20, Alan Modra wrote: > On Tue, Sep 23, 2025 at 10:15:51AM +0800, H.J. Lu wrote: >> Reject the empty symbol name, "". >> >> PR ld/33456 >> * elflink.c (elf_link_add_object_symbols): Disallow the empty >> symbol name. > > OK. Where exactly is it stated that zero-length symbols aren't allowed? gas allows me to make such a symbol. It isn't consistent though: It doesn't allow me to make such a symbol global, for example. Imo as long as such symbols aren't forbidden, this should be at most a warning. Jan
On Tue, Sep 23, 2025 at 10:34 PM Jan Beulich <jbeulich@suse.com> wrote: > > On 23.09.2025 13:20, Alan Modra wrote: > > On Tue, Sep 23, 2025 at 10:15:51AM +0800, H.J. Lu wrote: > >> Reject the empty symbol name, "". > >> > >> PR ld/33456 > >> * elflink.c (elf_link_add_object_symbols): Disallow the empty > >> symbol name. > > > > OK. > > Where exactly is it stated that zero-length symbols aren't allowed? > gas allows me to make such a symbol. It isn't consistent though: It > doesn't allow me to make such a symbol global, for example. Imo as > long as such symbols aren't forbidden, this should be at most a > warning. > > Jan name here is a global symbol, which can't be an empty string. I will update my commit message with elf: Disallow the empty global symbol name Reject the empty global symbol name, "". PR ld/33456 * elflink.c (elf_link_add_object_symbols): Disallow the empty global symbol name.
On Wed, Sep 24, 2025 at 04:21:33AM +0800, H.J. Lu wrote: > On Tue, Sep 23, 2025 at 10:34 PM Jan Beulich <jbeulich@suse.com> wrote: > > > > On 23.09.2025 13:20, Alan Modra wrote: > > > On Tue, Sep 23, 2025 at 10:15:51AM +0800, H.J. Lu wrote: > > >> Reject the empty symbol name, "". > > >> > > >> PR ld/33456 > > >> * elflink.c (elf_link_add_object_symbols): Disallow the empty > > >> symbol name. > > > > > > OK. > > > > Where exactly is it stated that zero-length symbols aren't allowed? > > gas allows me to make such a symbol. It isn't consistent though: It > > doesn't allow me to make such a symbol global, for example. Imo as > > long as such symbols aren't forbidden, this should be at most a > > warning. > > > > Jan > > name here is a global symbol, which can't be an empty string. > I will update my commit message with > > elf: Disallow the empty global symbol name > > Reject the empty global symbol name, "". > > PR ld/33456 > * elflink.c (elf_link_add_object_symbols): Disallow the empty > global symbol name. This needs tweaking. When I gave the OK for this patch, I'd seen that you were changing global syms (locals can have empty names of course), and thought that a global sym with name "" was useless: We match symbols by name when linking, obviously. The problem is that STT_LOOS thru STT_HIPROC symbol types might reasonably have empty names. I'll commit the following after running another testsuite run. It fixes sparc64-linux-gnu +FAIL: selective2 sparc64-linux-gnu +FAIL: selective3 PR ld/33456 * elflink.c (elf_link_add_object_symbols): Move new check later to give the backend add_symbol_hook a chance to remove symbols with empty names. diff --git a/bfd/elflink.c b/bfd/elflink.c index 0a0456177c2..5c8b822e36a 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -5096,13 +5096,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) if (name == NULL) goto error_free_vers; - if (name[0] == '\0') - { - _bfd_error_handler (_("%pB: corrupt symbol table"), abfd); - bfd_set_error (bfd_error_bad_value); - goto error_free_vers; - } - if (isym->st_shndx == SHN_COMMON && (abfd->flags & BFD_PLUGIN) != 0) { @@ -5146,6 +5139,13 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) continue; } + if (name[0] == '\0') + { + _bfd_error_handler (_("%pB: corrupt symbol table"), abfd); + bfd_set_error (bfd_error_bad_value); + goto error_free_vers; + } + /* Sanity check that all possibilities were handled. */ if (sec == NULL) abort ();
On 25.09.2025 03:22, Alan Modra wrote: > On Wed, Sep 24, 2025 at 04:21:33AM +0800, H.J. Lu wrote: >> On Tue, Sep 23, 2025 at 10:34 PM Jan Beulich <jbeulich@suse.com> wrote: >>> >>> On 23.09.2025 13:20, Alan Modra wrote: >>>> On Tue, Sep 23, 2025 at 10:15:51AM +0800, H.J. Lu wrote: >>>>> Reject the empty symbol name, "". >>>>> >>>>> PR ld/33456 >>>>> * elflink.c (elf_link_add_object_symbols): Disallow the empty >>>>> symbol name. >>>> >>>> OK. >>> >>> Where exactly is it stated that zero-length symbols aren't allowed? >>> gas allows me to make such a symbol. It isn't consistent though: It >>> doesn't allow me to make such a symbol global, for example. Imo as >>> long as such symbols aren't forbidden, this should be at most a >>> warning. >> >> name here is a global symbol, which can't be an empty string. Why? Where's this stated? >> I will update my commit message with >> >> elf: Disallow the empty global symbol name >> >> Reject the empty global symbol name, "". >> >> PR ld/33456 >> * elflink.c (elf_link_add_object_symbols): Disallow the empty >> global symbol name. > > This needs tweaking. When I gave the OK for this patch, I'd seen that > you were changing global syms (locals can have empty names of course), > and thought that a global sym with name "" was useless: We match > symbols by name when linking, obviously. Yes, yet still: A single such symbol could exist in the name space. Unless I've overlooked something in the spec. Jan > The problem is that STT_LOOS > thru STT_HIPROC symbol types might reasonably have empty names. > > I'll commit the following after running another testsuite run. It > fixes > sparc64-linux-gnu +FAIL: selective2 > sparc64-linux-gnu +FAIL: selective3 > > PR ld/33456 > * elflink.c (elf_link_add_object_symbols): Move new check later > to give the backend add_symbol_hook a chance to remove symbols > with empty names. > > diff --git a/bfd/elflink.c b/bfd/elflink.c > index 0a0456177c2..5c8b822e36a 100644 > --- a/bfd/elflink.c > +++ b/bfd/elflink.c > @@ -5096,13 +5096,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) > if (name == NULL) > goto error_free_vers; > > - if (name[0] == '\0') > - { > - _bfd_error_handler (_("%pB: corrupt symbol table"), abfd); > - bfd_set_error (bfd_error_bad_value); > - goto error_free_vers; > - } > - > if (isym->st_shndx == SHN_COMMON > && (abfd->flags & BFD_PLUGIN) != 0) > { > @@ -5146,6 +5139,13 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) > continue; > } > > + if (name[0] == '\0') > + { > + _bfd_error_handler (_("%pB: corrupt symbol table"), abfd); > + bfd_set_error (bfd_error_bad_value); > + goto error_free_vers; > + } > + > /* Sanity check that all possibilities were handled. */ > if (sec == NULL) > abort (); > >
On Thu, Sep 25, 2025 at 08:03:31AM +0200, Jan Beulich wrote: > Yes, yet still: A single such symbol could exist in the name space. Unless > I've overlooked something in the spec. You do have a point, but I'll only take it seriously if you can generate such a symbol in an ELF object file using gas.
From 3c3fab00d18ef3303e143e44aef88a8f60f1f904 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.tools@gmail.com> Date: Tue, 23 Sep 2025 10:05:14 +0800 Subject: [PATCH 1/4] elf: Disallow the empty symbol name Reject the empty symbol name, "". PR ld/33456 * elflink.c (elf_link_add_object_symbols): Disallow the empty symbol name. Signed-off-by: H.J. Lu <hjl.tools@gmail.com> --- bfd/elflink.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bfd/elflink.c b/bfd/elflink.c index b04b017747f..66982f82b94 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -5096,6 +5096,13 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) if (name == NULL) goto error_free_vers; + if (name[0] == '\0') + { + _bfd_error_handler (_("%pB: corrupt symbol table"), abfd); + bfd_set_error (bfd_error_bad_value); + goto error_free_vers; + } + if (isym->st_shndx == SHN_COMMON && (abfd->flags & BFD_PLUGIN) != 0) { -- 2.51.0