sh.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. From 3840d4c2add1dd282f5f01fa51720b2d5b8fd8d2 Mon Sep 17 00:00:00 2001
  2. From: Alexey Neyman <stilor@att.net>
  3. Date: Wed, 8 Feb 2017 16:00:57 -0200
  4. Subject: [PATCH] sh: Fix building with gcc5/6
  5. Build glibc for sh4-unknown-linux-gnu currently fails if one's
  6. using GCC5/6: in dl-conflict.c, the elf_machine_rela() function
  7. is called with NULL as its 3rd argument, sym. The implementation
  8. of that function in sysdeps/sh/dl-machine.h dereferences that pointer:
  9. const Elf32_Sym *const refsym = sym;
  10. ...
  11. if (map == &GL(dl_rtld_map))
  12. value -= map->l_addr + refsym->st_value + reloc->r_addend;
  13. GCC discovers a null pointer dereference, and in accordance with
  14. -fdelete-null-pointer-checks (which is enabled in -O2) replaces this
  15. code with a trap - which, as SH does not implement a trap pattern in
  16. GCC, evaluates to an abort() call. This abort() call pulls many more
  17. objects from libc_nonshared.a, eventually resulting in link failure
  18. due to multiple definitions for a number of symbols.
  19. As far as I see, the conditional before this code is always false in
  20. rtld: _dl_resolve_conflicts() is called with main_map as the first
  21. argument, not GL(_dl_rtld_map), but since that call is in yet another
  22. compilation unit, GCC does not know about it. Patch that wraps this
  23. conditional into !defined RESOLVE_CONFLICT_FIND_MAP attached.
  24. * sysdeps/sh/dl-machine.h (elf_machine_rela): The condition
  25. in R_SH_DIR32 case is always false when inlined from
  26. dl-conflict.c. Ifdef out to prevent GCC from insertin an
  27. abort() call.
  28. [Waldemar: backport of
  29. https://sourceware.org/git/?p=glibc.git;a=commit;h=d40dbe722f004f999b589de776f7e57e564dda01.]
  30. Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
  31. ---
  32. sysdeps/sh/dl-machine.h | 2 +-
  33. 1 file changed, 1 insertion(+), 1 deletion(-)
  34. diff --git a/sysdeps/sh/dl-machine.h b/sysdeps/sh/dl-machine.h
  35. index 449deea..2b468af 100644
  36. --- a/sysdeps/sh/dl-machine.h
  37. +++ b/sysdeps/sh/dl-machine.h
  38. @@ -389,7 +389,7 @@ elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
  39. break;
  40. case R_SH_DIR32:
  41. {
  42. -#ifndef RTLD_BOOTSTRAP
  43. +#if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP
  44. /* This is defined in rtld.c, but nowhere in the static
  45. libc.a; make the reference weak so static programs can
  46. still link. This declaration cannot be done when
  47. --
  48. 2.7.4