hyperboria / bugs

Peer-to-peer IPv6 networking, secure and near-zero-conf.
154 stars 17 forks source link

build fails for mingw32 target #33

Open dangowrt opened 9 years ago

dangowrt commented 9 years ago

Trying to build win32 binaries using x86_64-w64-mingw32-gcc 4.9.2 on Archlinux:

/usr/src/cjdns/node_build/builder.js:478
            if (err) { throw err; }
                             ^
Error: gcc -c -x cpp-output -o build_win32/memory_Allocator_c.o -std=c99 -Wall -Wextra -Werror -Wno-pointer-sign -pedantic -D win32=1 -Wno-unused-parameter -fomit-frame-pointer -D Log_DEBUG -g -D NumberCompress_TYPE=v3x5x8 -D Identity_CHECK=1 -D Allocator_USE_CANARIES=1 -D PARANOIA=1 -Wno-format -O3 build_win32/memory_Allocator_c.o.i

memory/Allocator.c: In function ‘Allocator__realloc’:
memory/Allocator.c:551:64: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
     if (context->rootAlloc->spaceAvailable + origLoc->pub.size < realSize) {
                                                                ^
cc1: all warnings being treated as errors

    at error (/usr/src/cjdns/node_build/builder.js:52:15)
    at /usr/src/cjdns/node_build/builder.js:115:22
    at /usr/src/cjdns/node_build/builder.js:85:13
    at ChildProcess.<anonymous> (/usr/src/cjdns/node_build/Semaphore.js:7:30)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Socket.<anonymous> (child_process.js:1183:11)
    at Socket.emit (events.js:107:17)
    at Pipe.close (net.js:485:12)

real    1m22.580s
user    3m1.400s
sys 0m14.507s
dangowrt commented 9 years ago

casting the right side of the comparision to size_t did the trick.

diff --git a/memory/Allocator.c b/memory/Allocator.c
index 8fef62a..799aa5c 100644
--- a/memory/Allocator.c
+++ b/memory/Allocator.c
@@ -548,7 +548,7 @@ void* Allocator__realloc(struct Allocator* allocator,
     }

     size_t realSize = getRealSize(size);
-    if (context->rootAlloc->spaceAvailable + origLoc->pub.size < realSize) {
+    if ((size_t)(context->rootAlloc->spaceAvailable + origLoc->pub.size) < realSize) {
         failure(context, "Out of memory, limit exceeded.", fileName, lineNum);
     }
     context->rootAlloc->spaceAvailable += origLoc->pub.size;

Now builds successful with

SSP_SUPPORT=0 SYSTEM=win32 CROSS_COMPILE=x86_64-w64-mingw32- ./cross-do

Build with SSP still fails

Total build time: 87442ms.
/usr/src/cjdns/node_build/builder.js:713
            if (err) { throw err; }
                             ^
Error: gcc -flto,-O3 -o build_win32/contrib_c_privatetopublic_c build_win32/util_Assert_c.o,build_win32/util_Bits_c.o,build_win32/crypto_AddressCalc_c.o,build_win32/memory_Allocator_c.o,build_win32/util_CString_c.o,build_win32/benc_String_c.o,build_win32/crypto_Key_c.o,build_win32/util_Hex_c.o,build_win32/util_platform_Sockaddr_c.o,build_win32/util_AddrTools_c.o,build_win32/dht_Address_c.o,build_win32/contrib_c_privatetopublic_c.o -lssp,build_win32/dependencies/cnacl/jsbuild/libnacl.a,build_win32/dependencies/libuv/out/Release/obj.target/libuv.a,-lpthread,-lws2_32,-lpsapi,-liphlpapi

/usr/lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lssp
collect2: error: ld returned 1 exit status
dangowrt commented 9 years ago

The resulting cjdroute.exe crashes on "real" Windows 7 and 8 and also in WINE on Linux:

Unhandled exception: page fault on read access to 0x00000094 in 64-bit code (0x0000000000468542).
Register dump:
 rip:0000000000468542 rsp:000000000032f7a0 rbp:0000000000000000 eflags:00010206 (  R- --  I   - -P- )
 rax:0000000000000000 rbx:0000000000731d90 rcx:0000000000731db8 rdx:0000000000731db8
 rsi:0000000000731d10 rdi:0000000000731ca0  r8:0000000000000080  r9:0000000000731db8 r10:0000000000000080
 r11:0000000000000218 r12:0000000000000002 r13:0000000000000002 r14:00007fffff7e8000 r15:00007ffeb6830440
Stack dump:
0x000000000032f7a0:  0000000000000000 0000000000000000
0x000000000032f7b0:  0000000000000000 0000000000000000
0x000000000032f7c0:  0000000000000000 0000000000000000
0x000000000032f7d0:  0000000000000000 ffffffffffffff00
0x000000000032f7e0:  0000000000000000 0000000000000000
0x000000000032f7f0:  0000000000000000 00007feee62295c5
0x000000000032f800:  770064665f657361 767265735f656e69
0x000000000032f810:  e25ad9e718feee17 4f0d0f0413375046
0x000000000032f820:  0515089d2627484e c668b434310128d2
0x000000000032f830:  62d311b8420841cc 36f3d0cd45ad78f7
0x000000000032f840:  b0511dc7d99c05e8 08b2b05069bc7ac4
0x000000000032f850:  8f92508052edca9d cf6607e6304d25a1
Backtrace:
=>0 0x0000000000468542 in cjdroute (+0x68542) (0x0000000000000000)
0x0000000000468542: movl    0x0000000000000014(%r10),%ecx
Modules:
Module  Address                 Debug info  Name (24 modules)
PE            400000-          724000   Dwarf           cjdroute
ELF         7b800000-        7bc85000   Deferred        kernel32<elf>
  \-PE          7b820000-        7bc85000   \               kernel32
ELF         7be00000-        7c103000   Deferred        <wine-loader>
ELF     7feee5aea000-    7feee5d4f000   Deferred        libncursesw.so.5
ELF     7feee5d4f000-    7feee5f8f000   Deferred        ws2_32<elf>
  \-PE      7feee5d60000-    7feee5f8f000   \               ws2_32
ELF     7feee5f8f000-    7feee61a2000   Deferred        psapi<elf>
  \-PE      7feee5f90000-    7feee61a2000   \               psapi
ELF     7feee61a2000-    7feee6474000   Deferred        msvcrt<elf>
  \-PE      7feee61c0000-    7feee6474000   \               msvcrt
ELF     7feee6474000-    7feee669e000   Deferred        iphlpapi<elf>
  \-PE      7feee6480000-    7feee669e000   \               iphlpapi
ELF     7feee669e000-    7feee6932000   Deferred        advapi32<elf>
  \-PE      7feee66b0000-    7feee6932000   \               advapi32
ELF     7feee6932000-    7feee6b3f000   Deferred        libnss_files.so.2
ELF     7feee6d04000-    7feee6f1a000   Deferred        libgcc_s.so.1
ELF     7feee6f1a000-    7feee721f000   Deferred        libm.so.6
ELF     7feee721f000-    7feee7522000   Deferred        ntdll<elf>
  \-PE      7feee7240000-    7feee7522000   \               ntdll
ELF     7feee7525000-    7feee7729000   Deferred        libdl.so.2
ELF     7feee7760000-    7feee7b03000   Deferred        libc.so.6
ELF     7feee7b03000-    7feee7d20000   Deferred        libpthread.so.0
ELF     7feee80c7000-    7feee82eb000   Deferred        ld-linux-x86-64.so.2
Threads:
process  tid      prio (all id:s are in hex)
0000000e services.exe
    0000001d    0
    0000001c    0
    00000016    0
    00000014    0
    00000010    0
    0000000f    0
00000012 winedevice.exe
    0000001b    0
    00000018    0
    00000017    0
    00000013    0
00000019 plugplay.exe
    0000001f    0
    0000001e    0
    0000001a    0
00000020 explorer.exe
    00000028    0
    00000027    0
    00000026    0
    00000021    0
00000022 (D) Z:\usr\src\cjdns\cjdroute.exe
    00000023    0 <==
System information:
    Wine build: wine-1.7.42
    Platform: x86_64
    Host system: Linux
    Host version: 4.0.1-1-ARCH
slothbag commented 9 years ago

I'm also getting build errors.

First one was with cnacl, saying _sleep is undefined. I added some preprocessor directives for sleep -> Sleep into devurandom.c and then it builds cnacl.

But then the next problem is building libuv, throwing error

undefined reference to `__imp__GetAddrInfoW@16'