aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lyon <jamesly0n@hotmail.com>2013-04-17 21:51:51 +0100
committerJames Lyon <jamesly0n@hotmail.com>2013-04-17 21:52:44 +0100
commitce5e12c2f950052d8109b6b7a56d900547705c08 (patch)
tree4fa4a67c8e67aae049c72e7ef60a17509eccabbe
parente31579b0769e1f9c0947d12e83316d1149307b1a (diff)
downloadtinycc-ce5e12c2f950052d8109b6b7a56d900547705c08.tar.gz
tinycc-ce5e12c2f950052d8109b6b7a56d900547705c08.tar.bz2
Added ABI compatibility tests with native compiler using libtcc.
Only one test so far, which fails on Windows (with MinGW as the native compiler - I've tested the MinGW output against MSVC and it appears the two are compatible). I've also had to modify tcc.h so that tcc_set_lib_path can point to the directory containing libtcc1.a on Windows to make the libtcc dependent tests work. I'm not sure this is the right way to fix this problem.
-rw-r--r--tcc.h2
-rw-r--r--tests/Makefile10
-rw-r--r--tests/abitest.c80
3 files changed, 91 insertions, 1 deletions
diff --git a/tcc.h b/tcc.h
index e94f91f..ef645b1 100644
--- a/tcc.h
+++ b/tcc.h
@@ -191,7 +191,7 @@
/* library search paths */
#ifndef CONFIG_TCC_LIBPATHS
# ifdef TCC_TARGET_PE
-# define CONFIG_TCC_LIBPATHS "{B}/lib"
+# define CONFIG_TCC_LIBPATHS "{B}/lib;{B}"
# else
# define CONFIG_TCC_LIBPATHS \
CONFIG_SYSROOT "/usr/" CONFIG_LDDIR \
diff --git a/tests/Makefile b/tests/Makefile
index 5e4a6c9..f47ede4 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -13,6 +13,7 @@ TESTS = \
hello-run \
libtest \
test3 \
+ abitest-exe \
moretests
# test4 -- problem with -static
@@ -177,6 +178,15 @@ asmtest: asmtest.ref
objdump -D asmtest.o > asmtest.out
@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
+# Check that code generated by libtcc is binary compatible with
+# that generated by CC
+abitest$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
+ $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir) -g -O0
+
+abitest-exe: abitest$(EXESUF)
+ @echo ------------ $@ ------------
+ abitest$(EXESUF) lib_path=..
+
# targets for development
%.bin: %.c tcc
$(TCC) -g -o $@ $<
diff --git a/tests/abitest.c b/tests/abitest.c
new file mode 100644
index 0000000..51a30ba
--- /dev/null
+++ b/tests/abitest.c
@@ -0,0 +1,80 @@
+#include <libtcc.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static const char *tccdir = NULL;
+
+typedef int (*callback_type) (void*);
+
+/*
+ * Compile source code and call a callback with a pointer to the symbol "f".
+ */
+static int run_callback(const char *src, callback_type callback) {
+ TCCState *s;
+ int result;
+ void *ptr;
+
+ s = tcc_new();
+ if (!s)
+ return -1;
+ if (tccdir)
+ tcc_set_lib_path(s, tccdir);
+ if (tcc_set_output_type(s, TCC_OUTPUT_MEMORY) == -1)
+ return -1;
+ if (tcc_compile_string(s, src) == -1)
+ return -1;
+ if (tcc_relocate(s, TCC_RELOCATE_AUTO) == -1)
+ return -1;
+
+ ptr = tcc_get_symbol(s, "f");
+ if (!ptr)
+ return -1;
+ result = callback(ptr);
+
+ tcc_delete(s);
+
+ return result;
+}
+
+typedef struct test1_type_s {int x, y;} test1_type;
+typedef test1_type (*test1_function_type) ();
+
+static int test1_callback(void *ptr) {
+ test1_type r;
+ r = ((test1_function_type)ptr)();
+ return ((r.x == 10) && (r.y == 35)) ? 0 : -1;
+}
+
+static int test1() {
+ const char *src =
+ "typedef struct test1_type_s {int x, y;} test1_type;"
+ "test1_type f() {\n"
+ " test1_type r = {10, 35};\n"
+ " return r;\n"
+ "}\n";
+
+ return run_callback(src, test1_callback);
+}
+
+#define RUN_TEST(t) \
+ do { \
+ fputs(#t "... ", stdout); \
+ fflush(stdout); \
+ if (t() == 0) { \
+ fputs("success\n", stdout); \
+ } else { \
+ fputs("failure\n", stdout); \
+ retval = EXIT_FAILURE; \
+ } \
+ } while (0);
+
+int main(int argc, char **argv) {
+ int retval = EXIT_SUCCESS;
+ /* if tcclib.h and libtcc1.a are not installed, where can we find them */
+ if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
+ tccdir = argv[1] + 9;
+
+ RUN_TEST(test1);
+ return retval;
+}