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 #ifndef NO_SYSBASE_REMAP
284 struct symbol
*SysBase_sym
= NULL
;
287 for (i
=0; i
<numrel
; i
++, rel
++)
296 * R_ARM_V4BX are actually special marks for the linker.
297 * They even never have a target (shindex == SHN_UNDEF),
298 * so we simply ignore them before doing any checks.
300 if (ELF_R_TYPE(rel
->info
) == R_ARM_V4BX
)
304 sym
= &symtab
[ELF_R_SYM(rel
->info
)];
305 p
= toreloc
->addr
+ rel
->offset
;
307 if (sym
->shindex
!= SHN_XINDEX
)
308 shindex
= sym
->shindex
;
311 if (symtab_shndx
== NULL
) {
312 D(bug("[ELF Loader] got symbol with shndx 0xfff, but there's no symtab shndx table\n"));
313 SetIoErr(ERROR_BAD_HUNK
);
316 shindex
= ((ULONG
*)symtab_shndx
->addr
)[ELF_R_SYM(rel
->info
)];
319 DB2(bug("[ELF Loader] Processing symbol %s\n", sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
));
325 D(bug("[ELF Loader] COMMON symbol '%s'\n",
326 (STRPTR
)sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
));
327 SetIoErr(ERROR_BAD_HUNK
);
332 #ifdef NO_SYSBASE_REMAP
335 if (SysBase_sym
== NULL
)
337 if (strncmp((STRPTR
)sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
, "SysBase", 8) == 0)
346 if (SysBase_sym
== sym
)
348 SysBase_yes
: s
= (IPTR
)&SysBase
;
351 SysBase_no
: s
= sym
->value
;
356 if (ELF_R_TYPE(rel
->info
) != 0) {
357 D(bug("[ELF Loader] Undefined symbol '%s'\n",
358 (STRPTR
)sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
));
359 SetIoErr(ERROR_BAD_HUNK
);
365 s
= (IPTR
)sh
[SHINDEX(shindex
)].addr
+ sym
->value
;
368 switch (ELF_R_TYPE(rel
->info
))
370 #if defined(__i386__)
372 case R_386_32
: /* 32bit absolute */
376 case R_386_PC32
: /* 32bit PC relative */
383 #elif defined(__x86_64__)
384 case R_X86_64_64
: /* 64bit direct/absolute */
385 *(UQUAD
*)p
= s
+ rel
->addend
;
388 case R_X86_64_PC32
: /* PC relative 32 bit signed */
389 *(ULONG
*)p
= s
+ rel
->addend
- (IPTR
) p
;
393 *(ULONG
*)p
= (UQUAD
)s
+ (UQUAD
)rel
->addend
;
397 *(LONG
*)p
= (QUAD
)s
+ (QUAD
)rel
->addend
;
400 case R_X86_64_NONE
: /* No reloc */
403 #elif defined(__mc68000__)
406 *p
= s
+ rel
->addend
;
410 *(UWORD
*)p
= s
+ rel
->addend
;
414 *(UBYTE
*)p
= s
+ rel
->addend
;
418 *p
= s
+ rel
->addend
- (ULONG
)p
;
422 *(UWORD
*)p
= s
+ rel
->addend
- (ULONG
)p
;
426 *(UBYTE
*)p
= s
+ rel
->addend
- (ULONG
)p
;
432 #elif defined(__ppc__) || defined(__powerpc__)
435 *p
= s
+ rel
->addend
;
438 case R_PPC_ADDR16_LO
:
440 unsigned short *c
= (unsigned short *) p
;
441 *c
= (s
+ rel
->addend
) & 0xffff;
445 case R_PPC_ADDR16_HA
:
447 unsigned short *c
= (unsigned short *) p
;
448 ULONG temp
= s
+ rel
->addend
;
450 if ((temp
& 0x8000) != 0)
457 unsigned short *c
= (unsigned short *) p
;
458 *c
= (s
+ rel
->addend
- (ULONG
) p
) & 0xffff;
464 unsigned short *c
= (unsigned short *) p
;
465 ULONG temp
= s
+ rel
->addend
- (ULONG
) p
;
467 if ((temp
& 0x8000) != 0)
474 *p
|= (s
+ rel
->addend
- (ULONG
) p
) & 0x3fffffc;
478 *p
= s
+ rel
->addend
- (ULONG
) p
;
484 #elif defined(__arm__)
490 /* On ARM the 24 bit offset is shifted by 2 to the right */
491 signed long offset
= (*p
& 0x00ffffff) << 2;
492 /* If highest bit set, make offset negative */
493 if (offset
& 0x02000000)
494 offset
-= 0x04000000;
496 if (offset
>= 0x02000000 ||
497 offset
<= -0x02000000)
499 bug("[ELF Loader] Relocation type %d %d out of range!\n", i
, ELF_R_TYPE(rel
->info
));
500 SetIoErr(ERROR_BAD_HUNK
);
503 offset
+= s
- (ULONG
)p
;
507 *p
|= offset
& 0x00ffffff;
512 case R_ARM_THM_JUMP24
:
514 ULONG upper
,lower
,sign
,j1
,j2
;
517 upper
= *((UWORD
*)p
);
518 lower
= *((UWORD
*)p
+1);
520 sign
= (upper
>> 10) & 1;
521 j1
= (lower
>> 13) & 1;
522 j2
= (lower
>> 11) & 1;
524 offset
= (sign
<< 24) | ((~(j1
^ sign
) & 1) << 23) |
525 ((~(j2
^ sign
) & 1) << 22) |
526 ((upper
& 0x03ff) << 12) |
527 ((lower
& 0x07ff) << 1);
529 if (offset
& 0x01000000)
530 offset
-= 0x02000000;
532 if (offset
>= 0x01000000 ||
533 offset
<= -0x01000000)
535 bug("[ELF Loader] Relocation type %d %d out of range!\n", i
, ELF_R_TYPE(rel
->info
));
536 SetIoErr(ERROR_BAD_HUNK
);
539 offset
+= s
- (ULONG
)p
;
541 sign
= (offset
>> 24) & 1;
542 j1
= sign
^ (~(offset
>> 23) & 1);
543 j2
= sign
^ (~(offset
>> 22) & 1);
545 *(UWORD
*)p
= (UWORD
)((upper
& 0xf800) | (sign
<< 10) |
546 ((offset
>> 12) & 0x03ff));
547 *((UWORD
*)p
+ 1) = (UWORD
)((lower
& 0xd000) |
548 (j1
<< 13) | (j2
<< 11) | ((offset
>> 1) & 0x07ff));
553 case R_ARM_THM_MOVW_ABS_NC
:
554 case R_ARM_THM_MOVT_ABS
:
559 upper
= *((UWORD
*)p
);
560 lower
= *((UWORD
*)p
+1);
562 offset
= ((upper
& 0x000f) << 12) |
563 ((upper
& 0x0400) << 1) |
564 ((lower
& 0x7000) >> 4) |
567 offset
= (offset
^ 0x8000) - 0x8000;
571 if (ELF_R_TYPE(rel
->info
) == R_ARM_THM_MOVT_ABS
)
574 *(UWORD
*)p
= (UWORD
)((upper
& 0xfbf0) |
575 ((offset
& 0xf000) >> 12) |
576 ((offset
& 0x0800) >> 1));
577 *((UWORD
*)p
+ 1) = (UWORD
)((lower
& 0x8f00) |
578 ((offset
& 0x0700)<< 4) |
583 case R_ARM_MOVW_ABS_NC
:
586 signed long offset
= *p
;
587 offset
= ((offset
& 0xf0000) >> 4) | (offset
& 0xfff);
588 offset
= (offset
^ 0x8000) - 0x8000;
592 if (ELF_R_TYPE(rel
->info
) == R_ARM_MOVT_ABS
)
596 *p
|= ((offset
& 0xf000) << 4) | (offset
& 0x0fff);
608 # error Your architecture is not supported
612 D(bug("[ELF Loader] Unrecognized relocation type %d %d\n", i
, ELF_R_TYPE(rel
->info
)));
613 SetIoErr(ERROR_BAD_HUNK
);
624 * On ARM < v6 all LONG accesses must be LONG-aligned
625 * TODO: This is useful and can be moved to some public include file.
627 #if (__ARM_ARCH__ > 5)
629 #define READLONG_UNALIGNED(src) src
633 static inline ULONG
readlong_unaligned(ULONG
*src
)
638 "ldrb %0, [%2, #0]\n\t"
639 "ldrb %1, [%2, #1]\n\t"
640 "orr %0, %0, %1, lsl #8\n\t"
641 "ldrb %1, [%2, #2]\n\t"
642 "orr %0, %0, %1, lsl #16\n\t"
643 "ldrb %1, [%2, #3]\n\t"
644 "orr %0, %0, %1, lsl #24"
645 :"=&r"(res
), "=&r"(tmp
) : "r"(src
)
651 #define READLONG_UNALIGNED(src) readlong_unaligned(&src);
655 * This code parses special .ARM.Attributes section and
656 * extracts system requirements from it. Things like float ABI,
657 * minimum CPU and FPU version are described there.
660 static UBYTE arm_cpus
[] =
670 CPUFAMILY_ARM_6
, /* 6KZ */
671 CPUFAMILY_ARM_6
, /* 6T2 */
672 CPUFAMILY_ARM_6
, /* 6K */
674 CPUFAMILY_ARM_6
, /* 6-M */
675 CPUFAMILY_ARM_6
, /* 6S-M */
676 CPUFAMILY_ARM_7
/* 7E-M */
679 static BOOL
ARM_ParseAttrs(UBYTE
*data
, ULONG len
, struct DosLibrary
*DOSBase
)
681 struct attrs_section
*attrs
;
683 if (data
[0] != ATTR_VERSION_CURRENT
)
685 DATTR(bug("[ELF.ARM] Unknown attributes version: 0x%02\n", data
[0]));
689 attrs
= (void *)data
+ 1;
692 ULONG attrs_size
= READLONG_UNALIGNED(attrs
->size
);
694 if (!strcmp(attrs
->vendor
, "aeabi"))
696 struct attrs_subsection
*aeabi_attrs
= (void *)attrs
->vendor
+ 6;
697 ULONG aeabi_len
= attrs_size
- 10;
699 DATTR(bug("[ELF.ARM] Found aeabi attributes @ 0x%p (length %u)\n", aeabi_attrs
, aeabi_len
));
701 while (aeabi_len
> 0)
703 ULONG aeabi_attrs_size
= READLONG_UNALIGNED(aeabi_attrs
->size
);
705 if (aeabi_attrs
->tag
== Tag_File
)
707 UBYTE
*file_subsection
= (void *)aeabi_attrs
+ sizeof(struct attrs_subsection
);
708 UBYTE file_len
= aeabi_attrs_size
- sizeof(struct attrs_subsection
);
710 DATTR(bug("[ELF.ARM] Found file-wide attributes @ 0x%p (length %u)\n", file_subsection
, file_len
));
717 tag
= *file_subsection
++;
722 DATTR(bug("[ELF.ARM] Mailformed attribute tag %d (no data)\n", tag
));
728 case Tag_CPU_raw_name
:
730 case Tag_compatibility
:
731 case Tag_also_compatible_with
:
732 case Tag_conformance
:
733 /* These two are NULL-terminated strings. Just skip. */
737 if (*file_subsection
++ == 0)
743 /* Read ULEB128 value */
749 byte
= *file_subsection
++;
752 val
|= (byte
& 0x7F) << shift
;
763 DATTR(bug("[ELF.ARM] ARM CPU architecture set to %d\n", val
));
765 if (val
> ELF_CPU_ARMv7EM
)
767 DATTR(bug("[ELF.ARM] Unknown CPU tag value (%d)\n", val
));
771 if (arm_cpus
[val
] > IDosBase(DOSBase
)->arm_Arch
)
773 DATTR(bug("[ELF.ARM] CPU Requirements too high (system %d, file %d)\n", IDosBase(DOSBase
)->arm_Arch
, arm_cpus
[val
]));
779 DATTR(bug("[ELF.ARM] ARM FPU architecture set to %d\n", val
));
788 if (!IDosBase(DOSBase
)->arm_VFP
)
790 DATTR(bug("[ELF.ARM] VFP required but missing\n"));
796 case ELF_FP_v3_Short
:
797 if (!IDosBase(DOSBase
)->arm_VFP_v3
)
799 DATTR(bug("[ELF.ARM] VFPv3 required but missing\n"));
805 /* This includes VFPv4 for now */
806 DATTR(bug("[ELF.ARM] VFP %d required -- unsupported\n", val
));
814 /* We allow to execute only files which contain attributes section */
817 aeabi_attrs
= (void *)aeabi_attrs
+ aeabi_attrs_size
;
818 aeabi_len
-= aeabi_attrs_size
;
823 attrs
= (void *)attrs
+ attrs_size
;
831 BPTR InternalLoadSeg_ELF
836 LONG
*stack __unused
,
837 struct DosLibrary
*DOSBase
842 struct sheader
*symtab_shndx
= NULL
;
843 struct sheader
*strtab
= NULL
;
845 BPTR
*next_hunk_ptr
= &hunks
;
847 BOOL exec_hunk_seen
= FALSE
;
850 /* load and validate ELF header */
851 if (!load_header(file
, &eh
, funcarray
, DOSBase
))
854 int_shnum
= read_shnum(file
, &eh
, funcarray
, DOSBase
);
858 /* load section headers */
859 if (!(sh
= load_block(file
, eh
.shoff
, int_shnum
* eh
.shentsize
, funcarray
, DOSBase
)))
863 for (i
= 0; i
< int_shnum
; i
++)
865 if (sh
[i
].type
== SHT_ARM_ATTRIBUTES
)
867 ULONG len
= sh
[i
].size
;
868 UBYTE
*data
= load_block(file
, sh
[i
].offset
, len
, funcarray
, DOSBase
);
872 BOOL res
= ARM_ParseAttrs(data
, len
, DOSBase
);
874 ilsFreeMem(data
, len
);
878 D(bug("[ELF Loader] Can't parse ARM attributes\n"));
879 SetIoErr(ERROR_NOT_EXECUTABLE
);
887 /* Iterate over the section headers in order to do some stuff... */
888 for (i
= 0; i
< int_shnum
; i
++)
891 Load the symbol and string table(s).
893 NOTICE: the ELF standard, at the moment (Nov 2002) explicitely states
894 that only one symbol table per file is allowed. However, it
895 also states that this may change in future... we already handle it.
897 if (sh
[i
].type
== SHT_SYMTAB
|| sh
[i
].type
== SHT_STRTAB
|| sh
[i
].type
== SHT_SYMTAB_SHNDX
)
899 sh
[i
].addr
= load_block(file
, sh
[i
].offset
, sh
[i
].size
, funcarray
, DOSBase
);
903 if (sh
[i
].type
== SHT_STRTAB
) {
904 if (strtab
== NULL
) {
907 D(bug("[ELF Loader] file contains multiple strtab tables. only using the first one\n"));
911 if (sh
[i
].type
== SHT_SYMTAB_SHNDX
) {
912 if (symtab_shndx
== NULL
)
913 symtab_shndx
= &sh
[i
];
915 D(bug("[ELF Loader] file contains multiple symtab shndx tables. only using the first one\n"));
920 /* Now that we have the string and symbol tables loaded,
921 * load the rest of the hunks.
923 for (i
= 0; i
< int_shnum
; i
++)
925 /* Skip the already loaded hunks */
926 if (sh
[i
].type
== SHT_SYMTAB
|| sh
[i
].type
== SHT_STRTAB
|| sh
[i
].type
== SHT_SYMTAB_SHNDX
)
929 /* Load the section in memory if needed, and make a hunk out of it */
930 if (sh
[i
].flags
& SHF_ALLOC
)
934 /* Only allow alignment if this is an executable hunk
935 or if an executable hunk has been loaded already,
936 so to avoid the situation in which a data hunk has its
937 content displaced from the hunk's header in case it's the
938 first hunk (this happens with Keymaps, for instance). */
939 if (sh
[i
].flags
& SHF_EXECINSTR
)
940 exec_hunk_seen
= TRUE
;
942 if (!load_hunk(file
, &next_hunk_ptr
, &sh
[i
], strtab
? strtab
->addr
: NULL
, funcarray
, exec_hunk_seen
, DOSBase
))
948 /* Relocate the sections */
949 for (i
= 0; i
< int_shnum
; i
++)
951 /* Does this relocation section refer to a hunk? If so, addr must be != 0 */
952 if ((sh
[i
].type
== AROS_ELF_REL
) && sh
[SHINDEX(sh
[i
].info
)].addr
)
954 sh
[i
].addr
= load_block(file
, sh
[i
].offset
, sh
[i
].size
, funcarray
, DOSBase
);
955 if (!sh
[i
].addr
|| !relocate(&eh
, sh
, i
, symtab_shndx
, DOSBase
))
958 ilsFreeMem(sh
[i
].addr
, sh
[i
].size
);
963 /* Everything is loaded now. Register the module at kernel.resource */
964 register_elf(file
, hunks
, &eh
, sh
, DOSBase
);
969 /* There were some errors, deallocate The hunks */
971 InternalUnLoadSeg(hunks
, (VOID_FUNC
)funcarray
[2]);
977 * Clear the caches to let the CPU see the new data and instructions.
978 * We check for SysBase's lib_Version, since this code is also built
979 * as linklib for AmigaOS version of AROS bootstrap, and it can be
980 * running on AOS 1.3 or lower.
982 if (SysBase
->LibNode
.lib_Version
>= 36)
988 struct hunk
*hunk
= BPTR2HUNK(BADDR(curr
));
990 CacheClearE(hunk
->data
, hunk
->size
, CACRF_ClearD
| CACRF_ClearI
);
996 /* deallocate the symbol tables */
997 for (i
= 0; i
< int_shnum
; i
++)
999 if (((sh
[i
].type
== SHT_SYMTAB
) || (sh
[i
].type
== SHT_STRTAB
)) && (sh
[i
].addr
!= NULL
))
1000 ilsFreeMem(sh
[i
].addr
, sh
[i
].size
);
1003 /* Free the section headers */
1004 ilsFreeMem(sh
, int_shnum
* eh
.shentsize
);