diff options
-rw-r--r-- | cfrontend/C2C.ml | 9 | ||||
-rw-r--r-- | cparser/Elab.ml | 2 | ||||
-rw-r--r-- | mppa_k1c/TargetPrinter.ml | 12 | ||||
-rw-r--r-- | runtime/include/ccomp_k1c_fixes.h | 2 | ||||
-rw-r--r-- | test/monniaux/thread_local/thread_local.c | 4 |
5 files changed, 23 insertions, 6 deletions
diff --git a/cfrontend/C2C.ml b/cfrontend/C2C.ml index 015a2eb6..d03392b1 100644 --- a/cfrontend/C2C.ml +++ b/cfrontend/C2C.ml @@ -59,6 +59,15 @@ let atom_is_extern a = with Not_found -> false +let atom_is_thread_local a = + try + match (Hashtbl.find decl_atom a).a_storage with + | C.Storage_thread_local_extern| C.Storage_thread_local_static + | C.Storage_thread_local -> true + | _ -> false + with Not_found -> + false + let atom_alignof a = try (Hashtbl.find decl_atom a).a_alignment diff --git a/cparser/Elab.ml b/cparser/Elab.ml index 42505a2c..3c754dd6 100644 --- a/cparser/Elab.ml +++ b/cparser/Elab.ml @@ -655,7 +655,7 @@ let rec elab_specifier ?(only = false) loc env specifier = restrict := cv = CV_RESTRICT; attr := add_attributes (elab_cvspec env cv) !attr | SpecStorage st -> - if !sto <> Storage_default && st <> TYPEDEF then + if !sto <> Storage_default && st <> TYPEDEF && st <> THREAD_LOCAL then error loc "multiple storage classes in declaration specifier"; begin match st with | AUTO -> sto := Storage_auto diff --git a/mppa_k1c/TargetPrinter.ml b/mppa_k1c/TargetPrinter.ml index 930b1c51..886b58d3 100644 --- a/mppa_k1c/TargetPrinter.ml +++ b/mppa_k1c/TargetPrinter.ml @@ -211,13 +211,17 @@ module Target (*: TARGET*) = (* Generate code to load the address of id + ofs in register r *) -(* FIXME DMonniaux ugly ugly hack to get at standard __thread data *) let loadsymbol oc r id ofs = if Archi.pic_code () then begin assert (ofs = Integers.Ptrofs.zero); - fprintf oc " make %a = %s\n" ireg r (extern_atom id) - end else begin - if (extern_atom id) = "_impure_thread_data" then begin + if C2C.atom_is_thread_local id then begin + fprintf oc " addd %a = $r13, @tprel(%s)\n" ireg r (extern_atom id) + end else begin + fprintf oc " make %a = %s\n" ireg r (extern_atom id) + end + end else + begin + if C2C.atom_is_thread_local id then begin fprintf oc " addd %a = $r13, @tprel(%a)\n" ireg r symbol_offset (id, ofs) end else begin fprintf oc " make %a = %a\n" ireg r symbol_offset (id, ofs) diff --git a/runtime/include/ccomp_k1c_fixes.h b/runtime/include/ccomp_k1c_fixes.h index 718ac3e5..69097d06 100644 --- a/runtime/include/ccomp_k1c_fixes.h +++ b/runtime/include/ccomp_k1c_fixes.h @@ -6,7 +6,7 @@ #endif #undef __GNUC__ -#define __thread +#define __thread _Thread_local struct __int128_ccomp { long __int128_ccomp_low; long __int128_ccomp_high; }; diff --git a/test/monniaux/thread_local/thread_local.c b/test/monniaux/thread_local/thread_local.c index 48f9d99a..824c8543 100644 --- a/test/monniaux/thread_local/thread_local.c +++ b/test/monniaux/thread_local/thread_local.c @@ -1,2 +1,6 @@ _Thread_local int toto; int toto2; + +int foobar(void) { + return toto; +} |