From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by sourceware.org (Postfix) with ESMTPS id 642823858C98 for ; Fri, 5 Apr 2024 01:51:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 642823858C98 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 642823858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b2a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712281868; cv=none; b=QA3Cf5Bvn0R1ebM0jfqD2xzR2SbihbB+e8VEbd/Ym6fXXHg9NwYje9U6jWfxowm6yXfoFQ3FKMFNk44pKAblXbZrayKlrrW5ljQTKRa4+3n7SnDQaNFFgZbJrj63EPGH2nG3ceAzcA0bRE8cUYcGUIdo9IrI9j33/Cclnzc/iSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712281868; c=relaxed/simple; bh=QZzjQb0tCUlxj2ZQ9pic6MCYm99eY52QcuEL8TUA7Ww=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=aKTMdyEOtkXGIDMGNLvpezsD2nJ2g0tB7QYMUIXuPYsxxxi44OW0IxmW9obbYQmJDyYD+ueKSyJlaP9KFUgFK2YbfVEq2DCGmnG4AraRdbPGaLkLMqT7TFeJl9faprkuzg5Ka34P7kJ/bs0okNBxmQyBZIn4E99CRIRmXXMzukE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-ddaad2aeab1so1645755276.3 for ; Thu, 04 Apr 2024 18:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712281864; x=1712886664; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Ou0+a5K0DyX1T2g5MhMFX43qABAxVHJP1OV7vXONG6k=; b=MYFwacgV+a7js2ZISJEzskrfkWX8IxfUDa45ECN3FweGsd80VPmHbW1FRVLNYXroGp 7Sfv8nUejBuS40o8fsa3WooE/g2c0t27vWXlvKNikn9C8ZULmkZLHNJjy3YsyDgwNPQt O8d+bgVp5r2Iuoo2xwYzjL+nXmihNcfCj4zle92NEfqYUMFUrfxZzgc5SFdK1/+V6I5M 5C5WvTqWXC2xdrbbCTV7M0JP06PC6AWTRuilkE3wA0W5dxJFQwCdiTLm5LlAwaHjEEwm JBOBLWepwnJqVjGp4Fd9wGfSYUE7bu9/29zLoLvJeqAK6uaI4MJCgua8+z8BME6LuWo+ gNZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712281864; x=1712886664; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ou0+a5K0DyX1T2g5MhMFX43qABAxVHJP1OV7vXONG6k=; b=LDisAZqIFM+3gJuTCuhH6kgFNfUC5NfdrK2n20MD5Aoy3vIKnxwy0pOek0+eXIcudn sOlHHx9jVpSRjUHHyIAb5Q+Xn91YdaIWwBARU5BDj/laBcnUJDkjRq6Sg0pR2Gh3glsk JbDw+mx1iiaMQxwS25YHLz8gDYxrz7ldZtzfZDLVs+azlFZNrWsP4AQymzAXSe68ZDOv i3C40YySSocng2IiY5ootbiDl8c7Vz4haKhpQ7q+Xw2xbl+nqbdKPkQjyj2oZ2n+a0dw 4YeqaIXvzbDhfnMXUFFEg0N8c5npNRZ/7CSyjG2REqsCDtAVgfooHcBTNO8nZ5dJhNBC u9sQ== X-Gm-Message-State: AOJu0YwuMX1P8Erfld8tXlKp074pfIcbcSTZTe63altRy5ww0pvzbcHS S4E2YaAQR21Lkw5acddoRQA4TSltsY9b9YJrVA676kEfz5TpQp0xw371yavWcNo92iVIhBNb3SF JbaK8YzlIJkw2JrA+nzTTXNYZ+FE= X-Google-Smtp-Source: AGHT+IFjoKHxeT1F7rEgO2vBZ/a+XNivTJv6jDB27CycMz5Sz6lxLMr4ZlR+lY+4al9TZBSnkpURRk48jcP101cHb48= X-Received: by 2002:a25:8691:0:b0:dcd:19ba:10df with SMTP id z17-20020a258691000000b00dcd19ba10dfmr4224554ybk.56.1712281863737; Thu, 04 Apr 2024 18:51:03 -0700 (PDT) MIME-Version: 1.0 References: <20240315194350.2697266-1-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Thu, 4 Apr 2024 18:50:27 -0700 Message-ID: Subject: Re: [PATCH v3] elf: Always honor the first definition in shared object and archive To: Alan Modra Cc: binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3013.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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: On Thu, Apr 4, 2024 at 4:54=E2=80=AFPM Alan Modra wrote: > > On Fri, Mar 15, 2024 at 12:43:50PM -0700, H.J. Lu wrote: > > GCC doesn't put builtin function symbol references, which are defined i= n > > the shared C library, in the IR symbol table. > > Should we be covering for what looks like a gcc bug? At the expense > of yet another hash table. I think we should. The built function references may be inlined by GCC. It is reasonable for them not to show up in IR symbol tables. > > + /* Hash table of symbols which are first defined in archives or shar= ed > > + objects when there are any IR inputs. */ > > + struct bfd_link_hash_table *first_hash; > > + > > It looks to me that you just need a hash table that maps a symbol name > to a bfd. Maybe use libiberty/hashtab.c hash instead, to cut down > memory for entries? I prefer not to deal with libiberty/hashtab.c. > > + if (e->type =3D=3D bfd_link_hash_new) > > + { > > + /* Change the type to bfd_link_hash_defined and > > + store ABFD in u.undef->abfd. */ > > + e->type =3D bfd_link_hash_defined; > > + e->u.undef.abfd =3D abfd; > > + } > > That's a bit rude, using bfd_link_hash_defined and a union field that > belongs to bfd_link_hash_undefined. I changed it to bfd_link_hash_undefined. > > @@ -5963,7 +6017,30 @@ _bfd_elf_archive_symbol_lookup (bfd *abfd, > > > > p =3D strchr (name, ELF_VER_CHR); > > if (p =3D=3D NULL || p[1] !=3D ELF_VER_CHR) > > - return h; > > + { > > + struct elf_link_hash_table *htab =3D elf_hash_table (info); > > + if (htab->first_hash !=3D NULL) > > + { > > + /* Add this symbol to first hash if this archive has the > > + first definition. */ > > + struct bfd_link_hash_entry *e > > + =3D bfd_link_hash_lookup (htab->first_hash, name, true, > > + false, true); > > + if (e =3D=3D NULL) > > + info->callbacks->einfo > > + (_("%F%P: %pB: failed to add %s to first hash\n"), > > + abfd, name); > > + > > + if (e->type =3D=3D bfd_link_hash_new) > > + { > > + /* Change the type to bfd_link_hash_defined and store > > + ABFD in u.undef->abfd. */ > > + e->type =3D bfd_link_hash_defined; > > + e->u.undef.abfd =3D abfd; > > + } > > + } > > + return h; > > + } > > At first glance this looks like a duplicate of the code in > elf_link_add_object_symbols adding an entry to first_hash, and > therefore could be extracted to a common function. > I added elf_link_add_to_first_hash in the v2 patch: https://sourceware.org/pipermail/binutils/2024-April/133395.html Thanks. --=20 H.J.