allocator_shim_internals.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_ALLOCATOR_ALLOCATOR_SHIM_INTERNALS_H_
  5. #define BASE_ALLOCATOR_ALLOCATOR_SHIM_INTERNALS_H_
  6. #include "build/build_config.h"
  7. #if defined(__GNUC__)
  8. #include <sys/cdefs.h> // for __THROW
  9. #ifndef __THROW // Not a glibc system
  10. #ifdef _NOEXCEPT // LLVM libc++ uses noexcept instead
  11. #define __THROW _NOEXCEPT
  12. #else
  13. #define __THROW
  14. #endif // !_NOEXCEPT
  15. #endif
  16. // Shim layer symbols need to be ALWAYS exported, regardless of component build.
  17. //
  18. // If an exported symbol is linked into a DSO, it may be preempted by a
  19. // definition in the main executable. If this happens to an allocator symbol, it
  20. // will mean that the DSO will use the main executable's allocator. This is
  21. // normally relatively harmless -- regular allocations should all use the same
  22. // allocator, but if the DSO tries to hook the allocator it will not see any
  23. // allocations.
  24. //
  25. // However, if LLVM LTO is enabled, the compiler may inline the shim layer
  26. // symbols into callers. The end result is that allocator calls in DSOs may use
  27. // either the main executable's allocator or the DSO's allocator, depending on
  28. // whether the call was inlined. This is arguably a bug in LLVM caused by its
  29. // somewhat irregular handling of symbol interposition (see llvm.org/PR23501).
  30. // To work around the bug we use noinline to prevent the symbols from being
  31. // inlined.
  32. //
  33. // In the long run we probably want to avoid linking the allocator bits into
  34. // DSOs altogether. This will save a little space and stop giving DSOs the false
  35. // impression that they can hook the allocator.
  36. #define SHIM_ALWAYS_EXPORT __attribute__((visibility("default"), noinline))
  37. #elif defined(OS_WIN) // __GNUC__
  38. #define __THROW
  39. #define SHIM_ALWAYS_EXPORT __declspec(noinline)
  40. #endif // __GNUC__
  41. #endif // BASE_ALLOCATOR_ALLOCATOR_SHIM_INTERNALS_H_