Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 383D2C433EF for ; Sat, 16 Apr 2022 10:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231575AbiDPLBx (ORCPT ); Sat, 16 Apr 2022 07:01:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231572AbiDPLBw (ORCPT ); Sat, 16 Apr 2022 07:01:52 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93CB05A146 for ; Sat, 16 Apr 2022 03:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=dr9bD3tN2MGIzfHnKbsXXJ2Zjd0N3TvRtrqZGz8+HZo=; b=SMvKdmH2RDrgzo7xIB8X13ma/Y hbDQXb+qBnp3aBrszwjefF0vS6xznsl1g2DeVO9hkCB7GfPJ4ctV1/JU128/oXLbSevkVA7Ek+CK0 SrI+Psdv8G6Q5QgZ7OrYkvSVmAGF72WgDIbrCQ8F4p1bYLew9/TYK3hO/wfkT8xzD0aTkBg+c+YW+ GknsC5BysJLWrzwjLu/qW8dUsHkKs4iRG25tbWSR9tO/liov7ssVg9MsL98vEzRnYjoo+xm7TSQkN YpVRjTYOJscdpenOjbswnynFGcQjAXywALtnqE1MpAsqU5cJ5oL9ZiZuqCb1kqnYYqxof0b/i96D5 X5xfn/3A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfg8w-005lk9-D2; Sat, 16 Apr 2022 10:59:06 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id CC2999861A3; Sat, 16 Apr 2022 12:59:05 +0200 (CEST) Date: Sat, 16 Apr 2022 12:59:05 +0200 From: Peter Zijlstra To: Segher Boessenkool Cc: x86@kernel.org, Josh Poimboeuf , hjl.tools@gmail.com, ndesaulniers@google.com, mbenes@suse.cz, rostedt@goodmis.org, linux-toolchains@vger.kernel.org Subject: Re: The trouble with __weak and objtool got worse Message-ID: <20220416105905.GE2731@worktop.programming.kicks-ass.net> References: <20220415182229.GB25951@gate.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220415182229.GB25951@gate.crashing.org> Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Fri, Apr 15, 2022 at 01:22:29PM -0500, Segher Boessenkool wrote: > Hi! > > On Fri, Apr 15, 2022 at 01:19:04PM +0200, Peter Zijlstra wrote: > [ huge snip ] > > > This seems to happen when objtool cannot find a section symbol, in which > > case it falls back to any other symbol to key off of, however in this > > case that goes terribly wrong! > > That is an objtool problem then. Fix objtool so it looks at symbols > directly? I'm not sure what you're saying. It *does* look at the symbols, but at the time we run objtool (pre link) there's multiple copies of a symbol (weak and non-weak), and if we then generate symbol relative relocs, we end up, post-link, with the relocs resolved wrong. The weak symbol relocs get applied to the non-weak symbol, and fail happens. > > The other option seems to be to have objtool add section symbols it > > needs, however due to ELF being a total PITA and requiring all LOCAL > > symbols to be before GLOBAL symbols, this would mean re-ordering the > > whole symbol table (I have the code somewhere :-/). > > ELF requires no such thing? Where do you see this? The first google hit: https://docs.oracle.com/cd/E23824_01/html/819-0690/chapter6-79797.html which has: "In each symbol table, all symbols with STB_LOCAL binding precede the weak symbols and global symbols. As Sections describes, a symbol table section's sh_info section header member holds the symbol table index for the first non-local symbol." I ran into that when I violated that contraint at some point and the various elf tools screamed at me.