diff --git a/build/config/BUILD.gn b/build/config/BUILD.gn index f0186809cf4..418e7c18ae0 100644 --- a/build/config/BUILD.gn +++ b/build/config/BUILD.gn @@ -18,17 +18,3 @@ config("product") { "PRODUCT", ] } - -config("shared_library_config") { - if (current_os == "android" || current_os == "fuchsia" || - current_os == "linux" || current_os == "mac") { - cflags = [ "-fPIC" ] - } -} - -config("executable_config") { - if (current_os == "android" || current_os == "fuchsia" || - current_os == "linux" || current_os == "mac") { - cflags = [ "-fPIE" ] - } -} diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index 787254cd6da..739b935642f 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -313,8 +313,7 @@ if (is_win) { } # Executable defaults. -_executable_configs = - _native_compiler_configs + [ "//build/config:executable_config" ] +_executable_configs = _native_compiler_configs if (is_win) { _executable_configs += _windows_linker_configs } else if (is_mac) { @@ -343,8 +342,7 @@ set_defaults("static_library") { } # Shared library defaults (also for components in component mode). -_shared_library_configs = - _native_compiler_configs + [ "//build/config:shared_library_config" ] +_shared_library_configs = _native_compiler_configs if (is_win) { _shared_library_configs += _windows_linker_configs } else if (is_mac) { diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index a0124d0d2a4..feb13b1af62 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -249,6 +249,17 @@ config("compiler") { ] } + # We need -fPIC: + # 1. On ARM for tcmalloc. + # 2. On Android. + # 3. When using the sanitizers. + # Otherwise there is a performance hit, in particular on ia32. + if (is_android || is_asan || is_lsan || is_msan || is_tsan || is_ubsan || + (is_linux && current_cpu != "x86") || is_fuchsia) { + cflags += [ "-fPIC" ] + ldflags += [ "-fPIC" ] + } + # Linux-specific compiler flags setup. # ------------------------------------ if (is_linux) { diff --git a/runtime/bin/BUILD.gn b/runtime/bin/BUILD.gn index a8e57044e61..d7d60a74ff6 100644 --- a/runtime/bin/BUILD.gn +++ b/runtime/bin/BUILD.gn @@ -1036,6 +1036,9 @@ shared_library("entrypoints_verification_test") { # The only effect of DART_SHARED_LIB is to export the Dart API. "DART_SHARED_LIB", ] + if (is_linux || is_android) { + cflags = [ "-fPIC" ] + } if (is_win) { # TODO(dartbug.com/40579): This wrongly links in dart.exe on precompiled. libs = [ "dart.lib" ] @@ -1052,6 +1055,9 @@ shared_library("ffi_test_dynamic_library") { # The only effect of DART_SHARED_LIB is to export the Dart API. "DART_SHARED_LIB", ] + if (is_linux || is_android) { + cflags = [ "-fPIC" ] + } if (is_win) { # TODO(dartbug.com/40579): This wrongly links in dart.exe on precompiled. libs = [ "dart.lib" ] @@ -1085,6 +1091,9 @@ shared_library("ffi_test_functions") { # The only effect of DART_SHARED_LIB is to export the Dart API. "DART_SHARED_LIB", ] + if (is_linux || is_android) { + cflags = [ "-fPIC" ] + } if (is_win) { # TODO(dartbug.com/40579): This wrongly links in dart.exe on precompiled. libs = [ "dart.lib" ] diff --git a/runtime/vm/os_thread.cc b/runtime/vm/os_thread.cc index 9bc6f61c358..c709cbc3592 100644 --- a/runtime/vm/os_thread.cc +++ b/runtime/vm/os_thread.cc @@ -20,6 +20,11 @@ OSThread* OSThread::thread_list_head_ = NULL; Mutex* OSThread::thread_list_lock_ = NULL; bool OSThread::creation_enabled_ = false; +thread_local ThreadState* OSThread::current_vm_thread_ = NULL; +#if defined(DEBUG) +thread_local bool ThreadInterruptScope::in_thread_interrupt_scope_ = false; +#endif + #if defined(SUPPORT_TIMELINE) inline void UpdateTimelineTrackMetadata(const OSThread& thread) { RecorderSynchronizationLockScope ls; diff --git a/runtime/vm/os_thread.h b/runtime/vm/os_thread.h index 5940cd7e11d..c934c7c7f1a 100644 --- a/runtime/vm/os_thread.h +++ b/runtime/vm/os_thread.h @@ -306,9 +306,7 @@ class OSThread : public BaseThread { static OSThread* thread_list_head_; static bool creation_enabled_; - // Inline initialization is important for avoiding unnecessary TLS - // initialization checks at each use. - static inline thread_local ThreadState* current_vm_thread_ = nullptr; + static thread_local ThreadState* current_vm_thread_; friend class IsolateGroup; // to access set_thread(Thread*). friend class OSThreadIterator; @@ -414,7 +412,7 @@ class ThreadInterruptScope : public ValueObject { private: ThreadState* saved_current_vm_thread_; - static inline thread_local bool in_thread_interrupt_scope_ = false; + static thread_local bool in_thread_interrupt_scope_; #endif // DEBUG }; diff --git a/tests/standalone/pie_test.dart b/tests/standalone/pie_test.dart deleted file mode 100644 index 8d0e025cb52..00000000000 --- a/tests/standalone/pie_test.dart +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import "dart:io"; - -// Mmmm... pie! -main() { - if (!Platform.isLinux) return; // readelf is a Linux tool. - // Modern Mac and Android binaries are always PIE. - // Fuchsia binaries are always PIE. - - var result = Process.runSync("readelf", ["-h", Platform.resolvedExecutable]); - print("stdout:"); - print(result.stdout); - print("stderr:"); - print(result.stderr); - - if (result.exitCode != 0) { - throw "readelf failed"; - } - - // A position-dependent executable outputs "EXEC (Executable file)". - if (!result.stdout.contains("DYN (Position-Independent Executable file)") && - !result.stdout.contains("DYN (Shared object file)")) { - throw "Standalone VM should be a position-independent executable"; - } -}