From ca92bfc3c64128872793c167de3a58a78b9a1299 Mon Sep 17 00:00:00 2001 From: grischka Date: Thu, 15 Dec 2016 17:01:22 +0100 Subject: tccelf: some linker cleanup - generate and use SYM@PLT for plt addresses - get rid of patch_dynsym_undef hack (no idea what it did on FreeBSD) - use sym_attrs instead of symtab_to_dynsym - special case for function pointers into .so on i386 - libtcc_test: test tcc_add_symbol with data object - move target specicic code to *-link.c files - add R_XXX_RELATIVE (needed for PE) --- tests/libtcc_test.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests/libtcc_test.c') diff --git a/tests/libtcc_test.c b/tests/libtcc_test.c index 109e488..be5db61 100644 --- a/tests/libtcc_test.c +++ b/tests/libtcc_test.c @@ -15,9 +15,12 @@ int add(int a, int b) return a + b; } +const char hello[] = "Hello World!"; + char my_program[] = "#include \n" /* include the "Simple libc header for TCC" */ "extern int add(int a, int b);\n" +"extern const char hello[];\n" "int fib(int n)\n" "{\n" " if (n <= 2)\n" @@ -28,7 +31,7 @@ char my_program[] = "\n" "int foo(int n)\n" "{\n" -" printf(\"Hello World!\\n\");\n" +" printf(\"%s\\n\", hello);\n" " printf(\"fib(%d) = %d\\n\", n, fib(n));\n" " printf(\"add(%d, %d) = %d\\n\", n, 2 * n, add(n, 2 * n));\n" " return 0;\n" @@ -65,9 +68,10 @@ int main(int argc, char **argv) if (tcc_compile_string(s, my_program) == -1) return 1; - /* as a test, we add a symbol that the compiled program can use. + /* as a test, we add symbols that the compiled program can use. You may also open a dll with tcc_add_dll() and use symbols from that */ tcc_add_symbol(s, "add", add); + tcc_add_symbol(s, "hello", hello); /* relocate the code */ if (tcc_relocate(s, TCC_RELOCATE_AUTO) < 0) -- cgit v1.3.1