1*4882a593SmuzhiyunFrom 203b80f8dbdd3ddb860114b03351a0dea28c978f Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Giulio Benetti <giulio.benetti@benettiengineering.com>
3*4882a593SmuzhiyunDate: Sat, 10 Jul 2021 17:57:34 +0200
4*4882a593SmuzhiyunSubject: [PATCH] or1k: fix pc-relative relocation against dynamic on PC
5*4882a593Smuzhiyun relative 26 bit relocation
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunWhen building openal we were seeing the assert failure:
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun/home/buildroot/autobuild/run/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/or1k-buildroot-linux-uclibc/9.3.0/../../../../or1k-buildroot-linux-uclibc/bin/ld: CMakeFiles/OpenAL.dir/al/source.cpp.o:
10*4882a593Smuzhiyunpc-relative relocation against dynamic symbol alSourcePausev
11*4882a593Smuzhiyun/home/buildroot/autobuild/run/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/or1k-buildroot-linux-uclibc/9.3.0/../../../../or1k-buildroot-linux-uclibc/bin/ld: CMakeFiles/OpenAL.dir/al/source.cpp.o:
12*4882a593Smuzhiyunpc-relative relocation against dynamic symbol alSourceStopv
13*4882a593Smuzhiyun/home/buildroot/autobuild/run/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/or1k-buildroot-linux-uclibc/9.3.0/../../../../or1k-buildroot-linux-uclibc/bin/ld: CMakeFiles/OpenAL.dir/al/source.cpp.o:
14*4882a593Smuzhiyunpc-relative relocation against dynamic symbol alSourceRewindv
15*4882a593Smuzhiyun/home/buildroot/autobuild/run/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/or1k-buildroot-linux-uclibc/9.3.0/../../../../or1k-buildroot-linux-uclibc/bin/ld: CMakeFiles/OpenAL.dir/al/source.cpp.o:
16*4882a593Smuzhiyunpc-relative relocation against dynamic symbol alSourcePlayv
17*4882a593Smuzhiyuncollect2: error: ld returned 1 exit status
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunThis happens because in R_OR1K_INSN_REL_26 case we can't reference local
20*4882a593Smuzhiyunsymbol as previously done but we need to make sure that calls to actual
21*4882a593Smuzhiyunsymbol always call the version of current object.
22*4882a593Smuzhiyun
23*4882a593Smuzhiyunbfd/Changelog:
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun	* elf32-or1k.c (or1k_elf_relocate_section): use a separate entry
26*4882a593Smuzhiyun	  in switch case R_OR1K_INSN_REL_26 where we need to check for
27*4882a593Smuzhiyun	  !SYMBOL_CALLS_LOCAL() instead of !SYMBOL_REFERENCES_LOCAL().
28*4882a593Smuzhiyun
29*4882a593SmuzhiyunSigned-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
30*4882a593Smuzhiyun---
31*4882a593Smuzhiyun bfd/elf32-or1k.c | 12 ++++++++++++
32*4882a593Smuzhiyun 1 file changed, 12 insertions(+)
33*4882a593Smuzhiyun
34*4882a593Smuzhiyundiff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c
35*4882a593Smuzhiyunindex 32063ab0289..67252394173 100644
36*4882a593Smuzhiyun--- a/bfd/elf32-or1k.c
37*4882a593Smuzhiyun+++ b/bfd/elf32-or1k.c
38*4882a593Smuzhiyun@@ -1543,6 +1543,18 @@ or1k_elf_relocate_section (bfd *output_bfd,
39*4882a593Smuzhiyun 	  break;
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun 	case R_OR1K_INSN_REL_26:
42*4882a593Smuzhiyun+	  /* For a non-shared link, these will reference plt or call the
43*4882a593Smuzhiyun+	     version of actual object.  */
44*4882a593Smuzhiyun+	  if (bfd_link_pic (info) && !SYMBOL_CALLS_LOCAL (info, h))
45*4882a593Smuzhiyun+	    {
46*4882a593Smuzhiyun+	      _bfd_error_handler
47*4882a593Smuzhiyun+		(_("%pB: pc-relative relocation against dynamic symbol %s"),
48*4882a593Smuzhiyun+		 input_bfd, name);
49*4882a593Smuzhiyun+	      ret_val = false;
50*4882a593Smuzhiyun+	      bfd_set_error (bfd_error_bad_value);
51*4882a593Smuzhiyun+	    }
52*4882a593Smuzhiyun+	  break;
53*4882a593Smuzhiyun+
54*4882a593Smuzhiyun 	case R_OR1K_PCREL_PG21:
55*4882a593Smuzhiyun 	case R_OR1K_LO13:
56*4882a593Smuzhiyun 	case R_OR1K_SLO13:
57*4882a593Smuzhiyun--
58*4882a593Smuzhiyun2.31.1
59*4882a593Smuzhiyun
60