Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3338086iob; Mon, 16 May 2022 19:55:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/cP8i50sQPzo6bgfLn1OYIcjYopro/pMCZbQNgSJK1UurHjLVHC0qfqjOTNMF3OT8nvZg X-Received: by 2002:a17:907:d0c:b0:6f4:a5b9:3799 with SMTP id gn12-20020a1709070d0c00b006f4a5b93799mr17564858ejc.732.1652756132436; Mon, 16 May 2022 19:55:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652756132; cv=none; d=google.com; s=arc-20160816; b=R6NJlkR5UxClmRjcd1AuH/j4gHEl3KXRuZyw1DF3FFEzznmAPfRV61WQLW22cB0y6t sWYMzfoKxzalPjHw24ko58vH/jvt5HtwpP1XjfWtlMsy7aH7/J6j5oJYstosP9cqPboB fzAmHKFDAUle+GYt/emfNER98d6XuAFmlJGpcwocA5A6gXHjmbzd4oj23dH+dCi8gMv2 YAfSpufX/rU2SXH0BIC93Of/zNLKpzRqkZi+0j1gfH6PqaJ2AxtTps6gpF+nK9RO0hlo NSDysQ6KLjUf4WNoCxCYClqfkLGpzkvbHSV4EJ8RsE0fCKS6g5DKKjV3XNh0fuNJ3+E0 t27w== 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=aCb2HiewM12GOnx9FEdB6E4pX5NJT/HZCa9UT6fkVvk=; b=e0hy0HdQJ1M2Usibez07kqO9fIyrvAvXQbQSK2KX31eph7pgEFXNp1Z90339rSkSVs AqkrzgjoHYLMuzQkMH6NVM2wJ18NPoyHKB/mNHWQQho+j11W/ehgRgjzwH6zxHTsuwp/ kCs8G9Q/4bUQ7hOhefk1jCMabruMSuPoc3mkiARA6NoZMKSzRbVarBKUYCNZgWnNxM0/ 2W3c9ecLUGP3Hw7wK3bAFAbhnEhvxCE6S07gVAubZClmMvot69rrZ8FFlt6q2VXBa8y3 JAnr6qf/EfBpa8UQ+yFxKGWffhAGMrLbZWuA4EqLVvm6DWgMS7OoXU5E/c7U0q4Sv7LK 9jXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=OlCozzdR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji11-20020a170907980b00b006e834c6948dsi1183050ejc.574.2022.05.16.19.55.06; Mon, 16 May 2022 19:55:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=OlCozzdR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240720AbiEPVkW (ORCPT + 99 others); Mon, 16 May 2022 17:40:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234718AbiEPVkR (ORCPT ); Mon, 16 May 2022 17:40: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 9FD1C419B2 for ; Mon, 16 May 2022 14:40: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=aCb2HiewM12GOnx9FEdB6E4pX5NJT/HZCa9UT6fkVvk=; b=OlCozzdRAQyf+vNMU2vVeuPHd/ qjdeQrKKntDC2H9t8AZ1ILZHIERUIF9f75hQRCxN4ftfUviI2YgdlATVvB5CaxsW7/4sm01G2sdpq oTlngSGy3zMhVkJjMdH59yo+1VCti6N84pqoR+OU7ERpLIqK8rTMBay/IMTUWkZ6qXWnV+ZE/x20i 7EEtNsu65vlPwEvJpsFiibLuITp6Aeovj9RCPmJ45ftcE5inToCKc5sxSmD6U44WqobMuk/U2BFYe Iiy6yxab5ivpBh39CBfuT4GgKovg5wzH+Eg2YSOqMQdXLzWhT3VhefsbImx1T6BW7Wrn9662ZHZkp PS33ixMw==; 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 1nqiRj-00120Q-1i; Mon, 16 May 2022 21:40:07 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 05E44980DCC; Mon, 16 May 2022 23:40:06 +0200 (CEST) Date: Mon, 16 May 2022 23:40:05 +0200 From: Peter Zijlstra To: Nathan Chancellor Cc: Josh Poimboeuf , 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: <20220516214005.GQ76023@worktop.programming.kicks-ass.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Mon, May 16, 2022 at 01:47:15PM -0700, Nathan Chancellor wrote: > Hi Josh and Peter, > > After a recent change in LLVM [1], I see warnings (errors?) from objtool > when building x86_64 allmodconfig on 5.15 and 5.17: > > $ make -skj"$(nproc)" KCONFIG_ALLCONFIG=<(echo CONFIG_WERROR) LLVM=1 allmodconfig all > ... > mm/highmem.o: warning: objtool: no non-local symbols !? > mm/highmem.o: warning: objtool: gelf_update_symshndx: invalid section index > make[2]: *** [scripts/Makefile.build:288: mm/highmem.o] Error 255 > ... > security/tomoyo/load_policy.o: warning: objtool: no non-local symbols !? > security/tomoyo/load_policy.o: warning: objtool: gelf_update_symshndx: invalid section index > make[3]: *** [scripts/Makefile.build:288: security/tomoyo/load_policy.o] Error 255 > ... > > I don't see the same errors on x86_64 allmodconfig on mainline so I > bisected the 5.17 branch and came upon commit 4abff6d48dbc ("objtool: > Fix code relocs vs weak symbols"). I wanted to see what 5.17 might be > missing and came to commit ed53a0d97192 ("x86/alternative: Use > .ibt_endbr_seal to seal indirect calls") in mainline, which I think just > hides the issue for allmodconfig. I can reproduce this problem with a > more selective set of config values on mainline: > > $ make -skj"$(nproc)" LLVM=1 defconfig > > $ scripts/config -e KASAN -e SECURITY_TOMOYO -e SECURITY_TOMOYO_OMIT_USERSPACE_LOADER > > $ make -skj"$(nproc)" LLVM=1 olddefconfig security/tomoyo/load_policy.o > security/tomoyo/load_policy.o: warning: objtool: no non-local symbols !? > security/tomoyo/load_policy.o: warning: objtool: gelf_update_symshndx: invalid section index > make[3]: *** [scripts/Makefile.build:288: security/tomoyo/load_policy.o] Error 255 > ... > > Looking at the object file, the '.text.asan.module_ctor' section has > disappeared. > > Before: > > $ llvm-nm -S security/tomoyo/load_policy.o > 0000000000000000 0000000000000001 t asan.module_ctor > > $ llvm-readelf -s security/tomoyo/load_policy.o > > Symbol table '.symtab' contains 4 entries: > Num: Value Size Type Bind Vis Ndx Name > 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND > 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS load_policy.c > 2: 0000000000000000 0 SECTION LOCAL DEFAULT 3 .text.asan.module_ctor > 3: 0000000000000000 1 FUNC LOCAL DEFAULT 3 asan.module_ctor > > After: > > $ llvm-nm -S security/tomoyo/load_policy.o > 0000000000000000 0000000000000001 t asan.module_ctor > > $ llvm-readelf -s security/tomoyo/load_policy.o > > Symbol table '.symtab' contains 3 entries: > Num: Value Size Type Bind Vis Ndx Name > 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND > 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS load_policy.c > 2: 0000000000000000 1 FUNC LOCAL DEFAULT 3 asan.module_ctor > The problem seems to be that we need to add a local symbols because LLVM helpfully stripped all unused section symbols. The way we do that, is by moving a the first non-local symbol to the end, thereby creating a hole where we can insert a new local symbol. Because ELF very helpfully mandates that local symbols must come before non-local symbols and keeps the symbols index of the first non-local in sh_info. Thing is, the above object files don't appear to have a non-local symbol so the swizzle thing isn't needed, and apparently the value in sh_info isn't valid either. Does something simple like this work? If not, I'll try and reproduce tomorrow, it shouldn't be too hard to fix. diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 583a3ec987b5..baabf38a2a11 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -618,8 +618,7 @@ static int elf_move_global_symbol(struct elf *elf, struct section *symtab, sym = find_symbol_by_index(elf, first_non_local); if (!sym) { - WARN("no non-local symbols !?"); - return first_non_local; + return symtab->sh.sh_size / sizeof(sym->sym); } s = elf_getscn(elf->elf, symtab->idx);