diff --git a/build.sh b/build.sh index 0e68645..3989297 100755 --- a/build.sh +++ b/build.sh @@ -149,6 +149,7 @@ pushd .. &>/dev/null popd &>/dev/null patch -p0 < $PATCH_DIR/cctools-ld64-1.patch patch -p0 < $PATCH_DIR/cctools-ld64-2.patch +patch -p1 < $PATCH_DIR/cctools-ld64-linux-ncpus.patch echo "" CONFFLAGS="--prefix=$TARGET_DIR --target=x86_64-apple-$TARGET " CONFFLAGS+="--disable-clang-as " diff --git a/patches/cctools-ld64-linux-ncpus.patch b/patches/cctools-ld64-linux-ncpus.patch new file mode 100644 index 0000000..a1a1c39 --- /dev/null +++ b/patches/cctools-ld64-linux-ncpus.patch @@ -0,0 +1,49 @@ +diff --git cctools/ld64/src/ld/InputFiles.cpp cctools/ld64/src/ld/InputFiles.cpp +index 13207e5..2b6f7bd 100644 +--- cctools/ld64/src/ld/InputFiles.cpp ++++ cctools/ld64/src/ld/InputFiles.cpp +@@ -43,6 +43,15 @@ + #include + #include + ++// ld64-port ++#ifdef __linux__ ++#ifndef __USE_GNU ++#define __USE_GNU ++#endif ++#include ++#endif ++// ld64-port end ++ + #include + #include + #include +@@ -913,6 +922,20 @@ InputFiles::InputFiles(Options& opts, const char** archName) + + // initialize info for parsing input files on worker threads + unsigned int ncpus; ++#ifdef __linux__ // ld64-port ++ cpu_set_t cs; ++ CPU_ZERO(&cs); ++ ++ if (!sched_getaffinity(0, sizeof(cs), &cs)) { ++ ncpus = 0; ++ ++ for (int i = 0; i < CPU_SETSIZE; i++) ++ if (CPU_ISSET(i, &cs)) ++ ncpus++; ++ } else { ++ ncpus = 1; ++ } ++#else + int mib[2]; + size_t len = sizeof(ncpus); + mib[0] = CTL_HW; +@@ -920,6 +943,7 @@ InputFiles::InputFiles(Options& opts, const char** archName) + if (sysctl(mib, 2, &ncpus, &len, NULL, 0) != 0) { + ncpus = 1; + } ++#endif + _availableWorkers = MIN(ncpus, files.size()); // max # workers we permit + _idleWorkers = 0; + diff --git a/tools/cpucount.c b/tools/cpucount.c index 3c51de5..3f06b8b 100644 --- a/tools/cpucount.c +++ b/tools/cpucount.c @@ -1,6 +1,6 @@ /*********************************************************************** * OSXCross * - * Copyright (C) 2013, 2014 by Thomas Poechtrager * + * Copyright (C) 2013-2016 by Thomas Poechtrager * * t.poechtrager@gmail.com * * * * This program is free software; you can redistribute it and/or * @@ -61,14 +61,15 @@ int getcpucount() { int i, cpucount = 0; CPU_ZERO(&cs); - sched_getaffinity(0, sizeof(cs), &cs); - for (i = 0; i < 128; i++) { + if (sched_getaffinity(0, sizeof(cs), &cs)) + return 1; + + for (i = 0; i < CPU_SETSIZE; i++) if (CPU_ISSET(i, &cs)) cpucount++; - } - return cpucount ? cpucount : 1; + return cpucount; #else #if defined(__FreeBSD__) || defined(__NetBSD__) || \ defined(__OpenBSD__) || defined(__DragonFly__) || \