From: Peter Zijlstra <peterz@infradead.org>
To: Nathan Chancellor <nathan@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
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
Date: Mon, 16 May 2022 23:40:05 +0200 [thread overview]
Message-ID: <20220516214005.GQ76023@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <YoK4U9RgQ9N+HhXJ@dev-arch.thelio-3990X>
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);
next prev parent reply other threads:[~2022-05-16 21:40 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-16 20:47 objtool "no non-local symbols" error with tip of tree LLVM Nathan Chancellor
2022-05-16 21:40 ` Peter Zijlstra [this message]
2022-05-16 22:48 ` Nathan Chancellor
2022-05-17 15:33 ` Peter Zijlstra
2022-05-17 15:42 ` Peter Zijlstra
2022-05-17 18:53 ` Nathan Chancellor
2022-05-18 1:24 ` Josh Poimboeuf
2022-05-18 5:30 ` Peter Zijlstra
2022-05-18 16:17 ` Josh Poimboeuf
2022-05-18 17:14 ` Josh Poimboeuf
2022-05-18 17:25 ` Peter Zijlstra
2022-05-18 18:04 ` Josh Poimboeuf
2022-05-18 7:40 ` Peter Zijlstra
2022-05-18 7:41 ` [PATCH] objtool: Fix symbol creation Peter Zijlstra
2022-05-18 17:36 ` Josh Poimboeuf
2022-05-18 22:10 ` Peter Zijlstra
2022-05-19 9:00 ` [PATCH v2] " Peter Zijlstra
2022-05-19 15:13 ` Josh Poimboeuf
2022-09-07 0:47 ` [PATCH] " Sami Tolvanen
2022-05-19 21:57 ` [tip: objtool/urgent] " tip-bot2 for Peter Zijlstra
2022-05-20 10:53 ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220516214005.GQ76023@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=jpoimboe@kernel.org \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox