Various Cygwin fixes (#87, #88)

This commit is contained in:
Thomas Pöchtrager 2016-09-22 18:58:45 +02:00
parent c270662f73
commit 233b1d8860
6 changed files with 121 additions and 5 deletions

View File

@ -16,11 +16,12 @@ Click on setup-*.exe and install the following packages:
For LTO support you will also need:
`libllvm-devel`, `libllvm` and `gendef`
`libllvm-devel`, `libllvm`, `libedit` and `libffi`
The cygLTO.dll import library is missing, create it by hand:
The Cygwin package of libLLVM lacks the LTO library, but you can create that dll
by issuing the following command:
`gendef /bin/cygLTO.dll && dlltool -d cygLTO.def -l /lib/libLTO.dll.a && rm cygLTO.def`
`./tools/gen_cyglto_dll.sh`
#### Step 2: ####

View File

@ -150,6 +150,9 @@ 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-misc-fixes.patch
pushd .. &>/dev/null
patch -p0 < $PATCH_DIR/cctools-ld64-cygwin-buildfix.patch
popd &>/dev/null
echo ""
CONFFLAGS="--prefix=$TARGET_DIR --target=x86_64-apple-$TARGET "
CONFFLAGS+="--disable-clang-as "

View File

@ -0,0 +1,60 @@
diff --git cctools/configure.ac cctools/configure.ac
index 56e8f24..5219e3d 100644
--- cctools/configure.ac
+++ cctools/configure.ac
@@ -49,7 +49,8 @@ case $host_os in
;;
cygwin* )
iscygwin=yes
- EXTRAFLAGS="-D__LARGE64_FILES -fno-PIC"
+ # https://github.com/tpoechtrager/osxcross/issues/87
+ EXTRAFLAGS="-D__LARGE64_FILES -D_GNU_SOURCE -fno-PIC"
WARNINGS="-Wno-attributes"
XCC="gcc"
XCXX="g++"
diff --git cctools/include/foreign/machine/endian.h cctools/include/foreign/machine/endian.h
index 6cf3901..0920fd6 100644
--- cctools/include/foreign/machine/endian.h
+++ cctools/include/foreign/machine/endian.h
@@ -28,7 +28,8 @@
/*
* Copyright 1995 NeXT Computer, Inc. All rights reserved.
*/
-#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
+ defined(__DragonFly__) || defined(__CYGWIN__)
#include_next <machine/endian.h>
#else
#ifndef _BSD_MACHINE_ENDIAN_H_
@@ -45,4 +46,5 @@
#endif
#endif /* _BSD_MACHINE_ENDIAN_H_ */
-#endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __DragonFly__ */
+#endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ ||
+ __DragonFly__ || __CYGWIN__ */
diff --git usage_examples/ios_toolchain/wrapper.c usage_examples/ios_toolchain/wrapper.c
index c102d79..b88d35a 100644
--- usage_examples/ios_toolchain/wrapper.c
+++ usage_examples/ios_toolchain/wrapper.c
@@ -86,6 +86,7 @@ char *get_executable_path(char *epath, size_t buflen)
l = strlen(epath);
#else
ssize_t l = readlink("/proc/self/exe", epath, buflen);
+ if (l > 0) epath[l] = '\0';
#endif
if (l <= 0) return NULL;
epath[buflen - 1] = '\0';
--- cctools/configure
+++ cctools/configure
@@ -2627,7 +2627,8 @@
;;
cygwin* )
iscygwin=yes
- EXTRAFLAGS="-D__LARGE64_FILES -fno-PIC"
+ # https://github.com/tpoechtrager/osxcross/issues/87
+ EXTRAFLAGS="-D__LARGE64_FILES -D_GNU_SOURCE -fno-PIC"
WARNINGS="-Wno-attributes"
XCC="gcc"
XCXX="g++"

51
tools/gen_cyglto_dll.sh Executable file
View File

@ -0,0 +1,51 @@
#!/usr/bin/env bash
pushd "${0%/*}/.." &>/dev/null
source tools/tools.sh
if [[ $PLATFORM != CYGWIN* ]]; then
exit 1
fi
LLVM_CONFIG="llvm-config"
CXXFLAGS="$($LLVM_CONFIG --cxxflags) -fno-PIC"
LDFLAGS="$($LLVM_CONFIG --cxxflags) -Wl,-s"
INCDIR=$($LLVM_CONFIG --includedir)
LIBDIR=$($LLVM_CONFIG --libdir)
LIBS=$($LLVM_CONFIG --libs all)
SYSLIBS="$($LLVM_CONFIG --system-libs) -ledit -lffi"
VERSION=$($LLVM_CONFIG --version | awk -F \. {'print $1$2'} | sed 's/svn//g')
set -e
TMP=$(mktemp -d)
set +e
pushd $TMP &>/dev/null
wget https://raw.githubusercontent.com/llvm-mirror/llvm/release_$VERSION/tools/lto/lto.cpp
wget https://raw.githubusercontent.com/llvm-mirror/llvm/release_$VERSION/tools/lto/LTODisassembler.cpp
wget https://raw.githubusercontent.com/llvm-mirror/llvm/release_$VERSION/tools/lto/lto.exports
echo "{" > cyglto.exports
echo " global:" >> cyglto.exports
while read p; do
echo " $p;" >> cyglto.exports
done < lto.exports
echo " LLVM*;" >> cyglto.exports
echo " local: *;" >> cyglto.exports
echo "};" >> cyglto.exports
popd &>/dev/null
set -x
g++ -shared \
-L$LIBDIR -I$INCDIR $CXXFLAGS $LDFLAGS \
-Wl,--whole-archive $LIBS -Wl,--no-whole-archive $SYSLIBS \
$TMP/lto.cpp $TMP/LTODisassembler.cpp -Wl,-version-script,$TMP/cyglto.exports \
-o /bin/cygLTO.dll -Wl,--out-implib,/lib/libLTO.dll.a
rm -rf $TMP
popd &>/dev/null

View File

@ -135,8 +135,9 @@ char *getExecutablePath(char *buf, size_t len) {
l = 0;
delete[] argv;
#else
ssize_t l = readlink("/proc/self/exe", buf, len);
ssize_t l = readlink("/proc/self/exe", buf, len - 1);
assert(l > 0 && "/proc not mounted?");
if (l > 0) buf[l] = '\0';
#endif
if (l <= 0)
return nullptr;

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Workspace Name="wrapper" Database="wrapper.tags" SWTLW="No">
<CodeLite_Workspace Name="wrapper" Database="wrapper.tags">
<Project Name="wrapper" Path="./wrapper.project" Active="Yes"/>
<BuildMatrix>
<WorkspaceConfiguration Name="Debug" Selected="yes">