lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 31 Mar 2022 08:10:29 +0000
From:   Christophe Leroy <christophe.leroy@...roup.eu>
To:     Peter Zijlstra <peterz@...radead.org>
CC:     Sathvika Vasireddy <sv@...ux.ibm.com>,
        Josh Poimboeuf <jpoimboe@...hat.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linuxppc-dev@...ts.ozlabs.org" <linuxppc-dev@...ts.ozlabs.org>
Subject: Re: [RFC PATCH v1] objtool: Use target file endianness instead of a
 compiled constant



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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ