From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by sourceware.org (Postfix) with ESMTPS id CF65B3844012 for ; Fri, 28 Aug 2020 01:59:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CF65B3844012 Received: by mail-pg1-x542.google.com with SMTP id 31so4666075pgy.13 for ; Thu, 27 Aug 2020 18:59:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=3aMItZEEruuPUYNXWS6CWfxrEpvVcMOriQOjSGDX83Y=; b=HxmR48HEWXyCRJRismdDplu9xhcLonD8bwzLkbedOJ3WQzBRflJL+3MEkMgM08xYuV RwxYH+knEDCUrR6hsAuLZhGYNEeVasTbIeFPa96NUhlbMM/8WYFFT+erIstwSR64Lu4A nVaYMDOlW3vPzwSopNl+mjGA/e0eBsCi7COTLfxU5ErXe0UkYrocUvZn+De6RlQ+yYMv bbyWL7Po9jA7oBdFwe8Tua5x+rfqjXNQ6TY2qdTZswC3BtZb49760E9yXGaXosFDOlka cHLF0qFeMQGa7rf0pxK3D4lxvtJPMY8bz+mGwsphpIvMYeYRFgKumepxk2hKOHabQ5JX fsKA== X-Gm-Message-State: AOAM53361GliCB3Q+ER+RO7xWupzYtJFkbnWbULIGsVCrijrahYoeOX0 2pJjfykQ/9OsjQy4EDVP/Jo= X-Google-Smtp-Source: ABdhPJzSwwOX01eN3xOmeaAZShTrxjbKpgKx0dNyZQ4aB0H2IIF2Er+DklPHgRyrmc84ZXL4U5BG2Q== X-Received: by 2002:a63:d60d:: with SMTP id q13mr16581315pgg.118.1598579941961; Thu, 27 Aug 2020 18:59:01 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:1cc2:f8ff:3647:bc1f]) by smtp.gmail.com with ESMTPSA id q10sm997940pfn.206.2020.08.27.18.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2020 18:59:00 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 888A8807B5; Fri, 28 Aug 2020 11:28:49 +0930 (ACST) Date: Fri, 28 Aug 2020 11:28:48 +0930 From: Alan Modra To: "H.J. Lu" Cc: Binutils Subject: Re: [PATCH] elf: Don't load archive element after dynamic definition Message-ID: <20200828015847.GG15695@bubble.grove.modra.org> References: <20200825172842.1212936-1-hjl.tools@gmail.com> <20200827135311.GD15695@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-4.1 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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Aug 2020 01:59:04 -0000 On Thu, Aug 27, 2020 at 07:05:15AM -0700, H.J. Lu wrote: > On Thu, Aug 27, 2020 at 6:53 AM Alan Modra wrote: > > > > On Tue, Aug 25, 2020 at 10:28:42AM -0700, H.J. Lu via Binutils wrote: > > > Don't load the archive element after seeing a definition in a shared > > > object. > > > > > > bfd/ > > > > > > PR ld/26530 > > > * elflink.c (elf_link_add_object_symbols): Also preserve the > > > dynamic_def bit for --as-needed. > > > (elf_link_add_archive_symbols): Don't load the archive element > > > after seeing a definition in a shared object. > > > > This seems over complicated to me. Why don't we just load the > > as-needed shared library on the first pass? > > > > In the first pass, when we are loading a shared object, do we have > the IR symbol resolution? No, but why should that matter? Adding DT_NEEDED for an as-needed library that turns out to not be needed after LTO is not a problem IMO. Also I think it may be necessary to load shared libraries on the first pass for LTO to work properly in corner cases. See the comment in git commit a896df97b952. The condition we use to add --as-needed libraries is: if (!add_needed && matched && definition && ((dynsym && h->ref_regular_nonweak) || (h->ref_dynamic_nonweak && (elf_dyn_lib_class (abfd) & DYN_AS_NEEDED) != 0 && !on_needed_list (elf_dt_name (abfd), htab->needed, NULL)))) Note the test of dynsym, but earlier /* Nor should we make plugin symbols dynamic. */ if ((abfd->flags & BFD_PLUGIN) != 0) dynsym = FALSE; So I'm thinking perhaps we should delete the above lines and instead add the BFD_PLUGIN condition where we make symbols dynamic. if (dynsym && (abfd->flags & BFD_PLUGIN) == 0 && h->dynindx == -1) { if (! bfd_elf_link_record_dynamic_symbol (info, h)) I haven't tested the idea.. -- Alan Modra Australia Development Lab, IBM