Module Name: src
Committed By: martin
Date: Sun Dec 15 12:57:33 UTC 2024
Modified Files:
src/sys/arch/hppa/stand/mkboot [netbsd-10]: mkboot.c
src/sys/arch/powerpc/stand/mkbootimage [netbsd-10]: mkbootimage.c
src/usr.bin/elf2aout [netbsd-10]: elf2aout.c
Log Message:
Pull up following revision(s) (requested by gutteridge in ticket #1019):
sys/arch/hppa/stand/mkboot/mkboot.c: revision 1.5
sys/arch/powerpc/stand/mkbootimage/mkbootimage.c: revision 1.21
usr.bin/elf2aout/elf2aout.c: revision 1.25
mkboot.c: ensure all functions are declared
Addresses build failure issue on current Linux distros that have a GCC
with implicit-function-declaration baked in as an error. Use be32toh(3)
instead of ntohl(3), seems to make more sense stylistically. Build
tested on Fedora 40.
Issue reported by Jan-Benedict Glaw. Also relevant to PR lib/58674.
elf2aout.c: switch to use htobe32(3)
As discussed on tech-toolchain. Tested with virt68k tools build on
Fedora 40. (Relevant to PR lib/58674.)
mkbootimage.c: consistently use sa_htobe32(2)
There were 38 calls to sa_htobe32(2) and two to htonl(3), mixed even
within the same function, with arpa/inet.h not included. (It's unclear
why this varied, as the original version of this file first checked in
included this discrepancy.)
Addresses build failure issue on current Linux distros that have a GCC
with implicit-function-declaration baked in as an error. Build tested
on Fedora 40.
Issue reported by Jan-Benedict Glaw. Also relevant to PR lib/58674.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.2.48.1 src/sys/arch/hppa/stand/mkboot/mkboot.c
cvs rdiff -u -r1.19 -r1.19.48.1 \
src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
cvs rdiff -u -r1.23.10.1 -r1.23.10.2 src/usr.bin/elf2aout/elf2aout.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/hppa/stand/mkboot/mkboot.c
diff -u src/sys/arch/hppa/stand/mkboot/mkboot.c:1.2 src/sys/arch/hppa/stand/mkboot/mkboot.c:1.2.48.1
--- src/sys/arch/hppa/stand/mkboot/mkboot.c:1.2 Thu Jan 21 17:00:23 2016
+++ src/sys/arch/hppa/stand/mkboot/mkboot.c Sun Dec 15 12:57:32 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: mkboot.c,v 1.2 2016/01/21 17:00:23 christos Exp $ */
+/* $NetBSD: mkboot.c,v 1.2.48.1 2024/12/15 12:57:32 martin Exp $ */
/* $OpenBSD: mkboot.c,v 1.9 2001/05/17 00:57:55 pvalchev Exp $ */
@@ -53,6 +53,7 @@ static char rcsid[] = "$OpenBSD: mkboot.
#endif
#include <sys/param.h>
+#include <sys/endian.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <string.h>
@@ -83,7 +84,7 @@ static char rcsid[] = "$OpenBSD: mkboot.
* Header prepended to each a.out file.
*/
struct exec {
- u_long a_midmag; /* htonl(flags<<26 | mid<<16 | magic) */
+ u_long a_midmag; /* htobe32(flags<<26 | mid<<16 | magic) */
u_long a_text; /* text segment size */
u_long a_data; /* initialized data size */
u_long a_bss; /* uninitialized data size */
@@ -101,7 +102,7 @@ struct exec {
#define N_GETMAGIC(ex) \
((((ex).a_midmag)&0xffff0000) ? \
- (ntohl((uint32_t)((ex).a_midmag))&0xffff) : ((ex).a_midmag))
+ (be32toh((uint32_t)((ex).a_midmag))&0xffff) : ((ex).a_midmag))
#include <stdio.h>
#include <ctype.h>
Index: src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
diff -u src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.19 src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.19.48.1
--- src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.19 Thu Jan 21 17:14:05 2016
+++ src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c Sun Dec 15 12:57:32 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: mkbootimage.c,v 1.19 2016/01/21 17:14:05 christos Exp $ */
+/* $NetBSD: mkbootimage.c,v 1.19.48.1 2024/12/15 12:57:32 martin Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -579,11 +579,11 @@ rs6000_build_image(char *kernel, char *b
printf("writing records\n");
memcpy(swapped, &bootrec, sizeof(rs6000_boot_record_t));
for (i=0; i < 128; i++)
- swapped[i] = htonl(swapped[i]);
+ swapped[i] = sa_htobe32(swapped[i]);
write(rs6000_fd, swapped, sizeof(rs6000_boot_record_t));
memcpy(swapped, &confrec, sizeof(rs6000_config_record_t));
for (i=0; i < 128; i++)
- swapped[i] = htonl(swapped[i]);
+ swapped[i] = sa_htobe32(swapped[i]);
write(rs6000_fd, swapped, sizeof(rs6000_config_record_t));
free(kern_img);
Index: src/usr.bin/elf2aout/elf2aout.c
diff -u src/usr.bin/elf2aout/elf2aout.c:1.23.10.1 src/usr.bin/elf2aout/elf2aout.c:1.23.10.2
--- src/usr.bin/elf2aout/elf2aout.c:1.23.10.1 Sun Nov 17 13:32:53 2024
+++ src/usr.bin/elf2aout/elf2aout.c Sun Dec 15 12:57:32 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: elf2aout.c,v 1.23.10.1 2024/11/17 13:32:53 martin Exp $ */
+/* $NetBSD: elf2aout.c,v 1.23.10.2 2024/12/15 12:57:32 martin Exp $ */
/*
* Copyright (c) 1995
@@ -43,6 +43,7 @@
#endif
#include <sys/types.h>
+#include <sys/endian.h>
#include <sys/exec_aout.h>
#include <sys/exec_elf.h>
@@ -56,8 +57,6 @@
#include <string.h>
#include <unistd.h>
-#include <arpa/inet.h>
-
struct sect {
/* should be unsigned long, but assume no a.out binaries on LP64 */
@@ -372,7 +371,7 @@ main(int argc, char **argv)
/* We now have enough information to cons up an a.out header... */
mid = get_mid(&ex);
- aex.a_midmag = (u_long)htonl(((u_long)symflag << 26)
+ aex.a_midmag = (u_long)htobe32(((u_long)symflag << 26)
| ((u_long)mid << 16) | magic);
aex.a_text = text.len;