Make.rules incomplete/wrong; make -r failure
[syslinux-gnu-efi.git] / gnuefi / reloc_mips64el.c
blob4db21adce5cb4d01412109369b2f9f216ce782cf
1 /* reloc_mips64el.c - position independent MIPS64 ELF shared object relocator
2 Copyright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
3 Copyright (C) 1999 Hewlett-Packard Co.
4 Contributed by David Mosberger <davidm@hpl.hp.com>.
5 Copyright (C) 2017 Lemote Co.
6 Contributed by Heiher <r@hev.cc>
8 All rights reserved.
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions
12 are met:
14 * Redistributions of source code must retain the above copyright
15 notice, this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above
17 copyright notice, this list of conditions and the following
18 disclaimer in the documentation and/or other materials
19 provided with the distribution.
20 * Neither the name of Hewlett-Packard Co. nor the names of its
21 contributors may be used to endorse or promote products derived
22 from this software without specific prior written permission.
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
29 BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
30 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
35 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 SUCH DAMAGE.
39 #include <efi.h>
40 #include <efilib.h>
42 #include <elf.h>
44 EFI_STATUS _relocate (long ldbase, Elf64_Dyn *dyn,
45 EFI_HANDLE image EFI_UNUSED,
46 EFI_SYSTEM_TABLE *systab EFI_UNUSED)
48 long relsz = 0, relent = 0, gotsz = 0;
49 Elf64_Rel *rel = 0;
50 unsigned long *addr = 0;
51 int i;
53 for (i = 0; dyn[i].d_tag != DT_NULL; ++i) {
54 switch (dyn[i].d_tag) {
55 case DT_REL:
56 rel = (Elf64_Rel*)
57 ((unsigned long)dyn[i].d_un.d_ptr
58 + ldbase);
59 break;
61 case DT_RELSZ:
62 relsz = dyn[i].d_un.d_val;
63 break;
65 case DT_RELENT:
66 relent = dyn[i].d_un.d_val;
67 break;
69 case DT_PLTGOT:
70 addr = (unsigned long *)
71 ((unsigned long)dyn[i].d_un.d_ptr
72 + ldbase);
73 break;
75 case DT_MIPS_LOCAL_GOTNO:
76 gotsz = dyn[i].d_un.d_val;
77 break;
79 default:
80 break;
84 if ((!rel && relent == 0) && (!addr && gotsz == 0))
85 return EFI_SUCCESS;
87 if ((!rel && relent != 0) || (!addr && gotsz != 0))
88 return EFI_LOAD_ERROR;
90 while (gotsz > 0) {
91 *addr += ldbase;
92 addr += 1;
93 gotsz --;
96 while (relsz > 0) {
97 /* apply the relocs */
98 switch (ELF64_R_TYPE (swap_uint64 (rel->r_info))) {
99 case R_MIPS_NONE:
100 break;
102 case (R_MIPS_64 << 8) | R_MIPS_REL32:
103 addr = (unsigned long *)
104 (ldbase + rel->r_offset);
105 *addr += ldbase;
106 break;
108 default:
109 break;
111 rel = (Elf64_Rel*) ((char *) rel + relent);
112 relsz -= relent;
114 return EFI_SUCCESS;