Include some build fixes for OS X.
Apart from the obvious little issues, this also works around a
(seeming) libtool/linker:
a.c defines a symbol:
int kFoo;
b.c uses it:
extern int kFoo;
int f() {
return kFoo;
}
compile them:
$ gcc -c a.c
$ gcc -c b.c
and create a dummy main in order to run it, main.c:
int f();
int main() {
return f();
}
this works as expected:
$ gcc main.c a.o b.o
but, if we make an archive:
$ ar q lib.a a.o b.o
and use that:
$ gcc main.c lib.a
Undefined symbols for architecture x86_64
"_kFoo", referenced from:
_f in lib.a(b.o)
(It doesn't matter what order the .o files are put into the .a)
Linux and Windows don't seem to have this problem.
nm on a.o shows that the symbol is of type "C", which is a "common symbol"[1].
Basically the linker will merge multiple common symbol definitions together.
If ones makes a.c read:
int kFoo = 0;
Then one gets a type "D" symbol - a "data section symbol" and everything works
just fine.
This might actually be a libtool bug instead of an ld bug: Looking at `xxd
lib.a | less`, the __.SYMDEF SORTED index at the beginning of the archive
doesn't contain an entry for kFoo unless initialised.
Change-Id: I4cdad9ba46e9919221c3cbd79637508959359427
diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt
index d9f6732..4b9c03b 100644
--- a/tool/CMakeLists.txt
+++ b/tool/CMakeLists.txt
@@ -10,4 +10,8 @@
tool.cc
)
-target_link_libraries(bssl ssl crypto -lrt)
+if (APPLE)
+ target_link_libraries(bssl ssl crypto)
+else()
+ target_link_libraries(bssl ssl crypto -lrt)
+endif()
diff --git a/tool/client.cc b/tool/client.cc
index 6af34a32..5acc8b1 100644
--- a/tool/client.cc
+++ b/tool/client.cc
@@ -17,6 +17,7 @@
#include <string>
#include <vector>
+#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
diff --git a/tool/speed.cc b/tool/speed.cc
index 176e2e2..8dde777 100644
--- a/tool/speed.cc
+++ b/tool/speed.cc
@@ -28,6 +28,8 @@
#if defined(OPENSSL_WINDOWS)
#include <Windows.h>
+#elif defined(OPENSSL_APPLE)
+#include <sys/time.h>
#endif
extern "C" {
@@ -61,6 +63,17 @@
#if defined(OPENSSL_WINDOWS)
static uint64_t time_now() { return GetTickCount64() * 1000; }
+#elif defined(OPENSSL_APPLE)
+static uint64_t time_now() {
+ struct timeval tv;
+ uint64_t ret;
+
+ gettimeofday(&tv, NULL);
+ ret = tv.tv_sec;
+ ret *= 1000000;
+ ret += tv.tv_usec;
+ return ret;
+}
#else
static uint64_t time_now() {
struct timespec ts;