2020-09-15 07:59:39

by Julien Thierry

[permalink] [raw]
Subject: [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections

Relocation for a call destination could point to a symbol that has
type STT_NOTYPE.

Lookup such a symbol when no function is available.

Signed-off-by: Julien Thierry <[email protected]>
---
tools/objtool/check.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index cd7c6698d316..500f63b3dcff 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -815,6 +815,17 @@ static void remove_insn_ops(struct instruction *insn)
}
}

+static struct symbol *find_call_destination(struct section *sec, unsigned long offset)
+{
+ struct symbol *call_dest;
+
+ call_dest = find_func_by_offset(sec, offset);
+ if (!call_dest)
+ call_dest = find_symbol_by_offset(sec, offset);
+
+ return call_dest;
+}
+
/*
* Find the destination instructions for all calls.
*/
@@ -832,9 +843,7 @@ static int add_call_destinations(struct objtool_file *file)
insn->offset, insn->len);
if (!reloc) {
dest_off = arch_jump_destination(insn);
- insn->call_dest = find_func_by_offset(insn->sec, dest_off);
- if (!insn->call_dest)
- insn->call_dest = find_symbol_by_offset(insn->sec, dest_off);
+ insn->call_dest = find_call_destination(insn->sec, dest_off);

if (insn->ignore)
continue;
@@ -852,8 +861,9 @@ static int add_call_destinations(struct objtool_file *file)

} else if (reloc->sym->type == STT_SECTION) {
dest_off = arch_dest_reloc_offset(reloc->addend);
- insn->call_dest = find_func_by_offset(reloc->sym->sec,
- dest_off);
+ insn->call_dest = find_call_destination(reloc->sym->sec,
+ dest_off);
+
if (!insn->call_dest) {
WARN_FUNC("can't find call dest symbol at %s+0x%lx",
insn->sec, insn->offset,
--
2.21.3


2020-09-18 20:09:15

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections

On Tue, Sep 15, 2020 at 08:53:18AM +0100, Julien Thierry wrote:
> Relocation for a call destination could point to a symbol that has
> type STT_NOTYPE.

Then shouldn't the callee be changed to STT_FUNC?

(Apologies if we discussed this one before...)

--
Josh

2020-09-21 10:00:27

by Julien Thierry

[permalink] [raw]
Subject: Re: [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections



On 9/18/20 9:07 PM, Josh Poimboeuf wrote:
> On Tue, Sep 15, 2020 at 08:53:18AM +0100, Julien Thierry wrote:
>> Relocation for a call destination could point to a symbol that has
>> type STT_NOTYPE.
>
> Then shouldn't the callee be changed to STT_FUNC?
>

Not if it's a code symbol that does not follow standard calling convention.

It's really the same case as the !reloc, except this time it's in a
different .text section. In arm64 there are different sections that are
used (.text for basic code, .idmap.text for code mapped in a manner
where virtual address == physical address, .hyp.text for kvm priviledged
code, .tramp.text for trampolines...). There aren't many cases, but some
symbols reference symbols in other sections, but the symbol being called
isn't a proper function.



--
Julien Thierry

2020-09-21 14:41:53

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH 3/3] objtool: check: Handle calling non-function symbols in other sections

On Mon, Sep 21, 2020 at 10:56:05AM +0100, Julien Thierry wrote:
>
>
> On 9/18/20 9:07 PM, Josh Poimboeuf wrote:
> > On Tue, Sep 15, 2020 at 08:53:18AM +0100, Julien Thierry wrote:
> > > Relocation for a call destination could point to a symbol that has
> > > type STT_NOTYPE.
> >
> > Then shouldn't the callee be changed to STT_FUNC?
> >
>
> Not if it's a code symbol that does not follow standard calling convention.
>
> It's really the same case as the !reloc, except this time it's in a
> different .text section.

Yeah, that makes sense. I'll take this one as well.

--
Josh