lkml.org 
[lkml]   [2020]   [Oct]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH v3 4/4] objtool: fix x86 orc generation on big endian cross compiles
On Thu, Oct 01, 2020 at 12:17:32AM +0200, Vasily Gorbik wrote:
> +++ b/tools/objtool/arch/x86/special.c
> @@ -9,7 +9,7 @@
>
> void arch_handle_alternative(unsigned short feature, struct special_alt *alt)
> {
> - switch (feature) {
> + switch (le16_to_cpu(feature)) {

It might be cleaner for the endian conversion to be done when the
'feature' value is first read.

feature = *(unsigned short *)(sec->data->d_buf + offset +
entry->feature);


> case X86_FEATURE_SMAP:
> /*
> * If UACCESS validation is enabled; force that alternative;
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 2df9f769412e..f20a4be2fb22 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -1370,7 +1370,7 @@ static int read_unwind_hints(struct objtool_file *file)
> cfa = &insn->cfi.cfa;
>
> if (hint->type == UNWIND_HINT_TYPE_RET_OFFSET) {
> - insn->ret_offset = hint->sp_offset;
> + insn->ret_offset = le16_to_cpu(hint->sp_offset);

Since this is common code, we might not always be able to assume the
value is little endian. Could you make a more generic conversion macro
which -- when the target ELF file's endianness doesn't match the host
CPU's -- does a byte swap? For example:

insn->ret_offset = bswap_if_needed(hint->sp_offset);

The macro could detect the type size, and would also know the
host/target endianness, and could swap accordingly. It could then be
called for all such multi-byte reads.

--
Josh

\
 
 \ /
  Last update: 2020-10-02 18:02    [W:0.540 / U:0.588 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site