From 5bd8aeb917ed326f50b1ed45669a1cf40aca75a3 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Fri, 26 Aug 2016 18:11:19 +0200 Subject: tccasm: Support refs to anon symbols from asm This happens when e.g. string constants (or other static data) are passed as operands to inline asm as immediates. The produced symbol ref wouldn't be found. So tighten the connection between C and asm-local symbol table even more. --- tests/tcctest.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests') diff --git a/tests/tcctest.c b/tests/tcctest.c index f8e2040..b8e534f 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2741,6 +2741,28 @@ void override_func2 (void) printf ("asmc: override2\n"); } +/* This checks a construct used by the linux kernel to encode + references to strings by PC relative references. */ +extern int bug_table[] __attribute__((section("__bug_table"))); +char * get_asm_string (void) +{ + extern int some_symbol; + asm volatile (".globl some_symbol\n" + "jmp .+6\n" + "1:\n" + "some_symbol: .long 0\n" + ".pushsection __bug_table, \"a\"\n" + ".globl bug_table\n" + "bug_table:\n" + /* The first entry (1b-2b) is unused in this test, + but we include it to check if cross-section + PC-relative references work. */ + "2:\t.long 1b - 2b, %c0 - 2b\n" + ".popsection\n" : : "i" ("A string")); + char * str = ((char*)bug_table) + bug_table[1]; + return str; +} + unsigned int set; void asm_test(void) @@ -2812,6 +2834,7 @@ void asm_test(void) if (!somebool) printf("asmbool: failed\n"); #endif + printf("asmstr: %s\n", get_asm_string()); return; label1: goto label2; -- cgit v1.3.1