Commit c752c887 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Zheng Zengkai
Browse files

objtool: Fix objtool regression on x32 systems

stable inclusion
from stable-v5.10.133
commit 236b959da9d145c311f9daa65e3fbbe1a3c9c9af
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5YVKO

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=236b959da9d145c311f9daa65e3fbbe1a3c9c9af



--------------------------------

commit 22682a07 upstream.

Commit c087c6e7 ("objtool: Fix type of reloc::addend") failed to
appreciate cross building from ILP32 hosts, where 'int' == 'long' and
the issue persists.

As such, use s64/int64_t/Elf64_Sxword for this field and suffer the
pain that is ISO C99 printf formats for it.

Fixes: c087c6e7 ("objtool: Fix type of reloc::addend")
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
[peterz: reword changelog, s/long long/s64/]
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Cc: <stable@vger.kernel.org>
Link: https://lkml.kernel.org/r/alpine.LRH.2.02.2205161041260.11556@file01.intranet.prod.int.rdu2.redhat.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
Acked-by: default avatarXie XiuQi <xiexiuqi@huawei.com>
parent 32553103
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -5,6 +5,7 @@


#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/mman.h>
#include <sys/mman.h>


#include "builtin.h"
#include "builtin.h"
@@ -468,12 +469,12 @@ static int add_dead_ends(struct objtool_file *file)
		else if (reloc->addend == reloc->sym->sec->len) {
		else if (reloc->addend == reloc->sym->sec->len) {
			insn = find_last_insn(file, reloc->sym->sec);
			insn = find_last_insn(file, reloc->sym->sec);
			if (!insn) {
			if (!insn) {
				WARN("can't find unreachable insn at %s+0x%lx",
				WARN("can't find unreachable insn at %s+0x%" PRIx64,
				     reloc->sym->sec->name, reloc->addend);
				     reloc->sym->sec->name, reloc->addend);
				return -1;
				return -1;
			}
			}
		} else {
		} else {
			WARN("can't find unreachable insn at %s+0x%lx",
			WARN("can't find unreachable insn at %s+0x%" PRIx64,
			     reloc->sym->sec->name, reloc->addend);
			     reloc->sym->sec->name, reloc->addend);
			return -1;
			return -1;
		}
		}
@@ -503,12 +504,12 @@ static int add_dead_ends(struct objtool_file *file)
		else if (reloc->addend == reloc->sym->sec->len) {
		else if (reloc->addend == reloc->sym->sec->len) {
			insn = find_last_insn(file, reloc->sym->sec);
			insn = find_last_insn(file, reloc->sym->sec);
			if (!insn) {
			if (!insn) {
				WARN("can't find reachable insn at %s+0x%lx",
				WARN("can't find reachable insn at %s+0x%" PRIx64,
				     reloc->sym->sec->name, reloc->addend);
				     reloc->sym->sec->name, reloc->addend);
				return -1;
				return -1;
			}
			}
		} else {
		} else {
			WARN("can't find reachable insn at %s+0x%lx",
			WARN("can't find reachable insn at %s+0x%" PRIx64,
			     reloc->sym->sec->name, reloc->addend);
			     reloc->sym->sec->name, reloc->addend);
			return -1;
			return -1;
		}
		}
+1 −1
Original line number Original line Diff line number Diff line
@@ -459,7 +459,7 @@ static struct section *elf_create_reloc_section(struct elf *elf,
						int reltype);
						int reltype);


int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
		  unsigned int type, struct symbol *sym, long addend)
		  unsigned int type, struct symbol *sym, s64 addend)
{
{
	struct reloc *reloc;
	struct reloc *reloc;


+2 −2
Original line number Original line Diff line number Diff line
@@ -74,7 +74,7 @@ struct reloc {
	struct symbol *sym;
	struct symbol *sym;
	unsigned long offset;
	unsigned long offset;
	unsigned int type;
	unsigned int type;
	long addend;
	s64 addend;
	int idx;
	int idx;
	bool jump_table_start;
	bool jump_table_start;
};
};
@@ -128,7 +128,7 @@ struct elf *elf_open_read(const char *name, int flags);
struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr);
struct section *elf_create_section(struct elf *elf, const char *name, unsigned int sh_flags, size_t entsize, int nr);


int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
		  unsigned int type, struct symbol *sym, long addend);
		  unsigned int type, struct symbol *sym, s64 addend);
int elf_add_reloc_to_insn(struct elf *elf, struct section *sec,
int elf_add_reloc_to_insn(struct elf *elf, struct section *sec,
			  unsigned long offset, unsigned int type,
			  unsigned long offset, unsigned int type,
			  struct section *insn_sec, unsigned long insn_off);
			  struct section *insn_sec, unsigned long insn_off);