From patchwork Sat Dec 6 03:04:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 126023 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 52A634D1087B for ; Sat, 6 Dec 2025 03:05:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 52A634D1087B 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=Ef4bWBj1 X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by sourceware.org (Postfix) with ESMTPS id DD3054BA23F5 for ; Sat, 6 Dec 2025 03:04:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DD3054BA23F5 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 DD3054BA23F5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764990300; cv=none; b=J/KJuNUQnsdTzuN274/XbTO6gtL5Jl9NQ0JWI59B+OpbqbokbW0BxBiAcLYy4xiFJjAjLxE0bMDjoWXsFvd7JjcVupgLsWK80dA6YJsS0v9dkFNT8rx3s/XNnaC+k5X53nK9tYlbE1j+i5Az/taQez8xwopbQGQMoHTTN4iy1BA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764990300; c=relaxed/simple; bh=nCq1xp7KidhX5sxbrT41rhYQOofCQLOBwOifLrypyFE=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=T4jQ886c4HIKslxVS8vozp1ghqzeBzbySod+LJjS+w5yYh8g8MTjNs35AtpYtCendc8mNiXt7EeBFi6+folMaiCF7+t5BqKmAvajXIvyQpWqLZyIfpBKvaSqHHD/pnkkNqBf7rhlhsDIlX9pRz4R39zF+5CZSuuaTNfLJ7Uwei0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD3054BA23F5 Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7b9387df58cso4196606b3a.3 for ; Fri, 05 Dec 2025 19:04:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764990299; x=1765595099; darn=sourceware.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=o44g18RWLrykksypH12XhJd/LItgQ1CyE4KdQcQwNvA=; b=Ef4bWBj1GBiouG7QYv8mi8CQeSfPafS1ULQWKlvneSHFvjdcpVxonmucKtpHOXzMY/ kUmxUbdE4jaSelzJhr2uwPIOGQLv5ZxTxQQ7s54860c9khgWjAIwJivN69SQzgl/qv3Y XyqYyTM0i7BlyjmT3U/VTXxz7seVZF+QM06s811cuJHxwerW0SUllNHgll/fEyQXmZKo no8neQq0ttnVJMPsvnsIIyvjYGT0KpJpQ2mXAHMgeF9mR0wT+z2EKD9dpW1NLb2tRjJ9 enfiD6mqTVaOKrlg7yzPzCAviefMGLQ9VW6e17GS/k3ZLbfFoh7yJb84wav94gFUfOSC b+uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764990299; x=1765595099; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=o44g18RWLrykksypH12XhJd/LItgQ1CyE4KdQcQwNvA=; b=UKx3KOB2khWgSFZ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:366:14b0:1a30 with SMTP id adf61e73a8af0-36618002952mr1052596637.62.1764990298813; Fri, 05 Dec 2025 19:04:58 -0800 (PST) MIME-Version: 1.0 References: <7ea91ecc-c6c4-44b5-a2d0-660657ba78bb@Oracle.COM> In-Reply-To: <7ea91ecc-c6c4-44b5-a2d0-660657ba78bb@Oracle.COM> From: "H.J. Lu" Date: Sat, 6 Dec 2025 11:04:22 +0800 X-Gm-Features: AWmQ_bkp2_OVO2RH-xpTYT9lRnspYpwvz6gmqmMgedCflv36ri8yKcHQKqgRHiQ Message-ID: Subject: [PATCH v2] elf: Keep section symbols for Solaris binary To: Ali Bahrami , Binutils Cc: Jan Beulich , Rainer Orth , Alan Modra , Nick Clifton X-Spam-Status: No, score=-3012.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org On Fri, Dec 5, 2025 at 1:31 AM Ali Bahrami wrote: > > [I've dropped the binutils alias for the moment] > > On 12/4/25 02:36, Jan Beulich wrote: > > On 04.12.2025 02:20, H.J. Lu wrote: > >> After > >> > >> commit d1bcae833b32f1408485ce69f844dcd7ded093a8 > >> Author: H.J. Lu > >> Date: Thu Jan 7 06:42:00 2021 -0800 > >> > >> ELF: Don't generate unused section symbols > >> > >> x86 ELF linkers no longer generate unused section symbols. But Solaris > >> symbol sort sections generated by Solaris linker use section symbols. > >> When objcopy removes section symbols, it corrupts Solaris symbol sort > >> sections. Add section_symbol_used to bfd and set it when Solaris symbol > >> sort sections are used. Keep section symbols if section_symbol_used is > >> set. > >> > >> PR binutils/33684 > >> * bfd-in2.h: Regenerated. > >> * bfd.c (bfd): Add section_symbol_used. > >> * elf.c (_bfd_elf_copy_private_section_data): Set > >> section_symbol_used if there are Solaris symbol sort sections. > >> * targets.c (bfd_keep_unused_section_symbols): Also return true > >> if section_symbol_used is set. > > > > This looks okay to me, but I'd like to ask Ali or Rainer to confirm. > > > > Jan > > > As you'll see on the bug thread, I was pushing for > a different solution last night that doesn't specifically > check for the sort sections, but simply keys off the > ELFOSABI_SOLARIS setting in the ELF header. > > https://sourceware.org/bugzilla/show_bug.cgi?id=33684 > > I understand that removing the section symbols is an x86 > binutils optimization, and I don't have a problem with that, > but it's breaking expectations in our world, and I think it > would be simpler to disable it, rather than maintain code > that looks for specific sections. The OSABI setting is an > easy way to recognize Solaris objects, and opt them out. > > I did however just apply the patch as it stands. While it > applies cleanly, the result doesn't build on Solaris. I > don't build binutils often, and may have botched something, > so I'll ask Rainer to double check. > After commit d1bcae833b32f1408485ce69f844dcd7ded093a8 Author: H.J. Lu Date: Thu Jan 7 06:42:00 2021 -0800 ELF: Don't generate unused section symbols x86 ELF binutils tools no longer generate unused section symbols. But Solaris binary generated by Solaris linker may include symbol sort sections which hold indexes of data and function symbols, sorted by name or by address. When objcopy removes section symbols, it corrupts Solaris symbol sort sections since symbol indexes are changed. Keep section symbols for Solaris binary. PR binutils/33684 * objcopy.c (copy_object): Keep section symbols if input is a Solaris binary and output target is the same as input target. From 9c9925d545b6abcff8cca4787b183900ca321fbc Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 3 Dec 2025 08:16:42 +0800 Subject: [PATCH v2] elf: Keep section symbols for Solaris binary After commit d1bcae833b32f1408485ce69f844dcd7ded093a8 Author: H.J. Lu Date: Thu Jan 7 06:42:00 2021 -0800 ELF: Don't generate unused section symbols x86 ELF binutils tools no longer generate unused section symbols. But Solaris binary generated by Solaris linker may include symbol sort sections which hold indexes of data and function symbols, sorted by name or by address. When objcopy removes section symbols, it corrupts Solaris symbol sort sections since symbol indexes are changed. Keep section symbols for Solaris binary. PR binutils/33684 * objcopy.c (copy_object): Keep section symbols if input is a Solaris binary and output target is the same as input target. Signed-off-by: H.J. Lu --- binutils/objcopy.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 17d4b501185..14fb8debbdf 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -2947,6 +2947,11 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) return false; } + int elf_osabi = -1; + if (ibfd->xvec == obfd->xvec + && bfd_get_flavour (ibfd) == bfd_target_elf_flavour) + elf_osabi = elf_elfheader (ibfd)->e_ident[EI_OSABI]; + if (add_sections != NULL) { struct section_add *padd; @@ -3323,7 +3328,10 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch) if ((obfd->flags & (EXEC_P | DYNAMIC)) != 0 && (obfd->flags & HAS_RELOC) == 0) { - if (bfd_keep_unused_section_symbols (obfd) || keep_section_symbols) + /* Keep section symbols for Solaris binary. */ + if (elf_osabi == ELFOSABI_SOLARIS + || bfd_keep_unused_section_symbols (obfd) + || keep_section_symbols) { /* Non-relocatable inputs may not have the unused section symbols. Mark all section symbols as used to generate -- 2.52.0