Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp172088iob; Tue, 17 May 2022 22:43:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxVJZeTZLyBV3Efud7l/wn8kBmkHXxyL5YUROJ4TtgbvJd+CGqNhkJhmCCp50AhPYUd5E+ X-Received: by 2002:a17:90b:4c85:b0:1dc:5778:5344 with SMTP id my5-20020a17090b4c8500b001dc57785344mr39773945pjb.8.1652852598165; Tue, 17 May 2022 22:43:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652852598; cv=none; d=google.com; s=arc-20160816; b=JVjiXWqhG2dhcl6imWyiDTI+DT437B13i2QAQ8FFLSmF2eZxNLqkHjCiP039zwmeQf zaTG2ljzh4tQaXVHSe+m/UxQGKFfgG/12qLDSIYJHFZcC9SbUwAXednE7ojyPNNxUmbA xpafMZYzOEB4jlq2Ugmhzhw2ESEYjcRal3NsgXY56/gi04DlCMA2VoDqLJo0CLU5/i9t aLV+cOkImHulvFuu/BgbAMZxDqQ6VeAcyTLC6D0mnZ+3uZQM5wncbTRyNAa8V8HyfDSj pFhkks/kPNo5Sx62itx8KydQEss5EVBubLhHScx2rLRZE4+DxCtPTjh/MZ/4fTWSYvqv pJMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ISxEuC4Kiq3vjUGUEirY3WiUkmrk0AhD6N2mrq7YQrw=; b=T31rZnl/iRQMipPG0OaJ+VqiB0dV5+9HWAS4lffk4Dhl4iiZEbPOilwcaWRuQf4J7K TYPhq1eQY9pX5uf/nJkfq/7wbLK3J+yHeC2QM+Waumd/0O6N8PoQaM9XV7nYs4EvMHs8 gSW59TL2fG+2HfJ02xdCvMbiG6BNFtExmlwPZF+HfxxPuHDXEi4qBva9zSBX3uGwU+BU apkCJ0TJ1+EXxf5b2Dj8BjVwfZ2WugafFpOJVZwc3b1qDpbBiuiHGusFqTSWbzTcibPS 3e+RkiPADZk965yrJZJvKDzxg+K5rhZy4hknWF0UnLCoq8xmBDPv0p/gRP9Du/RGSfaW wmXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=FiX5lak8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y64-20020a638a43000000b003c6205b60b6si1439257pgd.346.2022.05.17.22.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 22:43:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=FiX5lak8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 827001AD8B; Tue, 17 May 2022 22:30:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230235AbiERFaW (ORCPT + 99 others); Wed, 18 May 2022 01:30:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230222AbiERFaR (ORCPT ); Wed, 18 May 2022 01:30:17 -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 2D97014037 for ; Tue, 17 May 2022 22:30:16 -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=ISxEuC4Kiq3vjUGUEirY3WiUkmrk0AhD6N2mrq7YQrw=; b=FiX5lak8VUsm5Z8979SsoFCjc8 T2oQp66j9cPLFBhrAngOda54jnJI9CZX1TXMKxTp061Nlb9agO73fm0u1EMtVNv++t1Zb7RJoJYcn L9DND/cKiXkP+cHucd5hwV4EOP7SDMHMEiNJiaQVTy23F0FX+KmFa2k3zuIeCWbnJDfOIcsOc9Fk0 ZSt4ixhKLcynJtK8hr009UgvL3NN69LkkwN+JbCyV4j8adRlxKVslooprfsfBuEcuTx2+0S3gcxSa KGLCe/9EkN8GZFuGwXh+lOu1botuGT/rzgY+pKj2hUsj1hm4uvXaD4B4M+uppVfHydBmiX5lKQgKN htGS6OGA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrCG9-001RwI-1K; Wed, 18 May 2022 05:30:09 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id BDF1C30018E; Wed, 18 May 2022 07:30:06 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A068A206F245B; Wed, 18 May 2022 07:30:06 +0200 (CEST) Date: Wed, 18 May 2022 07:30:06 +0200 From: Peter Zijlstra To: Josh Poimboeuf Cc: Nathan Chancellor , Nick Desaulniers , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: Re: objtool "no non-local symbols" error with tip of tree LLVM Message-ID: References: <20220516214005.GQ76023@worktop.programming.kicks-ass.net> <20220518012429.4zqzarvwsraxivux@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220518012429.4zqzarvwsraxivux@treble> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 17, 2022 at 06:24:29PM -0700, Josh Poimboeuf wrote: > On Tue, May 17, 2022 at 05:42:04PM +0200, Peter Zijlstra wrote: > > + for (;;) { > > + symtab_data = elf_getdata(s, symtab_data); > > + if (t) > > + shndx_data = elf_getdata(t, shndx_data); > > > > + if (!symtab_data) { > > + if (!idx) { > > + void *buf; > > I'm confused by whatever this is doing, how is !symtab_data possible, > i.e. why would symtab not have data? Elf_Data *elf_getdata(Elf_Scn *scn, Elf_Data *data); is an iterator, if @data is null it will return the first element, which you then feed into @data the next time to get the next element, once it returns NULL, you've found the end. In our specific case, we iterate the data sections, if idx fits inside the current section, we good, otherwise we lower idx by however many did fit and try the next. > > elf_create_section_symbol(struct elf *elf, struct section *sec) > > { > > struct section *symtab, *symtab_shndx; > > - Elf_Data *shndx_data = NULL; > > - struct symbol *sym; > > - Elf32_Word shndx; > > + Elf32_Word first_non_local, new; > > + struct symbol *sym, *old; > > + int size; > > + > > + if (elf->ehdr.e_ident[EI_CLASS] == ELFCLASS32) > > + size = sizeof(Elf32_Sym); > > + else > > + size = sizeof(Elf64_Sym); > > This should probably be called 'entsize' and I think you can just get it > from symtab->sh.sh_entsize. Ok, that would be easier, I'll check. > > + /* > > + * Either way, we added a LOCAL symbol. > > + */ > > + symtab->sh.sh_info += 1; > > + > > elf_add_symbol(elf, sym); > > Not sure if it matters here, but elf_add_symbol() doesn't set sym->alias > and sym->pv_target, and both of those are unconditionally initialized in > read_symbols(). Should elf_add_symbol() be changed to initialize them? I'll go have a look, breakfast first though! :-)