2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Code to dynamically load ELF executables
8 1997/12/13: Changed filename to internalloadseg_elf.c
9 Original file was created by digulla.
14 #include <aros/asmcall.h>
15 #include <aros/debug.h>
16 #include <aros/macros.h>
17 #include <exec/memory.h>
19 #include <dos/dosasl.h>
20 #include <libraries/debug.h>
21 #include <resources/processor.h>
22 #include <proto/dos.h>
23 #include <proto/arossupport.h>
24 #include <proto/debug.h>
25 #include <proto/exec.h>
30 #include "internalloadseg.h"
31 #include "dos_intern.h"
32 #include "include/loadseg.h"
39 } __attribute__((packed
));
41 #define BPTR2HUNK(bptr) ((struct hunk *)((void *)bptr - offsetof(struct hunk, next)))
42 #define HUNK2BPTR(hunk) MKBADDR(&hunk->next)
44 static int elf_read_block
51 struct DosLibrary
*DOSBase
54 if (ilsSeek(file
, offset
, OFFSET_BEGINNING
) < 0)
57 return read_block(file
, buffer
, size
, funcarray
, DOSBase
);
60 static void *load_block
66 struct DosLibrary
*DOSBase
69 D(bug("[ELF Loader] Load Block\n"));
70 D(bug("[ELF Loader] (size=%d)\n",size
));
71 D(bug("[ELF Loader] (funcarray=0x%x)\n",funcarray
));
72 D(bug("[ELF Loader] (funcarray[1]=0x%x)\n",funcarray
[1]));
73 void *block
= ilsAllocMem(size
, MEMF_ANY
);
76 if (!elf_read_block(file
, offset
, block
, size
, funcarray
, DOSBase
))
79 ilsFreeMem(block
, size
);
82 SetIoErr(ERROR_NO_FREE_STORE
);
87 static ULONG
read_shnum(BPTR file
, struct elfheader
*eh
, SIPTR
*funcarray
, struct DosLibrary
*DOSBase
)
89 ULONG shnum
= eh
->shnum
;
91 /* the ELF header only uses 16 bits to store the count of section headers,
92 * so it can't handle more than 65535 headers. if the count is 0, and an
93 * offset is defined, then the real count can be found in the first
94 * section header (which always exists).
96 * similarly, if the string table index is SHN_XINDEX, then the actual
97 * index is found in the first section header also.
99 * see the System V ABI 2001-04-24 draft for more details.
105 if (eh
->shoff
== 0) {
106 D(bug("[ELF Loader] No section header\n"));
107 SetIoErr(ERROR_NOT_EXECUTABLE
);
111 if (elf_read_block(file
, eh
->shoff
, &sh
, sizeof(sh
), funcarray
, DOSBase
))
114 /* wider section header count is in the size field */
117 /* sanity, if they're still invalid then this isn't elf */
119 D(bug("[ELF Loader] Empty section header\n"));
120 SetIoErr(ERROR_NOT_EXECUTABLE
);
127 static int load_header(BPTR file
, struct elfheader
*eh
, SIPTR
*funcarray
, struct DosLibrary
*DOSBase
)
129 if (elf_read_block(file
, 0, eh
, sizeof(struct elfheader
), funcarray
, DOSBase
))
132 if (eh
->ident
[0] != 0x7f || eh
->ident
[1] != 'E' ||
133 eh
->ident
[2] != 'L' || eh
->ident
[3] != 'F') {
134 D(bug("[ELF Loader] Not an ELF object\n"));
135 SetIoErr(ERROR_NOT_EXECUTABLE
);
138 D(bug("[ELF Loader] ELF object\n"));
140 /* WANT_CLASS should be defined for your target */
141 if (eh
->ident
[EI_CLASS
] != AROS_ELF_CLASS
||
142 eh
->ident
[EI_VERSION
] != EV_CURRENT
||
143 eh
->type
!= ET_REL
||
144 eh
->ident
[EI_DATA
] != AROS_ELF_DATA
||
145 eh
->machine
!= AROS_ELF_MACHINE
)
147 D(bug("[ELF Loader] Object is of wrong type\n"));
148 D(bug("[ELF Loader] EI_CLASS is %d - should be %d\n", eh
->ident
[EI_CLASS
] , AROS_ELF_CLASS
));
149 D(bug("[ELF Loader] EI_VERSION is %d - should be %d\n", eh
->ident
[EI_VERSION
], EV_CURRENT
));
150 D(bug("[ELF Loader] type is %d - should be %d\n", eh
->type
, ET_REL
));
151 D(bug("[ELF Loader] EI_DATA is %d - should be %d\n", eh
->ident
[EI_DATA
] , AROS_ELF_DATA
));
152 D(bug("[ELF Loader] machine is %d - should be %d\n", eh
->machine
, AROS_ELF_MACHINE
));
154 SetIoErr(ERROR_NOT_EXECUTABLE
);
164 BPTR
**next_hunk_ptr
,
169 struct DosLibrary
*DOSBase
179 /* The size of the hunk is the size of the section, plus
180 the size of the hunk structure, plus the size of the alignment (if necessary)*/
181 hunk_size
= sh
->size
+ sizeof(struct hunk
);
185 hunk_size
+= sh
->addralign
;
187 /* Also create space for a trampoline, if necessary */
188 if (sh
->flags
& SHF_EXECINSTR
)
189 hunk_size
+= sizeof(struct FullJumpVec
);
193 CONST_STRPTR nameext
;
195 nameext
= strrchr(strtab
+ sh
->name
, '.');
197 if (strcmp(nameext
, ".MEMF_CHIP")==0) {
198 memflags
|= MEMF_CHIP
;
199 } else if (strcmp(nameext
, ".MEMF_LOCAL")==0) {
200 memflags
|= MEMF_LOCAL
;
201 } else if (strcmp(nameext
, ".MEMF_KICK")==0) {
202 memflags
|= MEMF_KICK
;
203 } else if (strcmp(nameext
, ".MEMF_FAST")==0) {
204 memflags
|= MEMF_FAST
;
205 } else if (strcmp(nameext
, ".MEMF_PUBLIC")==0) {
206 memflags
|= MEMF_PUBLIC
;
211 hunk
= ilsAllocMem(hunk_size
, memflags
| MEMF_PUBLIC
| (sh
->type
== SHT_NOBITS
? MEMF_CLEAR
: 0));
215 hunk
->size
= hunk_size
;
217 /* In case we are required to honour alignment, and If this section contains
218 executable code, create a trampoline to its beginning, so that even if the
219 alignment requirements make the actual code go much after the end of the
220 hunk structure, the code can still be reached in the usual way. */
223 if (sh
->flags
& SHF_EXECINSTR
)
225 sh
->addr
= (char *)AROS_ROUNDUP2
227 (IPTR
)hunk
->data
+ sizeof(struct FullJumpVec
), sh
->addralign
229 __AROS_SET_FULLJMP((struct FullJumpVec
*)hunk
->data
, sh
->addr
);
232 sh
->addr
= (char *)AROS_ROUNDUP2((IPTR
)hunk
->data
, sh
->addralign
);
235 sh
->addr
= hunk
->data
;
237 /* Link the previous one with the new one */
238 BPTR2HUNK(*next_hunk_ptr
)->next
= HUNK2BPTR(hunk
);
240 D(bug("[dos] hunk @ %p, size=%08x, addr @ %p\n", hunk
, hunk
->size
, sh
->addr
));
242 /* Update the pointer to the previous one, which is now the current one */
243 *next_hunk_ptr
= &hunk
->next
;
245 if (sh
->type
!= SHT_NOBITS
)
246 return !elf_read_block(file
, sh
->offset
, sh
->addr
, sh
->size
, funcarray
, DOSBase
);
252 SetIoErr(ERROR_NO_FREE_STORE
);
259 struct elfheader
*eh
,
262 struct sheader
*symtab_shndx
,
263 struct DosLibrary
*DOSBase
266 struct sheader
*shrel
= &sh
[shrel_idx
];
267 struct sheader
*shsymtab
= &sh
[SHINDEX(shrel
->link
)];
268 struct sheader
*toreloc
= &sh
[SHINDEX(shrel
->info
)];
270 struct symbol
*symtab
= (struct symbol
*)shsymtab
->addr
;
271 struct relo
*rel
= (struct relo
*)shrel
->addr
;
274 * Ignore relocs if the target section has no allocation. that can happen
275 * eg. with a .debug PROGBITS and a .rel.debug section
277 if (!(toreloc
->flags
& SHF_ALLOC
))
280 ULONG numrel
= shrel
->size
/ shrel
->entsize
;
283 for (i
=0; i
<numrel
; i
++, rel
++)
292 * R_ARM_V4BX are actually special marks for the linker.
293 * They even never have a target (shindex == SHN_UNDEF),
294 * so we simply ignore them before doing any checks.
296 if (ELF_R_TYPE(rel
->info
) == R_ARM_V4BX
)
300 sym
= &symtab
[ELF_R_SYM(rel
->info
)];
301 p
= toreloc
->addr
+ rel
->offset
;
303 if (sym
->shindex
!= SHN_XINDEX
)
304 shindex
= sym
->shindex
;
307 if (symtab_shndx
== NULL
) {
308 D(bug("[ELF Loader] got symbol with shndx 0xfff, but there's no symtab shndx table\n"));
309 SetIoErr(ERROR_BAD_HUNK
);
312 shindex
= ((ULONG
*)symtab_shndx
->addr
)[ELF_R_SYM(rel
->info
)];
315 DB2(bug("[ELF Loader] Processing symbol %s\n", sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
));
321 D(bug("[ELF Loader] COMMON symbol '%s'\n",
322 (STRPTR
)sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
));
323 SetIoErr(ERROR_BAD_HUNK
);
332 if (ELF_R_TYPE(rel
->info
) != 0) {
333 D(bug("[ELF Loader] Undefined symbol '%s'\n",
334 (STRPTR
)sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
));
335 SetIoErr(ERROR_BAD_HUNK
);
341 s
= (IPTR
)sh
[SHINDEX(shindex
)].addr
+ sym
->value
;
344 switch (ELF_R_TYPE(rel
->info
))
346 #if defined(__i386__)
348 case R_386_32
: /* 32bit absolute */
352 case R_386_PC32
: /* 32bit PC relative */
359 #elif defined(__x86_64__)
360 case R_X86_64_64
: /* 64bit direct/absolute */
361 *(UQUAD
*)p
= s
+ rel
->addend
;
364 case R_X86_64_PC32
: /* PC relative 32 bit signed */
365 *(ULONG
*)p
= s
+ rel
->addend
- (IPTR
) p
;
369 *(ULONG
*)p
= (UQUAD
)s
+ (UQUAD
)rel
->addend
;
373 *(LONG
*)p
= (QUAD
)s
+ (QUAD
)rel
->addend
;
376 case R_X86_64_NONE
: /* No reloc */
379 #elif defined(__mc68000__)
382 *p
= s
+ rel
->addend
;
386 *(UWORD
*)p
= s
+ rel
->addend
;
390 *(UBYTE
*)p
= s
+ rel
->addend
;
394 *p
= s
+ rel
->addend
- (ULONG
)p
;
398 *(UWORD
*)p
= s
+ rel
->addend
- (ULONG
)p
;
402 *(UBYTE
*)p
= s
+ rel
->addend
- (ULONG
)p
;
408 #elif defined(__ppc__) || defined(__powerpc__)
411 *p
= s
+ rel
->addend
;
414 case R_PPC_ADDR16_LO
:
416 unsigned short *c
= (unsigned short *) p
;
417 *c
= (s
+ rel
->addend
) & 0xffff;
421 case R_PPC_ADDR16_HA
:
423 unsigned short *c
= (unsigned short *) p
;
424 ULONG temp
= s
+ rel
->addend
;
426 if ((temp
& 0x8000) != 0)
433 unsigned short *c
= (unsigned short *) p
;
434 *c
= (s
+ rel
->addend
- (ULONG
) p
) & 0xffff;
440 unsigned short *c
= (unsigned short *) p
;
441 ULONG temp
= s
+ rel
->addend
- (ULONG
) p
;
443 if ((temp
& 0x8000) != 0)
450 *p
|= (s
+ rel
->addend
- (ULONG
) p
) & 0x3fffffc;
454 *p
= s
+ rel
->addend
- (ULONG
) p
;
460 #elif defined(__arm__)
466 /* On ARM the 24 bit offset is shifted by 2 to the right */
467 signed long offset
= (*p
& 0x00ffffff) << 2;
468 /* If highest bit set, make offset negative */
469 if (offset
& 0x02000000)
470 offset
-= 0x04000000;
472 if (offset
>= 0x02000000 ||
473 offset
<= -0x02000000)
475 bug("[ELF Loader] Relocation type %d %d out of range!\n", i
, ELF_R_TYPE(rel
->info
));
476 SetIoErr(ERROR_BAD_HUNK
);
479 offset
+= s
- (ULONG
)p
;
483 *p
|= offset
& 0x00ffffff;
488 case R_ARM_THM_JUMP24
:
490 ULONG upper
,lower
,sign
,j1
,j2
;
493 upper
= *((UWORD
*)p
);
494 lower
= *((UWORD
*)p
+1);
496 sign
= (upper
>> 10) & 1;
497 j1
= (lower
>> 13) & 1;
498 j2
= (lower
>> 11) & 1;
500 offset
= (sign
<< 24) | ((~(j1
^ sign
) & 1) << 23) |
501 ((~(j2
^ sign
) & 1) << 22) |
502 ((upper
& 0x03ff) << 12) |
503 ((lower
& 0x07ff) << 1);
505 if (offset
& 0x01000000)
506 offset
-= 0x02000000;
508 if (offset
>= 0x01000000 ||
509 offset
<= -0x01000000)
511 bug("[ELF Loader] Relocation type %d %d out of range!\n", i
, ELF_R_TYPE(rel
->info
));
512 SetIoErr(ERROR_BAD_HUNK
);
515 offset
+= s
- (ULONG
)p
;
517 sign
= (offset
>> 24) & 1;
518 j1
= sign
^ (~(offset
>> 23) & 1);
519 j2
= sign
^ (~(offset
>> 22) & 1);
521 *(UWORD
*)p
= (UWORD
)((upper
& 0xf800) | (sign
<< 10) |
522 ((offset
>> 12) & 0x03ff));
523 *((UWORD
*)p
+ 1) = (UWORD
)((lower
& 0xd000) |
524 (j1
<< 13) | (j2
<< 11) | ((offset
>> 1) & 0x07ff));
529 case R_ARM_THM_MOVW_ABS_NC
:
530 case R_ARM_THM_MOVT_ABS
:
535 upper
= *((UWORD
*)p
);
536 lower
= *((UWORD
*)p
+1);
538 offset
= ((upper
& 0x000f) << 12) |
539 ((upper
& 0x0400) << 1) |
540 ((lower
& 0x7000) >> 4) |
543 offset
= (offset
^ 0x8000) - 0x8000;
547 if (ELF_R_TYPE(rel
->info
) == R_ARM_THM_MOVT_ABS
)
550 *(UWORD
*)p
= (UWORD
)((upper
& 0xfbf0) |
551 ((offset
& 0xf000) >> 12) |
552 ((offset
& 0x0800) >> 1));
553 *((UWORD
*)p
+ 1) = (UWORD
)((lower
& 0x8f00) |
554 ((offset
& 0x0700)<< 4) |
559 case R_ARM_MOVW_ABS_NC
:
562 signed long offset
= *p
;
563 offset
= ((offset
& 0xf0000) >> 4) | (offset
& 0xfff);
564 offset
= (offset
^ 0x8000) - 0x8000;
568 if (ELF_R_TYPE(rel
->info
) == R_ARM_MOVT_ABS
)
572 *p
|= ((offset
& 0xf000) << 4) | (offset
& 0x0fff);
584 # error Your architecture is not supported
588 D(bug("[ELF Loader] Unrecognized relocation type %d %d\n", i
, ELF_R_TYPE(rel
->info
)));
589 SetIoErr(ERROR_BAD_HUNK
);
600 * On ARM < v6 all LONG accesses must be LONG-aligned
601 * TODO: This is useful and can be moved to some public include file.
603 #if (__ARM_ARCH__ > 5)
605 #define READLONG_UNALIGNED(src) src
609 static inline ULONG
readlong_unaligned(ULONG
*src
)
614 "ldrb %0, [%2, #0]\n\t"
615 "ldrb %1, [%2, #1]\n\t"
616 "orr %0, %0, %1, lsl #8\n\t"
617 "ldrb %1, [%2, #2]\n\t"
618 "orr %0, %0, %1, lsl #16\n\t"
619 "ldrb %1, [%2, #3]\n\t"
620 "orr %0, %0, %1, lsl #24"
621 :"=&r"(res
), "=&r"(tmp
) : "r"(src
)
627 #define READLONG_UNALIGNED(src) readlong_unaligned(&src);
631 * This code parses special .ARM.Attributes section and
632 * extracts system requirements from it. Things like float ABI,
633 * minimum CPU and FPU version are described there.
636 static UBYTE arm_cpus
[] =
646 CPUFAMILY_ARM_6
, /* 6KZ */
647 CPUFAMILY_ARM_6
, /* 6T2 */
648 CPUFAMILY_ARM_6
, /* 6K */
650 CPUFAMILY_ARM_6
, /* 6-M */
651 CPUFAMILY_ARM_6
, /* 6S-M */
652 CPUFAMILY_ARM_7
/* 7E-M */
655 static BOOL
ARM_ParseAttrs(UBYTE
*data
, ULONG len
, struct DosLibrary
*DOSBase
)
657 struct attrs_section
*attrs
;
659 if (data
[0] != ATTR_VERSION_CURRENT
)
661 DATTR(bug("[ELF.ARM] Unknown attributes version: 0x%02\n", data
[0]));
665 attrs
= (void *)data
+ 1;
668 ULONG attrs_size
= READLONG_UNALIGNED(attrs
->size
);
670 if (!strcmp(attrs
->vendor
, "aeabi"))
672 struct attrs_subsection
*aeabi_attrs
= (void *)attrs
->vendor
+ 6;
673 ULONG aeabi_len
= attrs_size
- 10;
675 DATTR(bug("[ELF.ARM] Found aeabi attributes @ 0x%p (length %u)\n", aeabi_attrs
, aeabi_len
));
677 while (aeabi_len
> 0)
679 ULONG aeabi_attrs_size
= READLONG_UNALIGNED(aeabi_attrs
->size
);
681 if (aeabi_attrs
->tag
== Tag_File
)
683 UBYTE
*file_subsection
= (void *)aeabi_attrs
+ sizeof(struct attrs_subsection
);
684 UBYTE file_len
= aeabi_attrs_size
- sizeof(struct attrs_subsection
);
686 DATTR(bug("[ELF.ARM] Found file-wide attributes @ 0x%p (length %u)\n", file_subsection
, file_len
));
693 tag
= *file_subsection
++;
698 DATTR(bug("[ELF.ARM] Mailformed attribute tag %d (no data)\n", tag
));
704 case Tag_CPU_raw_name
:
706 case Tag_compatibility
:
707 case Tag_also_compatible_with
:
708 case Tag_conformance
:
709 /* These two are NULL-terminated strings. Just skip. */
713 if (*file_subsection
++ == 0)
719 /* Read ULEB128 value */
725 byte
= *file_subsection
++;
728 val
|= (byte
& 0x7F) << shift
;
739 DATTR(bug("[ELF.ARM] ARM CPU architecture set to %d\n", val
));
741 if (val
> ELF_CPU_ARMv7EM
)
743 DATTR(bug("[ELF.ARM] Unknown CPU tag value (%d)\n", val
));
747 if (arm_cpus
[val
] > IDosBase(DOSBase
)->arm_Arch
)
749 DATTR(bug("[ELF.ARM] CPU Requirements too high (system %d, file %d)\n", IDosBase(DOSBase
)->arm_Arch
, arm_cpus
[val
]));
755 DATTR(bug("[ELF.ARM] ARM FPU architecture set to %d\n", val
));
764 if (!IDosBase(DOSBase
)->arm_VFP
)
766 DATTR(bug("[ELF.ARM] VFP required but missing\n"));
772 case ELF_FP_v3_Short
:
773 if (!IDosBase(DOSBase
)->arm_VFP_v3
)
775 DATTR(bug("[ELF.ARM] VFPv3 required but missing\n"));
781 /* This includes VFPv4 for now */
782 DATTR(bug("[ELF.ARM] VFP %d required -- unsupported\n", val
));
790 /* We allow to execute only files which contain attributes section */
793 aeabi_attrs
= (void *)aeabi_attrs
+ aeabi_attrs_size
;
794 aeabi_len
-= aeabi_attrs_size
;
799 attrs
= (void *)attrs
+ attrs_size
;
807 BPTR InternalLoadSeg_ELF
812 LONG
*stack __unused
,
813 struct DosLibrary
*DOSBase
818 struct sheader
*symtab_shndx
= NULL
;
819 struct sheader
*strtab
= NULL
;
821 BPTR
*next_hunk_ptr
= &hunks
;
823 BOOL exec_hunk_seen
= FALSE
;
826 /* load and validate ELF header */
827 if (!load_header(file
, &eh
, funcarray
, DOSBase
))
830 int_shnum
= read_shnum(file
, &eh
, funcarray
, DOSBase
);
834 /* load section headers */
835 if (!(sh
= load_block(file
, eh
.shoff
, int_shnum
* eh
.shentsize
, funcarray
, DOSBase
)))
839 for (i
= 0; i
< int_shnum
; i
++)
841 if (sh
[i
].type
== SHT_ARM_ATTRIBUTES
)
843 ULONG len
= sh
[i
].size
;
844 UBYTE
*data
= load_block(file
, sh
[i
].offset
, len
, funcarray
, DOSBase
);
848 BOOL res
= ARM_ParseAttrs(data
, len
, DOSBase
);
850 ilsFreeMem(data
, len
);
854 D(bug("[ELF Loader] Can't parse ARM attributes\n"));
855 SetIoErr(ERROR_NOT_EXECUTABLE
);
863 /* Iterate over the section headers in order to do some stuff... */
864 for (i
= 0; i
< int_shnum
; i
++)
867 Load the symbol and string table(s).
869 NOTICE: the ELF standard, at the moment (Nov 2002) explicitely states
870 that only one symbol table per file is allowed. However, it
871 also states that this may change in future... we already handle it.
873 if (sh
[i
].type
== SHT_SYMTAB
|| sh
[i
].type
== SHT_STRTAB
|| sh
[i
].type
== SHT_SYMTAB_SHNDX
)
875 sh
[i
].addr
= load_block(file
, sh
[i
].offset
, sh
[i
].size
, funcarray
, DOSBase
);
879 if (sh
[i
].type
== SHT_STRTAB
) {
880 if (strtab
== NULL
) {
883 D(bug("[ELF Loader] file contains multiple strtab tables. only using the first one\n"));
887 if (sh
[i
].type
== SHT_SYMTAB_SHNDX
) {
888 if (symtab_shndx
== NULL
)
889 symtab_shndx
= &sh
[i
];
891 D(bug("[ELF Loader] file contains multiple symtab shndx tables. only using the first one\n"));
896 /* Now that we have the string and symbol tables loaded,
897 * load the rest of the hunks.
899 for (i
= 0; i
< int_shnum
; i
++)
901 /* Skip the already loaded hunks */
902 if (sh
[i
].type
== SHT_SYMTAB
|| sh
[i
].type
== SHT_STRTAB
|| sh
[i
].type
== SHT_SYMTAB_SHNDX
)
905 /* Load the section in memory if needed, and make a hunk out of it */
906 if (sh
[i
].flags
& SHF_ALLOC
)
910 /* Only allow alignment if this is an executable hunk
911 or if an executable hunk has been loaded already,
912 so to avoid the situation in which a data hunk has its
913 content displaced from the hunk's header in case it's the
914 first hunk (this happens with Keymaps, for instance). */
915 if (sh
[i
].flags
& SHF_EXECINSTR
)
916 exec_hunk_seen
= TRUE
;
918 if (!load_hunk(file
, &next_hunk_ptr
, &sh
[i
], strtab
? strtab
->addr
: NULL
, funcarray
, exec_hunk_seen
, DOSBase
))
924 /* Relocate the sections */
925 for (i
= 0; i
< int_shnum
; i
++)
927 /* Does this relocation section refer to a hunk? If so, addr must be != 0 */
928 if ((sh
[i
].type
== AROS_ELF_REL
) && sh
[SHINDEX(sh
[i
].info
)].addr
)
930 sh
[i
].addr
= load_block(file
, sh
[i
].offset
, sh
[i
].size
, funcarray
, DOSBase
);
931 if (!sh
[i
].addr
|| !relocate(&eh
, sh
, i
, symtab_shndx
, DOSBase
))
934 ilsFreeMem(sh
[i
].addr
, sh
[i
].size
);
939 /* Everything is loaded now. Register the module at kernel.resource */
940 register_elf(file
, hunks
, &eh
, sh
, DOSBase
);
945 /* There were some errors, deallocate The hunks */
947 InternalUnLoadSeg(hunks
, (VOID_FUNC
)funcarray
[2]);
953 * Clear the caches to let the CPU see the new data and instructions.
954 * We check for SysBase's lib_Version, since this code is also built
955 * as linklib for AmigaOS version of AROS bootstrap, and it can be
956 * running on AOS 1.3 or lower.
958 if (SysBase
->LibNode
.lib_Version
>= 36)
964 struct hunk
*hunk
= BPTR2HUNK(BADDR(curr
));
966 CacheClearE(hunk
->data
, hunk
->size
, CACRF_ClearD
| CACRF_ClearI
);
972 /* deallocate the symbol tables */
973 for (i
= 0; i
< int_shnum
; i
++)
975 if (((sh
[i
].type
== SHT_SYMTAB
) || (sh
[i
].type
== SHT_STRTAB
)) && (sh
[i
].addr
!= NULL
))
976 ilsFreeMem(sh
[i
].addr
, sh
[i
].size
);
979 /* Free the section headers */
980 ilsFreeMem(sh
, int_shnum
* eh
.shentsize
);