tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Cross Compile NetBSD on OpenBSD



On Sat, 31 Jan 2009, Alexander Bluhm wrote:
> With these tiny changes I am able to build the NetBSD toolchain on
> OpenBSD.  Both are i386, I have not tested other architectures.
> Kernel compiles and runs, I have not tried userland yet.

Thank you for this report.

> OpenBSD's uname -p is not compatible to NetBSD, e.g. it gives this
> string and the () confuse build.sh.
> Intel(R) Core(TM)2 CPU T5600 @ 1.83GHz ("GenuineIntel" 686-class)

Please try the appended patch, which ignores the output from "uname -p"
if it is the string "unknown" (reported to be produced by Cygwin), or if
it contains any characters other than [a-z0-9].

> Your texinfo/info/echo-area.c uses intptr_t, on OpenBSD you have
> to include stdint.h for that.

I agree with your patch, and will apply it.

> The WA() defines seem to be a little different.  The additional ;
> should not hurt anybody.
> 
> Index: lib/libc/hash/hashhl.c
> ===================================================================
> RCS file: /data/mirror/netbsd/cvs/src/lib/libc/hash/hashhl.c,v
> retrieving revision 1.1
> diff -u -p -r1.1 hashhl.c
> --- lib/libc/hash/hashhl.c    28 Sep 2005 16:31:45 -0000      1.1
> +++ lib/libc/hash/hashhl.c    30 Jan 2009 20:58:39 -0000
> @@ -32,10 +32,10 @@
>  
>  #if !defined(_KERNEL) && defined(__weak_alias)
>  #define      WA(a,b) __weak_alias(a,b)
> -WA(FNPREFIX(End),CONCAT(_,FNPREFIX(End)))
> -WA(FNPREFIX(FileChunk),CONCAT(_,FNPREFIX(FileChunk)))
> -WA(FNPREFIX(File),CONCAT(_,FNPREFIX(File)))
> -WA(FNPREFIX(Data),CONCAT(_,FNPREFIX(Data)))
> +WA(FNPREFIX(End),CONCAT(_,FNPREFIX(End)));
> +WA(FNPREFIX(FileChunk),CONCAT(_,FNPREFIX(FileChunk)));
> +WA(FNPREFIX(File),CONCAT(_,FNPREFIX(File)));
> +WA(FNPREFIX(Data),CONCAT(_,FNPREFIX(Data)));
>  #undef WA
>  #endif

It does look harmless to add semicolons here, but I'd like a second
opinion before I apply this part of your patch.

> The uname -p issue again.  Don't know how to fix this in a compatible
> way.  Perhaps you ask the GNU autoconf people :-)

This is addressed in the appended patch.

> The OpenBSD linker prints warnings whenever strcpy() is used as it
> is considered insecure.  These warnings confuse build.sh.  So I
> replaced strcpy() with strncpy() although it cannot be exploited
> in this case.

In what way do the warnings confuse build.sh?  I'd prefer not to change
safe uses of strcpy to use strncpy instead.

> OpenBSD include files define swap..() as a macro.  This collides
> with the inline functions.

pwd_mkdb should probably be changed to follow the NetSBD convention of
using the bswap{16,32,64} macros defined in machine/bswap.h, instead of
its own swap{16,32,64} functions.

--apb (Alan Barrett)

Index: build.sh
===================================================================
--- build.sh    3 Jan 2009 08:23:00 -0000       1.200
+++ build.sh    1 Feb 2009 15:16:43 -0000
@@ -163,14 +163,23 @@
        [ -f share/mk/bsd.own.mk ] ||
            bomb "src/share/mk is missing; please re-fetch the source tree"
 
-       # Find information about the build platform.  Note that "uname -p"
-       # is not part of POSIX, but NetBSD's uname -p prints MACHINE_ARCH,
-       # while uname -m prints MACHINE.
+       # Find information about the build platform.  This should be
+       # kept in sync with _HOST_OSNAME, _HOST_OSREL, and _HOST_ARCH
+       # variables in share/mk/bsd.sys.mk.
+       #
+       # Note that "uname -p" is not part of POSIX, but we want uname_p
+       # to be set to the host MACHINE_ARCH, if possible.  On systems
+       # where "uname -p" fails, prints "unknown", or prints a string
+       # that does not look like an identifier, fall back to using the
+       # output from "uname -m" instead.
        #
        uname_s=$(uname -s 2>/dev/null)
        uname_r=$(uname -r 2>/dev/null)
        uname_m=$(uname -m 2>/dev/null)
-       uname_p=$(uname -p 2>/dev/null || uname -m 2>/dev/null)
+       uname_p=$(uname -p 2>/dev/null || echo "unknown")
+       case "${uname_p}" in
+       ''|unknown|*[^a-z0-9]*) uname_p="${uname_m}" ;;
+       esac
 
        # If $PWD is a valid name of the current directory, POSIX mandates
        # that pwd return it by default which causes problems in the
Index: share/mk/bsd.own.mk
===================================================================
--- share/mk/bsd.own.mk 30 Dec 2008 21:31:10 -0000      1.553
+++ share/mk/bsd.own.mk 1 Feb 2009 15:18:32 -0000
@@ -125,10 +125,16 @@
 .if !defined(HOST_OSTYPE)
 _HOST_OSNAME!= uname -s
 _HOST_OSREL!=  uname -r
-_HOST_ARCH!=   uname -p 2>/dev/null || uname -m
+# For _HOST_ARCH, if uname -p fails, or prints "unknown", or prints
+# something that does not look like an identifier, then use uname -m.
+_HOST_ARCH!=   uname -p 2>/dev/null
+_HOST_ARCH:=   ${HOST_ARCH:tW:C/.*[^a-z0-9].*//:S/unknown//}
+.if empty(_HOST_ARCH)
+_HOST_ARCH!=   uname -m
+.endif
 HOST_OSTYPE:=  ${_HOST_OSNAME}-${_HOST_OSREL:C/\([^\)]*\)//g:[*]:C/ 
/_/g}-${_HOST_ARCH:C/\([^\)]*\)//g:[*]:C/ /_/g}
 .MAKEOVERRIDES+= HOST_OSTYPE
-.endif
+.endif # !defined(HOST_OSTYPE)
 
 .if ${USETOOLS} == "yes"                                               # {
 


Home | Main Index | Thread Index | Old Index