From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id EA7A83858D1E for ; Sat, 6 Apr 2024 07:28:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA7A83858D1E 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 EA7A83858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712388534; cv=none; b=teyx9fbMAO5x5kkI6KvFYh4WdzbzfY8pAxK3W65XlFoxM3dFm3+nWiimIoG+OFBbQFaalb4fo8h6XhHf/Gy+fZHrQznTtGLcYf+gszt7QuwlYDnmJxL1Dviut7HyfgtS95DakO9A6kD3vQq1ZXeuoQcYPTSJSSsR63RNT6J9pPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712388534; c=relaxed/simple; bh=2NPdAdakKgIYURa1xKKuzt4lVIZmt0I2V7Ef2FVvq1M=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=xwbtKb0QI1LdQVcZ6KzXJrcn8//ZC0X6g0yFQiyqpYYJST+Z9ZJL4UTx5mzutMpialMWyckivAfWEzT0smbBuaDOymD+hbiSP3R8QNCAJ6z4pA6h5M+n1OTu/i2sOb2B05dAx2QzBFS5NoZw4KYOCZkFoXLJO/VU2bWWqAneFp4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1e24c889618so25158555ad.2 for ; Sat, 06 Apr 2024 00:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712388530; x=1712993330; darn=sourceware.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=BD6HCiObTtomJRvj861/jbjjd88vMlv9kQqNa4ZJCoE=; b=RGchM5syHjJdRchyG7T5pITATRqZqWCTRDXMjNySFv+FOie8nYllacEe3Fg0wPzFMq KLCstFFiFBhfOa4GF1k3LKbBM14BTy4KwNFZ3kCgOfouKgzizYv/FHeyTTv+suSFBfTm VBal5ek2bIr+MFFL2mU24gI8koaPkPSPX1FBf/dZivZEwXsmw2yxlOrNjYzzcDjvOL5U p8/XNu4k2f/C3iSlT4ajKraLmIjn9yZNQSRvYLUm0ue/T//s3LoA7WIwg6J27C0cDdCA 6lbas8aZl4ubun59Op/M8YIXs8GMdXvSe5sTesrZBbBICRbVJ9wqLu/rGCMSlPbNeIBU xV1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712388530; x=1712993330; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BD6HCiObTtomJRvj861/jbjjd88vMlv9kQqNa4ZJCoE=; b=aA2EASIlOezr/eRj/wBAEH0CgKbvoQaHIKtrw/qbKSGTWHxAiHO9Wszi9BUKs6EWhs OeNifgbYtJek29D/mi7whG/houl5wLbbaCcHVVDQ9iYipT8UQXN/G48VyTQ9QFDSpLFS TK3dQ/MEGuuIIWy5l3gHo/3Hjq4SkngLyrGNzgKcA1In35p7kE28picTZuA+HjcEX7TA VzWzuNPhnt3fHY84k6Htxqv7buBc3p7T3ivuaXANoWlD8oNP8chZrg9g4hJ13/AoSu0y CkEY32xurmCC3MApwo+ubqW71mGuqezmbyepIa3qi7dTT9u4b2QG1HUcnNdVBkq2jFko /EuA== X-Gm-Message-State: AOJu0Yw6AvZ7tsd+UTZZDYFzxl/Q+zbnUmNyust6Qz3JACd49FKk7Qg6 ylyvVoxTOP84/oghq7kh+TCIBtUbZK3neNvgrZhflLi3UM4T2STWKdoStShC X-Google-Smtp-Source: AGHT+IErmZhpn6AnokmR841PoR87U53CSK3ogdb6/g718Lw17iaEi1xYmH4pU9xCLzrjVhIGbLjIyw== X-Received: by 2002:a17:902:cecc:b0:1e2:ac38:2657 with SMTP id d12-20020a170902cecc00b001e2ac382657mr4001011plg.24.1712388529805; Sat, 06 Apr 2024 00:28:49 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id j12-20020a170903024c00b001dbb6fef41fsm2803122plh.257.2024.04.06.00.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Apr 2024 00:28:49 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id B12181140325; Sat, 6 Apr 2024 17:58:46 +1030 (ACDT) Date: Sat, 6 Apr 2024 17:58:46 +1030 From: Alan Modra To: "H.J. Lu" Cc: binutils@sourceware.org Subject: Re: [PATCH] elf: Use elf_link_first_hash_entry for first_hash Message-ID: References: <20240405233758.2040146-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3033.6 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 List-Id: I settled on this one. PR ld/31482 PR ld/31489 * elflink.c (elf_link_add_to_first_hash): Add "copy" param. (elf_link_add_object_symbols): Flag that name must be copied when appending version string to symbol name. diff --git a/bfd/elflink.c b/bfd/elflink.c index e41b3d6dad7..dadac2522d5 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -4304,7 +4304,7 @@ elf_link_first_hash_newfunc (struct bfd_hash_entry *entry, static void elf_link_add_to_first_hash (bfd *abfd, struct bfd_link_info *info, - const char *name) + const char *name, bool copy) { struct elf_link_hash_table *htab = elf_hash_table (info); /* Skip if there is no first hash. */ @@ -4313,7 +4313,7 @@ elf_link_add_to_first_hash (bfd *abfd, struct bfd_link_info *info, struct elf_link_first_hash_entry *e = ((struct elf_link_first_hash_entry *) - bfd_hash_lookup (htab->first_hash, name, true, false)); + bfd_hash_lookup (htab->first_hash, name, true, copy)); if (e == NULL) info->callbacks->einfo (_("%F%P: %pB: failed to add %s to first hash\n"), abfd, name); @@ -4920,6 +4920,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) asection *sec, *new_sec; flagword flags; const char *name; + bool must_copy_name = false; struct elf_link_hash_entry *h; struct elf_link_hash_entry *hi; bool definition; @@ -5217,6 +5218,11 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) memcpy (p, verstr, verlen + 1); name = newname; + /* Since bfd_hash_alloc is used for "name", the string + must be copied if added to first_hash. The string + memory can be freed when an --as-needed library is + not needed. */ + must_copy_name = true; } /* If this symbol has default visibility and the user has @@ -5660,7 +5666,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) && h->root.u.def.section->owner == abfd) /* Add this symbol to first hash if this shared object has the first definition. */ - elf_link_add_to_first_hash (abfd, info, name); + elf_link_add_to_first_hash (abfd, info, name, must_copy_name); } } } @@ -6108,7 +6114,7 @@ _bfd_elf_archive_symbol_lookup (bfd *abfd, { /* Add this symbol to first hash if this archive has the first definition. */ - elf_link_add_to_first_hash (abfd, info, name); + elf_link_add_to_first_hash (abfd, info, name, false); return h; } -- Alan Modra Australia Development Lab, IBM