Re: [C++ PATCH, ABI] Fix mangling of TLS init and wrapper fns (PR c++/77285)

2016-11-18 Thread Jason Merrill
On Fri, Nov 11, 2016 at 7:23 AM, Jakub Jelinek  wrote:
> Not really sure if we want to call just check_abi_tags (based on the idea
> that likely any uses of the TLS var from other TUs will be broken),

I think that's fine.  OK.

Jason


[C++ PATCH, ABI] Fix mangling of TLS init and wrapper fns (PR c++/77285)

2016-11-11 Thread Jakub Jelinek
Hi!

The following testcase fails to link, because in one TU
(pr77285-2.C) we first mangle the TLS symbols and only afterwards
the TLS wrapper fn symbol (and don't emit TLS init fn symbol at all,
as there are no uses of the TLS var), while in the other TU
we first mangle TLS init and TLS wrapper symbol (therefore check_abi_tags
has not been called).

Not really sure if we want to call just check_abi_tags (based on the idea
that likely any uses of the TLS var from other TUs will be broken),
or use:
  if (abi_version_at_least (11))
maybe_check_abi_tags (variable, NULL_TREE, 11);
(perhaps with some extra new argument to maybe_check_abi_tags, some
enum, that would allow it to say which symbol it is - as it is not
initialization guard variable, but thread_local wrapper or thread_local
initialization function symbol).  For the latter speaks that if such a var
is exported, but not really used from other TUs, it is an ABI change.

2016-11-11  Jakub Jelinek  

PR c++/77285
* mangle.c (mangle_tls_init_fn, mangle_tls_wrapper_fn): Call
check_abi_tags.

* g++.dg/tls/pr77285-1.C: New test.
* g++.dg/tls/pr77285-2.C: New test.

--- gcc/cp/mangle.c.jj  2016-11-10 18:03:27.0 +0100
+++ gcc/cp/mangle.c 2016-11-11 12:53:55.657483383 +0100
@@ -4254,6 +4254,7 @@ mangle_guard_variable (const tree variab
 tree
 mangle_tls_init_fn (const tree variable)
 {
+  check_abi_tags (variable);
   start_mangling (variable);
   write_string ("_ZTH");
   write_guarded_var_name (variable);
@@ -4268,6 +4269,7 @@ mangle_tls_init_fn (const tree variable)
 tree
 mangle_tls_wrapper_fn (const tree variable)
 {
+  check_abi_tags (variable);
   start_mangling (variable);
   write_string (TLS_WRAPPER_PREFIX);
   write_guarded_var_name (variable);
--- gcc/testsuite/g++.dg/tls/pr77285-1.C.jj 2016-11-11 13:03:14.439409858 
+0100
+++ gcc/testsuite/g++.dg/tls/pr77285-1.C2016-11-11 12:58:58.663647680 
+0100
@@ -0,0 +1,7 @@
+// { dg-do link { target c++11 } }
+// { dg-require-effective-target tls }
+// { dg-additional-sources pr77285-2.C }
+
+struct __attribute__((abi_tag("tag"))) X { ~X () {} int i = 0; };
+thread_local X var1;
+X var2;
--- gcc/testsuite/g++.dg/tls/pr77285-2.C.jj 2016-11-11 13:03:17.725368262 
+0100
+++ gcc/testsuite/g++.dg/tls/pr77285-2.C2016-11-11 13:00:59.976112006 
+0100
@@ -0,0 +1,17 @@
+// PR c++/77285
+// { dg-do compile { target c++11 } }
+// { dg-require-effective-target tls }
+// { dg-final { scan-assembler "_Z4var1B3tag" } }
+// { dg-final { scan-assembler "_Z4var2B3tag" } }
+// { dg-final { scan-assembler "_ZTH4var1B3tag" } }
+// { dg-final { scan-assembler "_ZTW4var1B3tag" } }
+
+struct __attribute__((abi_tag("tag"))) X { ~X () {} int i = 0; };
+extern thread_local X var1;
+extern X var2;
+
+int
+main ()
+{
+ return var1.i + var2.i;
+}

Jakub