aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-08-30 12:23:30 -0400
committerJack Lloyd <[email protected]>2017-08-30 12:23:30 -0400
commit931fc0db4ae4a2b63c81bee65186bd181368a5cd (patch)
tree846c23990d3f79f8d32f81d6698ce6aa4d7cdad0
parent06eefb457eb8e4fadd46d8dbde026a9f163ff4f1 (diff)
Add support for LLVM bitcode target
-rwxr-xr-xconfigure.py21
-rw-r--r--src/build-data/arch/llvm.txt1
-rw-r--r--src/build-data/cc/clang.txt9
-rw-r--r--src/build-data/cc/gcc.txt3
-rw-r--r--src/build-data/makefile/gmake.in4
-rw-r--r--src/build-data/makefile/header.in4
-rw-r--r--src/build-data/os/llvm.txt9
-rw-r--r--src/lib/utils/mutex.h2
-rw-r--r--src/lib/utils/os_utils.cpp2
-rw-r--r--src/tests/main.cpp17
10 files changed, 51 insertions, 21 deletions
diff --git a/configure.py b/configure.py
index 5d79aa012..a01addbd0 100755
--- a/configure.py
+++ b/configure.py
@@ -1195,10 +1195,10 @@ class CompilerInfo(InfoObject): # pylint: disable=too-many-instance-attributes
@staticmethod
def _so_link_search(osname, debug_info):
+ so_link_typ = [osname, 'default']
if debug_info:
- return [osname + '-debug', 'default-debug']
- else:
- return [osname, 'default']
+ so_link_typ = [l + '-debug' for l in so_link_typ] + so_link_typ
+ return so_link_typ
def so_link_command_for(self, osname, options):
"""
@@ -2056,6 +2056,14 @@ def create_template_vars(source_paths, build_config, options, modules, cc, arch,
# This can be made consistent over all platforms in the future
variables['libname'] = 'botan-%d' % (Version.major)
+ if options.os == 'llvm':
+ # llvm-link doesn't understand -L or -l flags
+ variables['link_to_botan'] = '%s/lib%s.a' % (variables['out_dir'], variables['libname'])
+ else:
+ variables['link_to_botan'] = '%s%s %s%s' % (
+ cc.add_lib_dir_option, variables['out_dir'],
+ cc.add_lib_option, variables['libname'])
+
variables["header_in"] = process_template(os.path.join(source_paths.makefile_dir, 'header.in'), variables)
if variables["makefile_style"] == "gmake":
@@ -2910,8 +2918,13 @@ def validate_options(options, info_os, info_cc, available_module_policies):
raise UserError("--destdir was removed. Use the DESTDIR environment "
"variable instead when calling 'make install'")
- # Warnings
+ if options.os == 'llvm' or options.cpu == 'llvm':
+ if options.compiler != 'clang':
+ raise UserError('LLVM target requires using Clang')
+ if options.os != options.cpu:
+ raise UserError('LLVM target requires both CPU and OS be set to llvm')
+ # Warnings
if options.os == 'windows' and options.compiler == 'gcc':
logging.warning('Detected GCC on Windows; use --os=cygwin or --os=mingw?')
diff --git a/src/build-data/arch/llvm.txt b/src/build-data/arch/llvm.txt
new file mode 100644
index 000000000..3b8c13ffd
--- /dev/null
+++ b/src/build-data/arch/llvm.txt
@@ -0,0 +1 @@
+wordsize 64
diff --git a/src/build-data/cc/clang.txt b/src/build-data/cc/clang.txt
index 2afd530d3..865809792 100644
--- a/src/build-data/cc/clang.txt
+++ b/src/build-data/cc/clang.txt
@@ -31,22 +31,17 @@ makefile_style gmake
<so_link_commands>
darwin -> "$(CXX) -dynamiclib -fPIC -install_name $(INSTALLED_LIB_DIR)/$(SONAME_ABI) -current_version $(DARWIN_CURRENT_VER) -compatibility_version $(DARWIN_COMPATIBILITY_VER)"
-darwin-debug -> "$(CXX) -dynamiclib -fPIC -install_name $(INSTALLED_LIB_DIR)/$(SONAME_ABI) -current_version $(DARWIN_CURRENT_VER) -compatibility_version $(DARWIN_COMPATIBILITY_VER)"
# The default works for GNU ld and several other Unix linkers
default -> "$(CXX) -shared -fPIC -Wl,-soname,$(SONAME_ABI)"
-default-debug -> "$(CXX) -shared -fPIC -Wl,-soname,$(SONAME_ABI)"
</so_link_commands>
<binary_link_commands>
darwin -> "$(LINKER) -headerpad_max_install_names"
-darwin-debug -> "$(LINKER) -headerpad_max_install_names"
linux -> "$(LINKER) -Wl,-rpath=\$$ORIGIN"
-linux-debug -> "$(LINKER) -Wl,-rpath=\$$ORIGIN"
freebsd -> "$(LINKER) -Wl,-rpath=\$$ORIGIN"
-freebsd-debug -> "$(LINKER) -Wl,-rpath=\$$ORIGIN"
default -> "$(LINKER)"
-default-debug -> "$(LINKER)"
+llvm -> "llvm-link"
</binary_link_commands>
<isa_flags>
@@ -64,6 +59,8 @@ altivec -> "-maltivec"
</isa_flags>
<mach_opt>
+all_llvm -> "-emit-llvm -fno-use-cxa-atexit"
+
x86_32 -> "-march=SUBMODEL"
x86_64 -> "-march=SUBMODEL"
nehalem -> "-march=corei7"
diff --git a/src/build-data/cc/gcc.txt b/src/build-data/cc/gcc.txt
index 5ace1931c..fdada6a3d 100644
--- a/src/build-data/cc/gcc.txt
+++ b/src/build-data/cc/gcc.txt
@@ -37,7 +37,6 @@ makefile_style gmake
<so_link_commands>
# The default works for GNU ld and several other Unix linkers
default -> "$(CXX) -shared -fPIC -Wl,-soname,$(SONAME_ABI)"
-default-debug -> "$(CXX) -shared -fPIC -Wl,-soname,$(SONAME_ABI)"
# Darwin, HP-UX and Solaris linkers use different syntax
darwin -> "$(CXX) -dynamiclib -fPIC -install_name $(LIBDIR)/$(SONAME_ABI)"
@@ -51,9 +50,7 @@ openbsd -> "$(CXX) -shared -fPIC"
<binary_link_commands>
linux -> "$(LINKER) -Wl,-rpath=\$$ORIGIN"
-linux-debug -> "$(LINKER) -Wl,-rpath=\$$ORIGIN"
default -> "$(LINKER)"
-default-debug -> "$(LINKER)"
</binary_link_commands>
<isa_flags>
diff --git a/src/build-data/makefile/gmake.in b/src/build-data/makefile/gmake.in
index 4b4426e5d..70b534503 100644
--- a/src/build-data/makefile/gmake.in
+++ b/src/build-data/makefile/gmake.in
@@ -38,11 +38,11 @@ cli: $(CLI)
tests: $(TEST)
$(CLI): $(LIBRARIES) $(CLIOBJS)
- $(CLI_LINK_CMD) $(LDFLAGS) $(CLIOBJS) -L%{out_dir} -l%{libname} $(CLI_LINKS_TO) -o $(CLI)
+ $(CLI_LINK_CMD) $(LDFLAGS) $(CLIOBJS) $(CLI_LINKS_TO) -o $(CLI)
$(CLI_POST_LINK_CMD)
$(TEST): $(LIBRARIES) $(TESTOBJS)
- $(TEST_LINK_CMD) $(LDFLAGS) $(TESTOBJS) -L%{out_dir} -l%{libname} $(TEST_LINKS_TO) -o $(TEST)
+ $(TEST_LINK_CMD) $(LDFLAGS) $(TESTOBJS) $(TEST_LINKS_TO) -o $(TEST)
$(TEST_POST_LINK_CMD)
$(STATIC_LIB): $(LIBOBJS)
diff --git a/src/build-data/makefile/header.in b/src/build-data/makefile/header.in
index 1114cf2d6..a63a83f3a 100644
--- a/src/build-data/makefile/header.in
+++ b/src/build-data/makefile/header.in
@@ -11,8 +11,8 @@ CLI_LINK_CMD = %{cli_link_cmd}
TEST_LINK_CMD = %{test_link_cmd}
LIB_LINKS_TO = %{link_to}
-CLI_LINKS_TO = $(LIB_LINKS_TO)
-TEST_LINKS_TO = $(LIB_LINKS_TO)
+CLI_LINKS_TO = %{link_to_botan} $(LIB_LINKS_TO)
+TEST_LINKS_TO = %{link_to_botan} $(LIB_LINKS_TO)
LIB_FLAGS = $(SO_OBJ_FLAGS) $(CXXFLAGS) $(WARN_FLAGS)
CLI_FLAGS = $(CXXFLAGS) $(WARN_FLAGS)
diff --git a/src/build-data/os/llvm.txt b/src/build-data/os/llvm.txt
new file mode 100644
index 000000000..119d641e4
--- /dev/null
+++ b/src/build-data/os/llvm.txt
@@ -0,0 +1,9 @@
+
+obj_suffix bc
+building_shared_supported no
+
+ar_command "llvm-link -o"
+
+<target_features>
+filesystem
+</target_features>
diff --git a/src/lib/utils/mutex.h b/src/lib/utils/mutex.h
index 0daea3148..2aabd2973 100644
--- a/src/lib/utils/mutex.h
+++ b/src/lib/utils/mutex.h
@@ -21,7 +21,7 @@ typedef std::mutex mutex_type;
}
-#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL)
+#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL) || defined(BOTAN_TARGET_OS_IS_LLVM)
// No threads
diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp
index 7bd9b842d..ca4b0fffe 100644
--- a/src/lib/utils/os_utils.cpp
+++ b/src/lib/utils/os_utils.cpp
@@ -34,7 +34,7 @@ uint32_t OS::get_process_id()
return ::getpid();
#elif defined(BOTAN_TARGET_OS_IS_WINDOWS) || defined(BOTAN_TARGET_OS_IS_MINGW)
return ::GetCurrentProcessId();
-#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL)
+#elif defined(BOTAN_TARGET_OS_TYPE_IS_UNIKERNEL) || defined(BOTAN_TARGET_OS_IS_LLVM)
return 0; // truly no meaningful value
#else
#error "Missing get_process_id"
diff --git a/src/tests/main.cpp b/src/tests/main.cpp
index e30c268c0..ae1ad18a7 100644
--- a/src/tests/main.cpp
+++ b/src/tests/main.cpp
@@ -11,8 +11,6 @@
#include <string>
#include <set>
#include <deque>
-#include <thread>
-#include <future>
#include <cstdlib>
#include <botan/version.h>
@@ -35,6 +33,11 @@
#include <botan/internal/openssl.h>
#endif
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
+ #include <thread>
+ #include <future>
+#endif
+
namespace {
class Test_Runner : public Botan_CLI::Command
@@ -192,7 +195,12 @@ class Test_Runner : public Botan_CLI::Command
std::unique_ptr<Botan::HMAC_DRBG> drbg(new Botan::HMAC_DRBG("SHA-384"));
drbg->initialize_with(seed.data(), seed.size());
+
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
rng.reset(new Botan::Serialized_RNG(drbg.release()));
+#else
+ rng = std::move(drbg);
+#endif
#else
@@ -323,6 +331,7 @@ class Test_Runner : public Botan_CLI::Command
else
{
+#if defined(BOTAN_TARGET_OS_HAS_THREADS)
/*
We're not doing this in a particularly nice way, and variance in time is
high so commonly we'll 'run dry' by blocking on the first future. But
@@ -365,6 +374,10 @@ class Test_Runner : public Botan_CLI::Command
out << report_out(fut_results[0].get(), tests_failed, tests_ran) << std::flush;
fut_results.pop_front();
}
+#else
+ out << "Threading support disabled\n";
+ return 1;
+#endif
}
const uint64_t total_ns = Botan_Tests::Test::timestamp() - start_time;