Messages in this thread | | | Date | Fri, 2 Oct 2020 11:01:14 -0500 | From | Josh Poimboeuf <> | Subject | Re: [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
| |