2021-01-14 22:30:22

by Josh Poimboeuf

[permalink] [raw]
Subject: [PATCH] objtool: Don't fail on missing symbol table

Thanks to a recent binutils change which doesn't generate unused
symbols, it's now possible for thunk_64.o be completely empty with
CONFIG_PREEMPTION: no text, no data, no symbols.

We could edit the Makefile to only build that file when
CONFIG_PREEMPTION is enabled, but that will likely create confusion
if/when the thunks end up getting used by some other code again.

Just ignore it and move on.

Reported-by: Nathan Chancellor <[email protected]>
Signed-off-by: Josh Poimboeuf <[email protected]>
---
tools/objtool/elf.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index be89c741ba9a..2b0f4f52f7b5 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -380,8 +380,11 @@ static int read_symbols(struct elf *elf)

symtab = find_section_by_name(elf, ".symtab");
if (!symtab) {
- WARN("missing symbol table");
- return -1;
+ /*
+ * A missing symbol table is actually possible if it's an empty
+ * .o file. This can happen for thunk_64.o.
+ */
+ return 0;
}

symtab_shndx = find_section_by_name(elf, ".symtab_shndx");
--
2.29.2


2021-01-14 22:35:55

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] objtool: Don't fail on missing symbol table

On Thu, Jan 14, 2021 at 04:24:15PM -0600, Josh Poimboeuf wrote:
> Thanks to a recent binutils change which doesn't generate unused
> symbols, it's now possible for thunk_64.o be completely empty with
> CONFIG_PREEMPTION: no text, no data, no symbols.
>
> We could edit the Makefile to only build that file when
> CONFIG_PREEMPTION is enabled, but that will likely create confusion
> if/when the thunks end up getting used by some other code again.
>
> Just ignore it and move on.
>
> Reported-by: Nathan Chancellor <[email protected]>
> Signed-off-by: Josh Poimboeuf <[email protected]>

Thanks for the quick fix!

Reviewed-by: Nathan Chancellor <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>

Is it worth a cc to stable given that I hit this in 5.4? I suppose it is
not super critical now but it seems like someone might eventually hit
this as times goes on and binutils 2.37 becomes more common.

> ---
> tools/objtool/elf.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index be89c741ba9a..2b0f4f52f7b5 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -380,8 +380,11 @@ static int read_symbols(struct elf *elf)
>
> symtab = find_section_by_name(elf, ".symtab");
> if (!symtab) {
> - WARN("missing symbol table");
> - return -1;
> + /*
> + * A missing symbol table is actually possible if it's an empty
> + * .o file. This can happen for thunk_64.o.
> + */
> + return 0;
> }
>
> symtab_shndx = find_section_by_name(elf, ".symtab_shndx");
> --
> 2.29.2
>

2021-01-15 11:33:43

by Miroslav Benes

[permalink] [raw]
Subject: Re: [PATCH] objtool: Don't fail on missing symbol table

On Thu, 14 Jan 2021, Josh Poimboeuf wrote:

> Thanks to a recent binutils change which doesn't generate unused
> symbols, it's now possible for thunk_64.o be completely empty with
> CONFIG_PREEMPTION: no text, no data, no symbols.

"without CONFIG_PREEMPTION", or did I misunderstand?

> We could edit the Makefile to only build that file when
> CONFIG_PREEMPTION is enabled, but that will likely create confusion
> if/when the thunks end up getting used by some other code again.
>
> Just ignore it and move on.
>
> Reported-by: Nathan Chancellor <[email protected]>
> Signed-off-by: Josh Poimboeuf <[email protected]>

Reviewed-by: Miroslav Benes <[email protected]>

with the note below.

> ---
> tools/objtool/elf.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index be89c741ba9a..2b0f4f52f7b5 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -380,8 +380,11 @@ static int read_symbols(struct elf *elf)
>
> symtab = find_section_by_name(elf, ".symtab");
> if (!symtab) {
> - WARN("missing symbol table");
> - return -1;
> + /*
> + * A missing symbol table is actually possible if it's an empty
> + * .o file. This can happen for thunk_64.o.
> + */
> + return 0;
> }

We rely on .symtab presence elsewhere in the code. See
elf_create_{rel,rela}_reloc_section(). However, there should never be a
problem. If there is a need to create a new reloc section (either for a
static call site, or ORC), there should always be a symbol to create it
for (or because of it).

Miroslav

2021-01-15 15:36:07

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH] objtool: Don't fail on missing symbol table

On Fri, Jan 15, 2021 at 12:31:26PM +0100, Miroslav Benes wrote:
> On Thu, 14 Jan 2021, Josh Poimboeuf wrote:
>
> > Thanks to a recent binutils change which doesn't generate unused
> > symbols, it's now possible for thunk_64.o be completely empty with
> > CONFIG_PREEMPTION: no text, no data, no symbols.
>
> "without CONFIG_PREEMPTION", or did I misunderstand?

Fixed.

>
> > We could edit the Makefile to only build that file when
> > CONFIG_PREEMPTION is enabled, but that will likely create confusion
> > if/when the thunks end up getting used by some other code again.
> >
> > Just ignore it and move on.
> >
> > Reported-by: Nathan Chancellor <[email protected]>
> > Signed-off-by: Josh Poimboeuf <[email protected]>
>
> Reviewed-by: Miroslav Benes <[email protected]>

Thanks!

>
> with the note below.
>
> > ---
> > tools/objtool/elf.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> > index be89c741ba9a..2b0f4f52f7b5 100644
> > --- a/tools/objtool/elf.c
> > +++ b/tools/objtool/elf.c
> > @@ -380,8 +380,11 @@ static int read_symbols(struct elf *elf)
> >
> > symtab = find_section_by_name(elf, ".symtab");
> > if (!symtab) {
> > - WARN("missing symbol table");
> > - return -1;
> > + /*
> > + * A missing symbol table is actually possible if it's an empty
> > + * .o file. This can happen for thunk_64.o.
> > + */
> > + return 0;
> > }
>
> We rely on .symtab presence elsewhere in the code. See
> elf_create_{rel,rela}_reloc_section(). However, there should never be a
> problem. If there is a need to create a new reloc section (either for a
> static call site, or ORC), there should always be a symbol to create it
> for (or because of it).

Right, let us hope so :-)

--
Josh