Skip to content

Commit

Permalink
netbsd: add cross target
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewbauer committed Feb 26, 2019
1 parent 1b26752 commit aab8c7b
Show file tree
Hide file tree
Showing 9 changed files with 706 additions and 312 deletions.
1 change: 1 addition & 0 deletions lib/systems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ rec {
else if final.isAndroid then "bionic"
else if final.isLinux /* default */ then "glibc"
else if final.isAvr then "avrlibc"
else if final.isNetBSD then "nblibc"
# TODO(@Ericson2314) think more about other operating systems
else "native/impure";
extensions = {
Expand Down
7 changes: 7 additions & 0 deletions lib/systems/examples.nix
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,11 @@ rec {
libc = "msvcrt"; # This distinguishes the mingw (non posix) toolchain
platform = {};
};

# BSDs

amd64-netbsd = {
config = "x86_64-unknown-netbsd";
libc = "nblibc";
};
}
1 change: 1 addition & 0 deletions pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ let
/**/ if libc == null then null
else if targetPlatform.libc == "musl" then "${libc_lib}/lib/ld-musl-*"
else if targetPlatform.libc == "bionic" then "/system/bin/linker"
else if targetPlatform.libc == "nblibc" then "${libc_lib}/libexec/ld.elf_so"
else if targetPlatform.system == "i686-linux" then "${libc_lib}/lib/ld-linux.so.2"
else if targetPlatform.system == "x86_64-linux" then "${libc_lib}/lib/ld-linux-x86-64.so.2"
# ARM with a wildcard, which can be "" or "-armhf".
Expand Down
4 changes: 4 additions & 0 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ stdenv.mkDerivation {
hardening_unsupported_flags+=" stackprotector pic"
''

+ optionalString targetPlatform.isNetBSD ''
hardening_unsupported_flags+=" stackprotector fortify"
''

+ optionalString (targetPlatform.libc == "newlib") ''
hardening_unsupported_flags+=" stackprotector fortify pie pic"
''
Expand Down
4 changes: 4 additions & 0 deletions pkgs/development/compilers/gcc/7/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ let version = "7.4.0";
./riscv-no-relax.patch
]
++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch
++ optionals targetPlatform.isNetBSD [
../libstdc++-netbsd-ctypes.patch
]
++ optional noSysDirs ../no-sys-dirs.patch
++ optional (hostPlatform != buildPlatform) (fetchpatch { # XXX: Refine when this should be applied
url = "https://git.busybox.net/buildroot/plain/package/gcc/7.1.0/0900-remove-selftests.patch?id=11271540bfe6adafbc133caf6b5b902a816f5f02";
Expand Down Expand Up @@ -302,6 +305,7 @@ stdenv.mkDerivation ({
"--disable-gnu-indirect-function"
]
++ optional (targetPlatform.isAarch64) "--enable-fix-cortex-a53-843419"
++ optional targetPlatform.isNetBSD "--disable-libcilkrts"
;

targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
Expand Down
141 changes: 141 additions & 0 deletions pkgs/development/compilers/gcc/libstdc++-netbsd-ctypes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
diff --git a/libstdc++-v3/config/os/bsd/netbsd/ctype_base.h b/libstdc++-v3/config/os/bsd/netbsd/ctype_base.h
index ff3ec893974..21eccf9fde1 100644
--- a/libstdc++-v3/config/os/bsd/netbsd/ctype_base.h
+++ b/libstdc++-v3/config/os/bsd/netbsd/ctype_base.h
@@ -38,40 +38,46 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// @brief Base class for ctype.
struct ctype_base
{
- // Non-standard typedefs.
- typedef const unsigned char* __to_type;

// NB: Offsets into ctype<char>::_M_table force a particular size
// on the mask type. Because of this, we don't use an enum.
- typedef unsigned char mask;

#ifndef _CTYPE_U
- static const mask upper = _U;
- static const mask lower = _L;
- static const mask alpha = _U | _L;
- static const mask digit = _N;
- static const mask xdigit = _N | _X;
- static const mask space = _S;
- static const mask print = _P | _U | _L | _N | _B;
- static const mask graph = _P | _U | _L | _N;
- static const mask cntrl = _C;
- static const mask punct = _P;
- static const mask alnum = _U | _L | _N;
+ // Non-standard typedefs.
+ typedef const unsigned char* __to_type;
+
+ typedef unsigned char mask;
+
+ static const mask upper = _U;
+ static const mask lower = _L;
+ static const mask alpha = _U | _L;
+ static const mask digit = _N;
+ static const mask xdigit = _N | _X;
+ static const mask space = _S;
+ static const mask print = _P | _U | _L | _N | _B;
+ static const mask graph = _P | _U | _L | _N;
+ static const mask cntrl = _C;
+ static const mask punct = _P;
+ static const mask alnum = _U | _L | _N;
#else
- static const mask upper = _CTYPE_U;
- static const mask lower = _CTYPE_L;
- static const mask alpha = _CTYPE_U | _CTYPE_L;
- static const mask digit = _CTYPE_N;
- static const mask xdigit = _CTYPE_N | _CTYPE_X;
- static const mask space = _CTYPE_S;
- static const mask print = _CTYPE_P | _CTYPE_U | _CTYPE_L | _CTYPE_N | _CTYPE_B;
- static const mask graph = _CTYPE_P | _CTYPE_U | _CTYPE_L | _CTYPE_N;
- static const mask cntrl = _CTYPE_C;
- static const mask punct = _CTYPE_P;
- static const mask alnum = _CTYPE_U | _CTYPE_L | _CTYPE_N;
+ typedef const unsigned short* __to_type;
+
+ typedef unsigned short mask;
+
+ static const mask upper = _CTYPE_U;
+ static const mask lower = _CTYPE_L;
+ static const mask alpha = _CTYPE_A;
+ static const mask digit = _CTYPE_D;
+ static const mask xdigit = _CTYPE_X;
+ static const mask space = _CTYPE_S;
+ static const mask print = _CTYPE_R;
+ static const mask graph = _CTYPE_G;
+ static const mask cntrl = _CTYPE_C;
+ static const mask punct = _CTYPE_P;
+ static const mask alnum = _CTYPE_A | _CTYPE_D;
#endif
#if __cplusplus >= 201103L
- static const mask blank = space;
+ static const mask blank = space;
#endif
};

diff --git a/libstdc++-v3/config/os/bsd/netbsd/ctype_configure_char.cc b/libstdc++-v3/config/os/bsd/netbsd/ctype_configure_char.cc
index ed3b7cd0d6a..33358e8f5d8 100644
--- a/libstdc++-v3/config/os/bsd/netbsd/ctype_configure_char.cc
+++ b/libstdc++-v3/config/os/bsd/netbsd/ctype_configure_char.cc
@@ -38,11 +38,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

// Information as gleaned from /usr/include/ctype.h

- extern "C" const u_int8_t _C_ctype_[];
-
const ctype_base::mask*
ctype<char>::classic_table() throw()
- { return _C_ctype_ + 1; }
+ { return _C_ctype_tab_ + 1; }

ctype<char>::ctype(__c_locale, const mask* __table, bool __del,
size_t __refs)
@@ -69,14 +67,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

char
ctype<char>::do_toupper(char __c) const
- { return ::toupper((int) __c); }
+ { return ::toupper((int)(unsigned char) __c); }

const char*
ctype<char>::do_toupper(char* __low, const char* __high) const
{
while (__low < __high)
{
- *__low = ::toupper((int) *__low);
+ *__low = ::toupper((int)(unsigned char) *__low);
++__low;
}
return __high;
@@ -84,14 +82,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

char
ctype<char>::do_tolower(char __c) const
- { return ::tolower((int) __c); }
+ { return ::tolower((int)(unsigned char) __c); }

const char*
ctype<char>::do_tolower(char* __low, const char* __high) const
{
while (__low < __high)
{
- *__low = ::tolower((int) *__low);
+ *__low = ::tolower((int)(unsigned char) *__low);
++__low;
}
return __high;
diff --git a/libstdc++-v3/config/os/bsd/netbsd/ctype_inline.h b/libstdc++-v3/config/os/bsd/netbsd/ctype_inline.h
index ace1120fba2..3234ce17c70 100644
--- a/libstdc++-v3/config/os/bsd/netbsd/ctype_inline.h
+++ b/libstdc++-v3/config/os/bsd/netbsd/ctype_inline.h
@@ -48,7 +48,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
is(const char* __low, const char* __high, mask* __vec) const
{
while (__low < __high)
- *__vec++ = _M_table[*__low++];
+ *__vec++ = _M_table[(unsigned char)*__low++];
return __high;
}

122 changes: 122 additions & 0 deletions pkgs/os-specific/bsd/netbsd/builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
source $stdenv/setup

# NetBSD makefiles should be able to detect this
# but without they end up using gcc on Darwin stdenv
addMakeFlags() {
export setOutputFlags=

export LIBCRT0=
export LIBCRTI=
export LIBCRTEND=
export LIBCRTBEGIN=
export LIBC=
export LIBUTIL=
export LIBSSL=
export LIBCRYPTO=
export LIBCRYPT=
export LIBCURSES=
export LIBTERMINFO=
export LIBM=
export LIBL=

export _GCC_CRTBEGIN=
export _GCC_CRTBEGINS=
export _GCC_CRTEND=
export _GCC_CRTENDS=
export _GCC_LIBGCCDIR=
export _GCC_CRTI=
export _GCC_CRTN=
export _GCC_CRTDIR=

# Definitions passed to share/mk/*.mk. Should be pretty simple -
# eventually maybe move it to a configure script.
export DESTDIR=
export USETOOLS=never
export NOCLANGERROR=yes
export NOGCCERROR=yes
export LEX=flex
export MKUNPRIVED=yes
export EXTERNAL_TOOLCHAIN=yes

export INSTALL_FILE="install -U -c"
export INSTALL_DIR="xinstall -U -d"
export INSTALL_LINK="install -U -l h"
export INSTALL_SYMLINK="install -U -l s"

makeFlags="MACHINE=$MACHINE $makeFlags"
makeFlags="MACHINE_ARCH=$MACHINE_ARCH $makeFlags"
makeFlags="AR=$AR $makeFlags"
makeFlags="CC=$CC $makeFlags"
makeFlags="CPP=$CPP $makeFlags"
makeFlags="CXX=$CXX $makeFlags"
makeFlags="LD=$LD $makeFlags"
makeFlags="STRIP=$STRIP $makeFlags"

makeFlags="BINDIR=${!outputBin}/bin $makeFlags"
makeFlags="LIBDIR=${!outputLib}/lib $makeFlags"
makeFlags="SHLIBDIR=${!outputLib}/lib $makeFlags"
makeFlags="MANDIR=${!outputMan}/share/man $makeFlags"
makeFlags="INFODIR=${!outputInfo}/share/info $makeFlags"
makeFlags="DOCDIR=${!outputDoc}/share/doc $makeFlags"
makeFlags="LOCALEDIR=${!outputLib}/share/locale $makeFlags"

# Parallel building. Needs the space.
makeFlags="-j $NIX_BUILD_CORES $makeFlags"
}

setNetBSDSourceDir() {
# merge together all extra paths
# there should be a better way to do this
sourceRoot=$PWD/$sourceRoot
export NETBSDSRCDIR=$sourceRoot
export BSDSRCDIR=$NETBSDSRCDIR
export _SRC_TOP_=$NETBSDSRCDIR
chmod -R u+w $sourceRoot
for path in $extraPaths; do
cd $path
find . -type d -exec mkdir -p $sourceRoot/\{} \;
find . -type f -exec cp -pr \{} $sourceRoot/\{} \;
chmod -R u+w $sourceRoot
done

cd $sourceRoot
if [ -d "$NETBSD_PATH" ]
then sourceRoot=$sourceRoot/$NETBSD_PATH
fi
}

includesPhase() {
if [ -z "${skipIncludesPhase:-}" ]; then

local flagsArray=(
$makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
DESTDIR=${!outputInclude} includes
)

echoCmd 'includes flags' "${flagsArray[@]}"
make ${makefile:+-f $makefile} "${flagsArray[@]}"

moveUsrDir

fi
}

moveUsrDir() {
if [ -d $prefix ]; then
# Remove lingering /usr references
if [ -d $prefix/usr ]; then
cd $prefix/usr
find . -type d -exec mkdir -p $out/\{} \;
find . \( -type f -o -type l \) -exec mv \{} $out/\{} \;
fi

find $prefix -type d -empty -delete
fi
}

postUnpackHooks+=(setNetBSDSourceDir)
preConfigureHooks+=(addMakeFlags)
preInstallHooks+=(includesPhase)
fixupOutputHooks+=(moveUsrDir)

genericBuild
Loading

0 comments on commit aab8c7b

Please sign in to comment.