From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Sathvika Vasireddy <sv@linux.ibm.com>,
Josh Poimboeuf <jpoimboe@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [RFC PATCH v1] objtool: Use target file endianness instead of a compiled constant
Date: Thu, 31 Mar 2022 08:10:29 +0000 [thread overview]
Message-ID: <2c2bcb5f-e9bd-d7fc-effd-81aed6bd27e6@csgroup.eu> (raw)
In-Reply-To: <20220331080814.GQ8939@worktop.programming.kicks-ass.net>
Le 31/03/2022 à 10:08, Peter Zijlstra a écrit :
> On Thu, Mar 31, 2022 at 09:52:07AM +0200, Christophe Leroy wrote:
>> Some architectures like powerpc support both endianness, it's
>> therefore not possible to fix the endianness via arch/endianness.h
>> because there is no easy way to get the target endianness at
>> build time.
>>
>> Use the endianness recorded in the file objtool is working on.
>>
>
>> +#include <objtool/elf.h>
>>
>> /*
>> - * Does a byte swap if target endianness doesn't match the host, i.e. cross
>> + * Does a byte swap if target file endianness doesn't match the host, i.e. cross
>> * compilation for little endian on big endian and vice versa.
>> * To be used for multi-byte values conversion, which are read from / about
>> * to be written to a target native endianness ELF file.
>> */
>> -#define bswap_if_needed(val) \
>> +static inline bool need_bswap(GElf_Ehdr *ehdr)
>> +{
>> + return (__BYTE_ORDER == __LITTLE_ENDIAN) ^
>> + (ehdr->e_ident[EI_DATA] == ELFDATA2LSB);
>> +}
>> +
>> +#define bswap_if_needed(ehdr, val) \
>> ({ \
>> __typeof__(val) __ret; \
>> + bool __need_bswap = need_bswap(ehdr); \
>> switch (sizeof(val)) { \
>> - case 8: __ret = __NEED_BSWAP ? bswap_64(val) : (val); break; \
>> - case 4: __ret = __NEED_BSWAP ? bswap_32(val) : (val); break; \
>> - case 2: __ret = __NEED_BSWAP ? bswap_16(val) : (val); break; \
>> + case 8: __ret = __need_bswap ? bswap_64(val) : (val); break; \
>> + case 4: __ret = __need_bswap ? bswap_32(val) : (val); break; \
>> + case 2: __ret = __need_bswap ? bswap_16(val) : (val); break; \
>> default: \
>> BUILD_BUG(); break; \
>> } \
>
> Far less painfull that I imagined it would be,.. but I think I prefer
> passing in elf, as opposed to elf->ehdr, would that work?
That's what I wanted to do in the beginning, but we don't have it in
orc_dump()
Christophe
prev parent reply other threads:[~2022-03-31 8:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-31 7:52 [RFC PATCH v1] objtool: Use target file endianness instead of a compiled constant Christophe Leroy
2022-03-31 8:08 ` Peter Zijlstra
2022-03-31 8:10 ` Christophe Leroy [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2c2bcb5f-e9bd-d7fc-effd-81aed6bd27e6@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=peterz@infradead.org \
--cc=sv@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox