Browse Source

Fix symbol issues in static build.

Adam Ierymenko 5 years ago
parent
commit
346d4b572b
5 changed files with 14 additions and 8 deletions
  1. 1 1
      core/Buf.cpp
  2. 5 4
      core/FCV.hpp
  3. 2 0
      core/Utils.cpp
  4. 4 1
      core/Utils.hpp
  5. 2 2
      pkg/zerotier/node.go

+ 1 - 1
core/Buf.cpp

@@ -43,7 +43,7 @@ void *Buf::operator new(std::size_t sz)
 		s_pool.store(0);
 		b = (Buf *) malloc(sz);
 		if (!b)
-			throw std::bad_alloc();
+			throw Utils::BadAllocException;
 		++s_allocated;
 	}
 

+ 5 - 4
core/FCV.hpp

@@ -19,6 +19,7 @@
 #include <iterator>
 #include <algorithm>
 #include <memory>
+#include <stdexcept>
 
 namespace ZeroTier {
 
@@ -114,14 +115,14 @@ public:
 	{
 		if (likely(i < _s))
 			return reinterpret_cast<T *>(_m)[i];
-		throw std::out_of_range("i > capacity");
+		throw Utils::OutOfRangeException;
 	}
 
 	ZT_INLINE const T &operator[](const unsigned int i) const
 	{
 		if (likely(i < _s))
 			return reinterpret_cast<const T *>(_m)[i];
-		throw std::out_of_range("i > capacity");
+		throw Utils::OutOfRangeException;
 	}
 
 	static constexpr unsigned int capacity() noexcept
@@ -150,7 +151,7 @@ public:
 	{
 		if (likely(_s < C))
 			new(reinterpret_cast<T *>(_m) + _s++) T(v);
-		else throw std::out_of_range("capacity exceeded");
+		throw Utils::OutOfRangeException;
 	}
 
 	/**
@@ -200,7 +201,7 @@ public:
 	ZT_INLINE void resize(unsigned int ns)
 	{
 		if (unlikely(ns > C))
-			throw std::out_of_range("capacity exceeded");
+			throw Utils::OutOfRangeException;
 		unsigned int s = _s;
 		while (s < ns)
 			new(reinterpret_cast<T *>(_m) + s++) T();

+ 2 - 0
core/Utils.cpp

@@ -84,6 +84,8 @@ CPUIDRegisters::CPUIDRegisters() noexcept
 const CPUIDRegisters CPUID;
 #endif
 
+const std::bad_alloc BadAllocException;
+const std::out_of_range OutOfRangeException("access out of range");
 const uint64_t ZERO256[4] = {0, 0, 0, 0};
 const char HEXCHARS[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
 const uint64_t s_mapNonce = getSecureRandomU64();

+ 4 - 1
core/Utils.hpp

@@ -69,6 +69,9 @@ struct CPUIDRegisters
 extern const CPUIDRegisters CPUID;
 #endif
 
+extern const std::bad_alloc BadAllocException;
+extern const std::out_of_range OutOfRangeException;
+
 /**
  * 256 zero bits / 32 zero bytes
  */
@@ -862,7 +865,7 @@ struct Mallocator
 			return nullptr;
 		pointer temp = (pointer)malloc(s * sizeof(T));
 		if (temp == nullptr)
-			throw std::bad_alloc();
+			throw BadAllocException;
 		return temp;
 	}
 

+ 2 - 2
pkg/zerotier/node.go

@@ -14,8 +14,8 @@
 package zerotier
 
 // #cgo CFLAGS: -O3 -I${SRCDIR}/../../build/core
-// #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup
-// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all
+// #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup -lc++
+// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all -lstdc++
 // #include "../../serviceiocore/GoGlue.h"
 import "C"