From 5c6ce84a4ceffff39a1fa4c13ca430bad70ac6af Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 1 Jun 2018 08:10:25 +0900 Subject: [PATCH] Bug 1464084 - Don't export std::thread::_M_start_thread symbols with --enable-stdcxx-compat. r=froydnj This relies on the fact that providing multiple --version-script combines them all, so we effectively create a new symbol version that has no global symbol, but hides the std::thread::_M_start_thread symbols. This version script trick happens to work with BFD ld, gold, and lld. The downside is that when providing multiple --version-script's, ld doesn't want any of them to have no version at all. So for the libraries that do already have a version script (through SYMBOLS_FILE), we use a version where there used to be none, using the library name as the version. Practically speaking, this binds the libraries a little closer than they used to be, kind of non-flat namespace on OSX (which is the default there), meaning the dynamic linker will actively want to use symbols from those libraries instead of a system library that might happen to have the same symbol name. --HG-- extra : rebase_source : a7f672c35609d993849385ddb874ba791b34f929 --- build/unix/stdc++compat/hide_std.ld | 5 +++++ build/unix/stdc++compat/moz.build | 2 ++ python/mozbuild/mozbuild/action/generate_symbols_file.py | 9 +++++---- testing/cppunittest.ini | 1 - 4 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 build/unix/stdc++compat/hide_std.ld diff --git a/build/unix/stdc++compat/hide_std.ld b/build/unix/stdc++compat/hide_std.ld new file mode 100644 index 000000000000..4b3400b0f327 --- /dev/null +++ b/build/unix/stdc++compat/hide_std.ld @@ -0,0 +1,5 @@ +hidden { + local: + # std::thread::_M_start_thread(...) + _ZNSt6thread15_M_start_thread*; +}; diff --git a/build/unix/stdc++compat/moz.build b/build/unix/stdc++compat/moz.build index 20517a1caef5..4444d0c4f297 100644 --- a/build/unix/stdc++compat/moz.build +++ b/build/unix/stdc++compat/moz.build @@ -23,3 +23,5 @@ COMPILE_FLAGS['CLANG_PLUGIN'] = [] DEFINES['MOZ_LIBSTDCXX_VERSION'] = CONFIG['MOZ_LIBSTDCXX_TARGET_VERSION'] HOST_DEFINES['MOZ_LIBSTDCXX_VERSION'] = CONFIG['MOZ_LIBSTDCXX_HOST_VERSION'] + +OS_LIBS += ['-Wl,--version-script,%s/hide_std.ld' % SRCDIR] diff --git a/python/mozbuild/mozbuild/action/generate_symbols_file.py b/python/mozbuild/mozbuild/action/generate_symbols_file.py index f118060f47cf..bf1ae917a2d0 100644 --- a/python/mozbuild/mozbuild/action/generate_symbols_file.py +++ b/python/mozbuild/mozbuild/action/generate_symbols_file.py @@ -42,6 +42,8 @@ def generate_symbols_file(output, *args): symbols = [s.strip() for s in pp.out.getvalue().splitlines() if s.strip()] + libname, ext = os.path.splitext(os.path.basename(output.name)) + if buildconfig.substs['OS_TARGET'] == 'WINNT': # A def file is generated for MSVC link.exe that looks like the # following: @@ -66,14 +68,13 @@ def generate_symbols_file(output, *args): # those platforms, and to DATA on Windows, so that the "DATA" part # is, in fact, part of the symbol name as far as the symbols variable # is concerned. - libname, ext = os.path.splitext(os.path.basename(output.name)) assert ext == '.def' output.write('LIBRARY %s\nEXPORTS\n %s\n' % (libname, '\n '.join(symbols))) elif buildconfig.substs['GCC_USE_GNU_LD']: # A linker version script is generated for GNU LD that looks like the # following: - # { + # liblibrary.so { # global: # symbol1; # symbol2; @@ -81,8 +82,8 @@ def generate_symbols_file(output, *args): # local: # *; # }; - output.write('{\nglobal:\n %s;\nlocal:\n *;\n};' - % ';\n '.join(symbols)) + output.write('%s {\nglobal:\n %s;\nlocal:\n *;\n};' + % (libname, ';\n '.join(symbols))) elif buildconfig.substs['OS_TARGET'] == 'Darwin': # A list of symbols is generated for Apple ld that simply lists all # symbols, with an underscore prefix. diff --git a/testing/cppunittest.ini b/testing/cppunittest.ini index 462d572f8c24..54efaf97b6be 100644 --- a/testing/cppunittest.ini +++ b/testing/cppunittest.ini @@ -43,7 +43,6 @@ skip-if = os == 'android' # Bug 1147630 [TestSaturate] [TestSplayTree] [TestSPSCQueue] -skip-if = os == 'linux' # Bug 1464084 [TestSyncRunnable] [TestTemplateLib] [TestTuple]