From d61e728e08c7806281c45947e099d5280512df0b Mon Sep 17 00:00:00 2001 From: Andriy Tkachuk Date: Wed, 4 Sep 2024 14:47:53 +0100 Subject: [PATCH 1/3] Fix priv/leo_erasure.so linking on Linux --- c_src/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/c_src/Makefile b/c_src/Makefile index 6c381e0..788118a 100644 --- a/c_src/Makefile +++ b/c_src/Makefile @@ -21,16 +21,19 @@ ifeq ($(UNAME_SYS), Darwin) CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes CXXFLAGS ?= -O3 -finline-functions -Wall LDFLAGS ?= -flat_namespace -undefined suppress + LDFLAGS += gf-complete/src/.libs/*.o jerasure/src/.libs/*.o -Wl,-load_hidden,isa-l/.libs/libisal.a else ifeq ($(UNAME_SYS), FreeBSD) CC ?= cc CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes CXXFLAGS ?= -O3 -finline-functions -Wall LDFLAGS ?= -lstdc++ + LDFLAGS += gf-complete/src/.libs/*.o jerasure/src/.libs/*.o isa-l/.libs/libisal.a else ifeq ($(UNAME_SYS), Linux) CC ?= gcc CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes CXXFLAGS ?= -O3 -finline-functions -Wall LDFLAGS ?= -lstdc++ + LDFLAGS += gf-complete/src/.libs/*.o jerasure/src/.libs/*.o isa-l/.libs/libisal.a endif CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR) @@ -38,7 +41,6 @@ CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR) CXXFLAGS += -I isa-l/include -I jerasure/include -I gf-complete/include LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lei -LDFLAGS += gf-complete/src/.libs/*.o jerasure/src/.libs/*.o -Wl,-load_hidden,isa-l/.libs/libisal.a LDFLAGS += -shared # Verbosity. From e0619343a17ba86c3e1e6e6d2b261c9a2259876f Mon Sep 17 00:00:00 2001 From: Andriy Tkachuk Date: Wed, 4 Sep 2024 19:51:27 +0100 Subject: [PATCH 2/3] Fix proper isa-l compilation on FreeBSD Added -fPIC to CFLAGS. --- Makefile | 2 +- c_src/Makefile | 2 +- c_src/build_deps.sh | 8 +++++++- c_src/irscoding.cpp | 2 +- c_src/liberationcoding.cpp | 2 +- c_src/rscoding.cpp | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d2f3ec4..114ae5c 100644 --- a/Makefile +++ b/Makefile @@ -22,4 +22,4 @@ clean: distclean: @$(REBAR) clean @rm -rf c_src/*.o - @rm -rf _build/ priv/ blocks/ .eunit/ rebar.lock + @rm -rf _build/ priv/ blocks/ rebar.lock diff --git a/c_src/Makefile b/c_src/Makefile index 788118a..25d7c12 100644 --- a/c_src/Makefile +++ b/c_src/Makefile @@ -25,7 +25,7 @@ ifeq ($(UNAME_SYS), Darwin) else ifeq ($(UNAME_SYS), FreeBSD) CC ?= cc CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes - CXXFLAGS ?= -O3 -finline-functions -Wall + CXXFLAGS ?= -O3 -finline-functions -Wall -Wno-vla-cxx-extension LDFLAGS ?= -lstdc++ LDFLAGS += gf-complete/src/.libs/*.o jerasure/src/.libs/*.o isa-l/.libs/libisal.a else ifeq ($(UNAME_SYS), Linux) diff --git a/c_src/build_deps.sh b/c_src/build_deps.sh index 6632f54..9010481 100755 --- a/c_src/build_deps.sh +++ b/c_src/build_deps.sh @@ -29,11 +29,16 @@ fi # (code from github.com/tuncer/re2/c_src/build_deps.sh which gmake 1>/dev/null 2>/dev/null && MAKE=gmake MAKE=${MAKE:-make} +if [ `uname` = 'FreeBSD' -a "$MAKE" = 'make' ]; then + echo "WARNING: make may not work for some libs, install gmake." +fi which glibtoolize 1>/dev/null 2>/dev/null && LIBTOOLIZE=glibtoolize LIBTOOLIZE=${LIBTOOLIZE:-libtoolize} -# Changed "make" to $MAKE +if [ `uname` = 'FreeBSD' ]; then + CONFIG="$CONFIG CFLAGS=-fPIC" +fi case "$1" in clean) @@ -60,6 +65,7 @@ case "$1" in git clone -b v2.31.0 -c advice.detachedHead=false https://github.com/intel/isa-l.git cd isa-l (./autogen.sh && $CONFIG && $MAKE) + cd .. fi ;; esac diff --git a/c_src/irscoding.cpp b/c_src/irscoding.cpp index 0f53ffb..24891a3 100644 --- a/c_src/irscoding.cpp +++ b/c_src/irscoding.cpp @@ -32,7 +32,7 @@ using namespace std; void IRSCoding::checkParams() { if (k <= 0 || m <= 0 || w <= 0) throw std::invalid_argument("Invalid Coding Parameters"); - if (w != 8) + if (w != 8) throw std::invalid_argument("Invalid Coding Parameters (w = 8)"); } diff --git a/c_src/liberationcoding.cpp b/c_src/liberationcoding.cpp index 8b45ca8..023f5c4 100644 --- a/c_src/liberationcoding.cpp +++ b/c_src/liberationcoding.cpp @@ -31,7 +31,7 @@ void LiberationCoding::checkParams() { throw std::invalid_argument("Invalid Coding Parameters (m = 2)"); if (k > w) throw std::invalid_argument("Invalid Coding Parameters (k <= w)"); - if (w <= 2 || !(w%2) || !is_prime(w)) + if (w <= 2 || !(w%2) || !is_prime(w)) throw std::invalid_argument("Invalid Coding Parameters (w is prime)"); } diff --git a/c_src/rscoding.cpp b/c_src/rscoding.cpp index b25ab38..26ce2db 100644 --- a/c_src/rscoding.cpp +++ b/c_src/rscoding.cpp @@ -29,7 +29,7 @@ void RSCoding::checkParams() { if (k <= 0 || m <= 0 || w <= 0) throw std::invalid_argument("Invalid Coding Parameters"); - if (w != 8 && w != 16 && w != 32) + if (w != 8 && w != 16 && w != 32) throw std::invalid_argument("Invalid Coding Parameters (w = 8/16/32)"); } From aeb69a8050a973cddab96a36a47725f475702216 Mon Sep 17 00:00:00 2001 From: Andriy Tkachuk Date: Wed, 4 Sep 2024 19:32:33 +0100 Subject: [PATCH 3/3] Fix warning: blockSize may be used uninitialized --- c_src/cauchycoding.cpp | 4 ++-- c_src/irscoding.cpp | 4 ++-- c_src/liberationcoding.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/c_src/cauchycoding.cpp b/c_src/cauchycoding.cpp index 7d627ed..c17bda6 100644 --- a/c_src/cauchycoding.cpp +++ b/c_src/cauchycoding.cpp @@ -97,7 +97,7 @@ ERL_NIF_TERM CauchyCoding::doDecode(vector blockList, vector throw std::invalid_argument("Blocks should be unique"); } - size_t blockSize; + size_t blockSize = 0; ErlNifBinary blocks[k + m]; for(size_t i = 0; i < blockIdList.size(); ++i) { @@ -165,7 +165,7 @@ vector CauchyCoding::doRepair(vector blockList, vect throw std::invalid_argument("Blocks should be unique"); } - size_t blockSize; + size_t blockSize = 0; ErlNifBinary blocks[k + m]; for(size_t i = 0; i < blockIdList.size(); ++i) { diff --git a/c_src/irscoding.cpp b/c_src/irscoding.cpp index 24891a3..3e55794 100644 --- a/c_src/irscoding.cpp +++ b/c_src/irscoding.cpp @@ -91,7 +91,7 @@ ERL_NIF_TERM IRSCoding::doDecode(vector blockList, vector blo throw std::invalid_argument("Blocks should be unique"); } - size_t blockSize; + size_t blockSize = 0; unsigned char* availBlocks[k + m]; ErlNifBinary blocks[k + m]; @@ -147,7 +147,7 @@ vector IRSCoding::doRepair(vector blockList, vector< throw std::invalid_argument("Blocks should be unique"); } - size_t blockSize; + size_t blockSize = 0; unsigned char* availBlocks[k + m]; ErlNifBinary blocks[k + m]; diff --git a/c_src/liberationcoding.cpp b/c_src/liberationcoding.cpp index 023f5c4..4664807 100644 --- a/c_src/liberationcoding.cpp +++ b/c_src/liberationcoding.cpp @@ -95,7 +95,7 @@ ERL_NIF_TERM LiberationCoding::doDecode(vector blockList, vector LiberationCoding::doRepair(vector blockList, throw std::invalid_argument("Blocks should be unique"); } - size_t blockSize; + size_t blockSize = 0; ErlNifBinary blocks[k + m]; for(size_t i = 0; i < blockIdList.size(); ++i) {