Skip to contentSkip to conversation

objtool: Miscellaneous cleanup/fixes

PATCH In review Julien Thierry 2 participants 8 messages Sep 15, 2020 – Sep 21, 2020 objtool

lore
Share & tools
lore
#0 lore raw

cover objtool: Miscellaneous cleanup/fixes

Hi,

These patches provide some simple cleanup or lift small limitations found while working on the arm64 port.

They should apply on current tip/objtool/core branch

Cheers,

Julien

-->

Julien Thierry (3):
objtool: check: Remove useless tests
objtool: check: Ignore unreachable fake jumps
objtool: check: Handle calling non-function symbols in other sections

 tools/objtool/check.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

--
2.21.3

#1 lore raw

PATCH 1/3 objtool: check: Remove useless tests

save_reg already checks that the register being saved does not already have a saved state.

Remove redundant checks before processing a register storing operation.

---
 tools/objtool/check.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tools/objtool/check.c +2 -4
index 4e2f703b6a25..fd2edab8e672 100644
@@ -2030,7 +2030,7 @@ static int update_cfi_state(struct instruction *insn, struct cfi_state *cfi,
 				/* drap: push %rbp */
 				cfi->stack_size = 0;
 
-			} else if (regs[op->src.reg].base == CFI_UNDEFINED) {
+			} else {
 
 				/* drap: push %reg */
 				save_reg(cfi, op->src.reg, CFI_BP, -cfi->stack_size);
@@ -2059,9 +2059,7 @@ static int update_cfi_state(struct instruction *insn, struct cfi_state *cfi,
 
 				/* save drap offset so we know when to restore it */
 				cfi->drap_offset = op->dest.offset;
-			}
-
-			else if (regs[op->src.reg].base == CFI_UNDEFINED) {
+			} else {
 
 				/* drap: mov reg, disp(%rbp) */
 				save_reg(cfi, op->src.reg, CFI_BP, op->dest.offset);
Signature · 1 line
2.21.3
#2 lore raw

PATCH 2/3 objtool: check: Ignore unreachable fake jumps

In reply to Julien Thierry

It is possible for alternative code to unconditionally jump out of the alternative region. In such a case, if a fake jump is added at the end of the alternative instructions, the fake jump will never be reached. Since the fake jump is just a mean to make sure code validation does not go beyond the set of alternatives, reaching it is not a requirement.

---
 tools/objtool/check.c | 3 +++
 1 file changed, 3 insertions(+)
tools/objtool/check.c +3 -0
index fd2edab8e672..cd7c6698d316 100644
@@ -2648,6 +2648,9 @@ static bool ignore_unreachable_insn(struct instruction *insn)
 	    !strcmp(insn->sec->name, ".altinstr_aux"))
 		return true;
 
+	if (insn->type == INSN_JUMP_UNCONDITIONAL && insn->offset == FAKE_JUMP_OFFSET)
+		return true;
+
 	if (!insn->func)
 		return false;
 
Signature · 1 line
2.21.3
#3 lore raw

PATCH 3/3 objtool: check: Handle calling non-function symbols in other sections

In reply to Julien Thierry

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

Lookup such a symbol when no function is available.

---
 tools/objtool/check.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
tools/objtool/check.c +15 -5
index cd7c6698d316..500f63b3dcff 100644
@@ -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,
Signature · 1 line
2.21.3
#4 lore raw

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

Quoted 2 lines · Julien Thierry

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...)

Signature · 1 line
Josh
#5 lore raw

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

Quoted 6 lines · Josh Poimboeuf
Quoted 2 lines · Julien Thierry

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.

Signature · 1 line
Julien Thierry
#6 lore raw

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

Quoted 7 lines · Julien Thierry
Quoted 4 lines · Josh Poimboeuf
Quoted 2 lines · Julien Thierry

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

Quoted 7 lines
Quoted 2 lines

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.

Signature · 1 line
Josh
#7 lore raw
In reply to Julien Thierry
Quoted 6 lines · Julien Thierry

Hi,

These patches provide some simple cleanup or lift small limitations found while working on the arm64 port.

They should apply on current tip/objtool/core branch

I've got patches 1 & 2 queued up in jpoimboe/objtool/core.

Signature · 1 line
Josh