summaryrefslogtreecommitdiff
path: root/toolchain/elf2flt/patches/453398f917d167f8c308c8f997270c48ae8f8b12/0004-elf2flt.c-add-new-relocation-types-for-xtensa.patch
blob: 953bd79ccf989cf84d33f99d46b163dd056bb9c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
From d7eb73163bcea31168c438fc132a0967ac172e3d Mon Sep 17 00:00:00 2001
From: Max Filippov <jcmvbkbc@gmail.com>
Date: Thu, 7 May 2020 21:11:43 -0700
Subject: [PATCH] elf2flt.c: add new relocation types for xtensa

Xtensa have added new relocation types R_XTENSA_[NP]DIFF{8,16,32} with
the same properties as the existing types R_XTENSA_DIFF{8,16,32}.
Add them to the list of ignored relocation types.

This fixes the following error when invoking elf2flt on xtensa binaries
built with the recent binutils:

  ERROR: reloc type R_XTENSA_PDIFF32 unsupported in this context

Reported-by: Romain Naour <romain.naour@gmail.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Backported from: d7eb73163bcea31168c438fc132a0967ac172e3d
---
 Makefile.in  |  3 ++-
 configure    | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 configure.ac | 14 ++++++++++++
 elf2flt.c    |  8 +++++++
 4 files changed, 88 insertions(+), 1 deletion(-)

diff --git a/Makefile.in b/Makefile.in
index 52b3347d7f43..0529c7f0a25a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -30,7 +30,8 @@ DEFS = @DEFS@ \
 	-DNO_GOT_CHECK=@got_check@ \
 	-DUSE_EMIT_RELOCS=@emit_relocs@ \
 	-DEMIT_CTOR_DTOR=@emit_ctor_dtor@ \
-	-DALWAYS_RELOC_TEXT=@always_reloc_text@
+	-DALWAYS_RELOC_TEXT=@always_reloc_text@ \
+	-DHAVE_BFD_XTENSA_PDIFF_RELOCS=@HAVE_BFD_XTENSA_PDIFF_RELOCS@
 EXEEXT = @EXEEXT@
 OBJEXT = @OBJEXT@
 
diff --git a/configure b/configure
index bb8e33f9cb28..bca38c34247e 100755
--- a/configure
+++ b/configure
@@ -621,6 +621,7 @@ ac_includes_default="\
 
 ac_subst_vars='LTLIBOBJS
 LIBOBJS
+HAVE_BFD_XTENSA_PDIFF_RELOCS
 SYMBOL_PREFIX
 always_reloc_text
 emit_ctor_dtor
@@ -1729,6 +1730,52 @@ fi
 
 } # ac_fn_c_try_link
 
+# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES
+# ---------------------------------------------
+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR
+# accordingly.
+ac_fn_c_check_decl ()
+{
+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
+  as_decl_name=`echo $2|sed 's/ *(.*//'`
+  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5
+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }
+if eval \${$3+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$4
+int
+main ()
+{
+#ifndef $as_decl_name
+#ifdef __cplusplus
+  (void) $as_decl_use;
+#else
+  (void) $as_decl_name;
+#endif
+#endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  eval "$3=yes"
+else
+  eval "$3=no"
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+eval ac_res=\$$3
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
+
+} # ac_fn_c_check_decl
+
 # ac_fn_c_check_func LINENO FUNC VAR
 # ----------------------------------
 # Tests whether FUNC exists, setting the cache variable VAR accordingly
@@ -4272,6 +4319,22 @@ $as_echo "#define const /**/" >>confdefs.h
 fi
 
 
+HAVE_BFD_XTENSA_PDIFF_RELOCS=0
+case $target in
+	xtensa*)
+		OLD_CPPFLAGS=$CPPFLAGS
+		CPPFLAGS="-I$bfd_include_dir -I$binutils_include_dir $CPPFLAGS"
+		ac_fn_c_check_decl "$LINENO" "R_XTENSA_PDIFF8" "ac_cv_have_decl_R_XTENSA_PDIFF8" "#include \"bfd.h\"
+			       #include \"elf/xtensa.h\"
+"
+if test "x$ac_cv_have_decl_R_XTENSA_PDIFF8" = xyes; then :
+  HAVE_BFD_XTENSA_PDIFF_RELOCS=1
+fi
+
+		CPPFLAGS=$OLD_CPPFLAGS
+		;;
+esac
+
 for ac_func in vprintf
 do :
   ac_fn_c_check_func "$LINENO" "vprintf" "ac_cv_func_vprintf"
@@ -4333,6 +4396,7 @@ fi
 
 
 
+
 ac_config_files="$ac_config_files ld-elf2flt.sh:ld-elf2flt.in Makefile elf2flt.ld"
 
 cat >confcache <<\_ACEOF
diff --git a/configure.ac b/configure.ac
index d6b4119eb18a..19969b1045f6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -202,6 +202,19 @@ AC_CHECK_HEADERS(fcntl.h unistd.h bfd.h)
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
 
+HAVE_BFD_XTENSA_PDIFF_RELOCS=0
+case $target in
+	xtensa*)
+		AS_VAR_COPY([OLD_CPPFLAGS], [CPPFLAGS])
+		AS_VAR_SET([CPPFLAGS], ["-I$bfd_include_dir -I$binutils_include_dir $CPPFLAGS"])
+		AC_CHECK_DECL([R_XTENSA_PDIFF8],
+			      [HAVE_BFD_XTENSA_PDIFF_RELOCS=1],,
+			      [#include "bfd.h"
+			       #include "elf/xtensa.h"])
+		AS_VAR_COPY([CPPFLAGS], [OLD_CPPFLAGS])
+		;;
+esac
+
 dnl Checks for library functions.
 AC_FUNC_VPRINTF
 
@@ -235,6 +248,7 @@ AC_SUBST(emit_relocs)
 AC_SUBST(emit_ctor_dtor)
 AC_SUBST(always_reloc_text)
 AC_SUBST(SYMBOL_PREFIX)
+AC_SUBST(HAVE_BFD_XTENSA_PDIFF_RELOCS)
 
 AC_OUTPUT(ld-elf2flt.sh:ld-elf2flt.in Makefile elf2flt.ld)
 
diff --git a/elf2flt.c b/elf2flt.c
index b7c4a490df02..961534973f56 100644
--- a/elf2flt.c
+++ b/elf2flt.c
@@ -776,6 +776,14 @@ output_relocs (
 				case R_XTENSA_DIFF8:
 				case R_XTENSA_DIFF16:
 				case R_XTENSA_DIFF32:
+#if HAVE_BFD_XTENSA_PDIFF_RELOCS
+				case R_XTENSA_PDIFF8:
+				case R_XTENSA_PDIFF16:
+				case R_XTENSA_PDIFF32:
+				case R_XTENSA_NDIFF8:
+				case R_XTENSA_NDIFF16:
+				case R_XTENSA_NDIFF32:
+#endif
 				case R_XTENSA_32_PCREL:
 					continue;
 				case R_XTENSA_32:
-- 
2.20.1