Re: [PATCH] Current GNU libc: Declare htonl() via <arpa/inet.h>

"David H. Gutteridge" <[email protected]> Mon, 28 Oct 2024 12:41:36 -0400
Newsgroups gmane.os.netbsd.devel.toolchain
Message-ID <[email protected]>
On Mon, 28 Oct 2024 at 22:19:40 +0900, Izumi Tsutsui wrote:
>>   | Would be nice if somebody would comment on this (verified to not 
>> break
>>   | a build on NetBSD-current) or commit it.
>> 
>> Looks reasonable to me, I will get to it later tonight.
> 
> Maybe we can replace it with N_SETMAGIC() in <sys/exec_aout.h>
> (that already uses htobe32()):
> 
> ---
> #define N_SETMAGIC(ex,mag,mid,flag) \
>    ((ex).a_midmag = htobe32((uint32_t) \
>    ((((flag)&0x3f)<<26)|(((mid)&0x03ff)<<16)|(((mag)&0xffff)))))
> ---
> 
> We should also update another htonl() leftover in comment
> in <sys/exec_aout.h>?
> 
> ---
> /*
> * Header prepended to each a.out file.
> * only manipulate the a_midmag field via the
> * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros below.
> */
> struct exec {
> 	unsigned long a_midmag;	/* htonl(flags<<26 | mid<<16 | magic) */
> 	unsigned long a_text;	/* text segment size */

For mkubootimage.c (which is what I've looked at), I think it makes
most sense to convert htonl(3) and ntohl(3) use to their equivalents
found in sys/endian.h. mkubootimage.c already uses bswap32(3),
le64toh(3), and more anyway. I see all of the necessary sys/endian.h
functions are provided by NetBSD compat, so making these changes
indeed results in a successful tools build on Fedora 40 inclusive of
mkubootimage(1). (I've been sitting on this change, hadn't got around
to emailing about it and/or committing. But I can do so soon.)

Regards,

Dave