0004-elf2flt.c-add-new-relocation-types-for-xtensa.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. From d7eb73163bcea31168c438fc132a0967ac172e3d Mon Sep 17 00:00:00 2001
  2. From: Max Filippov <jcmvbkbc@gmail.com>
  3. Date: Thu, 7 May 2020 21:11:43 -0700
  4. Subject: [PATCH] elf2flt.c: add new relocation types for xtensa
  5. Xtensa have added new relocation types R_XTENSA_[NP]DIFF{8,16,32} with
  6. the same properties as the existing types R_XTENSA_DIFF{8,16,32}.
  7. Add them to the list of ignored relocation types.
  8. This fixes the following error when invoking elf2flt on xtensa binaries
  9. built with the recent binutils:
  10. ERROR: reloc type R_XTENSA_PDIFF32 unsupported in this context
  11. Reported-by: Romain Naour <romain.naour@gmail.com>
  12. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
  13. Backported from: d7eb73163bcea31168c438fc132a0967ac172e3d
  14. ---
  15. Makefile.in | 3 ++-
  16. configure | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  17. configure.ac | 14 ++++++++++++
  18. elf2flt.c | 8 +++++++
  19. 4 files changed, 88 insertions(+), 1 deletion(-)
  20. diff --git a/Makefile.in b/Makefile.in
  21. index 52b3347d7f43..0529c7f0a25a 100644
  22. --- a/Makefile.in
  23. +++ b/Makefile.in
  24. @@ -30,7 +30,8 @@ DEFS = @DEFS@ \
  25. -DNO_GOT_CHECK=@got_check@ \
  26. -DUSE_EMIT_RELOCS=@emit_relocs@ \
  27. -DEMIT_CTOR_DTOR=@emit_ctor_dtor@ \
  28. - -DALWAYS_RELOC_TEXT=@always_reloc_text@
  29. + -DALWAYS_RELOC_TEXT=@always_reloc_text@ \
  30. + -DHAVE_BFD_XTENSA_PDIFF_RELOCS=@HAVE_BFD_XTENSA_PDIFF_RELOCS@
  31. EXEEXT = @EXEEXT@
  32. OBJEXT = @OBJEXT@
  33. diff --git a/configure b/configure
  34. index bb8e33f9cb28..bca38c34247e 100755
  35. --- a/configure
  36. +++ b/configure
  37. @@ -621,6 +621,7 @@ ac_includes_default="\
  38. ac_subst_vars='LTLIBOBJS
  39. LIBOBJS
  40. +HAVE_BFD_XTENSA_PDIFF_RELOCS
  41. SYMBOL_PREFIX
  42. always_reloc_text
  43. emit_ctor_dtor
  44. @@ -1729,6 +1730,52 @@ fi
  45. } # ac_fn_c_try_link
  46. +# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
  47. +# ---------------------------------------------
  48. +# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
  49. +# accordingly.
  50. +ac_fn_c_check_decl ()
  51. +{
  52. + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  53. + as_decl_name=`echo $2|sed 's/ *(.*//'`
  54. + as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
  55. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
  56. +$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
  57. +if eval \${$3+:} false; then :
  58. + $as_echo_n "(cached) " >&6
  59. +else
  60. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  61. +/* end confdefs.h. */
  62. +$4
  63. +int
  64. +main ()
  65. +{
  66. +#ifndef $as_decl_name
  67. +#ifdef __cplusplus
  68. + (void) $as_decl_use;
  69. +#else
  70. + (void) $as_decl_name;
  71. +#endif
  72. +#endif
  73. +
  74. + ;
  75. + return 0;
  76. +}
  77. +_ACEOF
  78. +if ac_fn_c_try_compile "$LINENO"; then :
  79. + eval "$3=yes"
  80. +else
  81. + eval "$3=no"
  82. +fi
  83. +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  84. +fi
  85. +eval ac_res=\$$3
  86. + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
  87. +$as_echo "$ac_res" >&6; }
  88. + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  89. +
  90. +} # ac_fn_c_check_decl
  91. +
  92. # ac_fn_c_check_func LINENO FUNC VAR
  93. # ----------------------------------
  94. # Tests whether FUNC exists, setting the cache variable VAR accordingly
  95. @@ -4272,6 +4319,22 @@ $as_echo "#define const /**/" >>confdefs.h
  96. fi
  97. +HAVE_BFD_XTENSA_PDIFF_RELOCS=0
  98. +case $target in
  99. + xtensa*)
  100. + OLD_CPPFLAGS=$CPPFLAGS
  101. + CPPFLAGS="-I$bfd_include_dir -I$binutils_include_dir $CPPFLAGS"
  102. + ac_fn_c_check_decl "$LINENO" "R_XTENSA_PDIFF8" "ac_cv_have_decl_R_XTENSA_PDIFF8" "#include \"bfd.h\"
  103. + #include \"elf/xtensa.h\"
  104. +"
  105. +if test "x$ac_cv_have_decl_R_XTENSA_PDIFF8" = xyes; then :
  106. + HAVE_BFD_XTENSA_PDIFF_RELOCS=1
  107. +fi
  108. +
  109. + CPPFLAGS=$OLD_CPPFLAGS
  110. + ;;
  111. +esac
  112. +
  113. for ac_func in vprintf
  114. do :
  115. ac_fn_c_check_func "$LINENO" "vprintf" "ac_cv_func_vprintf"
  116. @@ -4333,6 +4396,7 @@ fi
  117. +
  118. ac_config_files="$ac_config_files ld-elf2flt.sh:ld-elf2flt.in Makefile elf2flt.ld"
  119. cat >confcache <<\_ACEOF
  120. diff --git a/configure.ac b/configure.ac
  121. index d6b4119eb18a..19969b1045f6 100644
  122. --- a/configure.ac
  123. +++ b/configure.ac
  124. @@ -202,6 +202,19 @@ AC_CHECK_HEADERS(fcntl.h unistd.h bfd.h)
  125. dnl Checks for typedefs, structures, and compiler characteristics.
  126. AC_C_CONST
  127. +HAVE_BFD_XTENSA_PDIFF_RELOCS=0
  128. +case $target in
  129. + xtensa*)
  130. + AS_VAR_COPY([OLD_CPPFLAGS], [CPPFLAGS])
  131. + AS_VAR_SET([CPPFLAGS], ["-I$bfd_include_dir -I$binutils_include_dir $CPPFLAGS"])
  132. + AC_CHECK_DECL([R_XTENSA_PDIFF8],
  133. + [HAVE_BFD_XTENSA_PDIFF_RELOCS=1],,
  134. + [#include "bfd.h"
  135. + #include "elf/xtensa.h"])
  136. + AS_VAR_COPY([CPPFLAGS], [OLD_CPPFLAGS])
  137. + ;;
  138. +esac
  139. +
  140. dnl Checks for library functions.
  141. AC_FUNC_VPRINTF
  142. @@ -235,6 +248,7 @@ AC_SUBST(emit_relocs)
  143. AC_SUBST(emit_ctor_dtor)
  144. AC_SUBST(always_reloc_text)
  145. AC_SUBST(SYMBOL_PREFIX)
  146. +AC_SUBST(HAVE_BFD_XTENSA_PDIFF_RELOCS)
  147. AC_OUTPUT(ld-elf2flt.sh:ld-elf2flt.in Makefile elf2flt.ld)
  148. diff --git a/elf2flt.c b/elf2flt.c
  149. index b7c4a490df02..961534973f56 100644
  150. --- a/elf2flt.c
  151. +++ b/elf2flt.c
  152. @@ -776,6 +776,14 @@ output_relocs (
  153. case R_XTENSA_DIFF8:
  154. case R_XTENSA_DIFF16:
  155. case R_XTENSA_DIFF32:
  156. +#if HAVE_BFD_XTENSA_PDIFF_RELOCS
  157. + case R_XTENSA_PDIFF8:
  158. + case R_XTENSA_PDIFF16:
  159. + case R_XTENSA_PDIFF32:
  160. + case R_XTENSA_NDIFF8:
  161. + case R_XTENSA_NDIFF16:
  162. + case R_XTENSA_NDIFF32:
  163. +#endif
  164. case R_XTENSA_32_PCREL:
  165. continue;
  166. case R_XTENSA_32:
  167. --
  168. 2.20.1