Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Unable to compile on macOS Catalina #1

Description

@d9pouces

I tried to compile Hairgap on Catalina, but there are some compilation errors:

$ make
mkdir -p build
clang -c src/hairgaps.c -o build/hairgaps.o -Wall -Wextra -fPIE -fstack-protector-strong -Wno-format-security -Werror -I./wirehair/include -Isrc/lib -D_FORTIFY_SOURCE=1 -Ofast -D_FORTIFY_SOURCE=1
clang -c src/lib/channel.c -o build/channel.o -Wall -Wextra -fPIE -fstack-protector-strong -Wno-format-security -Werror -I./wirehair/include -Isrc/lib -D_FORTIFY_SOURCE=1 -Ofast -D_FORTIFY_SOURCE=1
clang -c src/lib/common.c -o build/common.o -Wall -Wextra -fPIE -fstack-protector-strong -Wno-format-security -Werror -I./wirehair/include -Isrc/lib -D_FORTIFY_SOURCE=1 -Ofast -D_FORTIFY_SOURCE=1
clang -c src/lib/config.c -o build/config.o -Wall -Wextra -fPIE -fstack-protector-strong -Wno-format-security -Werror -I./wirehair/include -Isrc/lib -D_FORTIFY_SOURCE=1 -Ofast -D_FORTIFY_SOURCE=1
clang -c src/lib/encoding.c -o build/encoding.o -Wall -Wextra -fPIE -fstack-protector-strong -Wno-format-security -Werror -I./wirehair/include -Isrc/lib -D_FORTIFY_SOURCE=1 -Ofast -D_FORTIFY_SOURCE=1
src/lib/encoding.c:394:19: error: format specifies type 'unsigned long' but the argument has type 'uint64_t' (aka 'unsigned long long') [-Werror,-Wformat]
                  pkt.hdr.chunk_num, dec->chunk->num, pkt.hdr.data_id);
                  ^~~~~~~~~~~~~~~~~
src/lib/common.h:45:21: note: expanded from macro 'ERROR'
    fprintf(stderr, __VA_ARGS__);\
                    ^~~~~~~~~~~
src/lib/encoding.c:394:38: error: format specifies type 'unsigned long' but the argument has type 'uint64_t' (aka 'unsigned long long') [-Werror,-Wformat]
                  pkt.hdr.chunk_num, dec->chunk->num, pkt.hdr.data_id);
                                     ^~~~~~~~~~~~~~~
src/lib/common.h:45:21: note: expanded from macro 'ERROR'
    fprintf(stderr, __VA_ARGS__);\
                    ^~~~~~~~~~~
2 errors generated.
make: *** [build/encoding.o] Error 1

I tried to patch GNUmakefile, src/lib/encoding.c, src/lib/hgap_receive.c and src/lib/proto.c. Hairgap now compiles (and works, at least for a quick demo) but I am sure that a better fix exists.

diff --git a/GNUmakefile b/GNUmakefile
index 41d7b45..3c2b247 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -23,7 +23,7 @@ CFLAGS = -Wall -Wextra -fPIE -fstack-protector-strong \
 	 -Wno-format-security \
 	 -Werror \
          $(IFLAGS)
-LDFLAGS = $(IFLAGS) -L$(WIREHAIR)/bin -lpthread -lstdc++ -Wl,-z,now -Wl,-z,relro
+LDFLAGS = $(IFLAGS) -L$(WIREHAIR)/bin -lpthread -lstdc++ -Wl -Wl

 INSTALLDIR=/usr/local
 BIN=${INSTALLDIR}/bin
diff --git a/src/lib/encoding.c b/src/lib/encoding.c
index 4708789..0078b16 100644
--- a/src/lib/encoding.c
+++ b/src/lib/encoding.c
@@ -391,7 +391,7 @@ hgap_decoder_read(struct hgap_decoder *dec, void *raw_pkt, size_t len)
         if (!dec->chunk_complete) {
             ERROR("Error: missed too many packets "
                   "(cur chunk: %lu, last_chunk: %lu, cur_id: %u\n",
-                  pkt.hdr.chunk_num, dec->chunk->num, pkt.hdr.data_id);
+                  (unsigned long) pkt.hdr.chunk_num, (unsigned long) dec->chunk->num, pkt.hdr.data_id);
             return -HGAP_ERR_INCOMPLETE_CHUNK;
         }

diff --git a/src/lib/hgap_receive.c b/src/lib/hgap_receive.c
index 7a57079..4dfefa3 100644
--- a/src/lib/hgap_receive.c
+++ b/src/lib/hgap_receive.c
@@ -259,9 +259,6 @@ writer(struct writer_arg* args)
     int retval = HGAP_SUCCESS;

     int fd = fileno(out);
-    if (fd != -1) {
-        posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL | POSIX_FADV_NOREUSE);
-    }

     size_t data_written = 0;
     size_t data_written_total = 0;
diff --git a/src/lib/proto.c b/src/lib/proto.c
index 2d9b838..76bc390 100644
--- a/src/lib/proto.c
+++ b/src/lib/proto.c
@@ -19,7 +19,7 @@

 #include "proto.h"

-#include <endian.h>
+#include <machine/endian.h>
 #include <inttypes.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -28,6 +28,26 @@
 #include <wirehair.h>

 #include "common.h"
+#ifdef __APPLE__
+
+#include <libkern/OSByteOrder.h>
+
+#define htobe16(x) OSSwapHostToBigInt16(x)
+#define htole16(x) OSSwapHostToLittleInt16(x)
+#define be16toh(x) OSSwapBigToHostInt16(x)
+#define le16toh(x) OSSwapLittleToHostInt16(x)
+
+#define htobe32(x) OSSwapHostToBigInt32(x)
+#define htole32(x) OSSwapHostToLittleInt32(x)
+#define be32toh(x) OSSwapBigToHostInt32(x)
+#define le32toh(x) OSSwapLittleToHostInt32(x)
+
+#define htobe64(x) OSSwapHostToBigInt64(x)
+#define htole64(x) OSSwapHostToLittleInt64(x)
+#define be64toh(x) OSSwapBigToHostInt64(x)
+#define le64toh(x) OSSwapLittleToHostInt64(x)
+
+#endif

 int
 hgap_pkt_parse(struct hgap_pkt *pkt, const void *raw_pkt, size_t size)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions