0012-Quote-from-bug-1443-which-explains-what-the-patch-do.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From add514edf4299d1bf540d85d0aa0bd5fe0d46b78 Mon Sep 17 00:00:00 2001
  2. From: Khem Raj <raj.khem@gmail.com>
  3. Date: Wed, 18 Mar 2015 00:20:09 +0000
  4. Subject: [PATCH] Quote from bug 1443 which explains what the patch does :
  5. We build some random program and link it with -lust. When we run it,
  6. it dies with a SIGSEGV before reaching main().
  7. Libust.so depends on liburcu-bp.so from the usermode-rcu package.
  8. Although libust.so is not prelinked, liburcu-bp.so IS prelinked; this
  9. is critical.
  10. Libust.so uses a TLS / __thread variable that is defined in liburcu-
  11. bp.so. There are special ARM-specific relocation types that allow two
  12. shared libraries to share thread-specific data. This is critical too.
  13. One more critical issue: although liburcu-bp.so is prelinked, we can't
  14. load it at its prelinked address, because we also link against
  15. librt.so, and librt.so uses that address.
  16. The dynamic linker is forced to relink liburcu-bp.so at a different
  17. address. In the course of relinking, it processes the special ARM
  18. relocation record mentioned above. The prelinker has already filled
  19. in the information, which is a short offset into a table of thread-
  20. specific data that is allocated per-thread for each library that uses
  21. TLS. Because the normal behavior of a relocation is to add the symbol
  22. value to an addend stored at the address being relocated, we end up
  23. adding the short offset to itself, doubling it.
  24. Now we have an awkward situation. The libust.so library doesn't know
  25. about the addend, so its TLS data for this element is correct. The
  26. liburcu-bp.so library has a different offset for the element. When we
  27. go to initialize the element for the first time in liburcu-bp.so, we
  28. write the address of the result at the doubled (broken) offset.
  29. Later, when we refer to the address from libust.so, we check the value
  30. at the correct offset, but it's NULL, so we eat hot SIGSEGV.
  31. Upstream-Status: Pending
  32. Signed-off-by: Andrei Dinu <andrei.adrianx.dinu@intel.com>
  33. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  34. ---
  35. sysdeps/arm/dl-machine.h | 2 +-
  36. 1 file changed, 1 insertion(+), 1 deletion(-)
  37. diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
  38. index ff5e09e207..d68bfe5cbe 100644
  39. --- a/sysdeps/arm/dl-machine.h
  40. +++ b/sysdeps/arm/dl-machine.h
  41. @@ -510,7 +510,7 @@ elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
  42. case R_ARM_TLS_DTPOFF32:
  43. if (sym != NULL)
  44. - *reloc_addr += sym->st_value;
  45. + *reloc_addr = sym->st_value;
  46. break;
  47. case R_ARM_TLS_TPOFF32: