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 SetIoErr(ERROR_NOT_EXECUTABLE
);
110 if (elf_read_block(file
, eh
->shoff
, &sh
, sizeof(sh
), funcarray
, DOSBase
))
113 /* wider section header count is in the size field */
116 /* sanity, if they're still invalid then this isn't elf */
118 SetIoErr(ERROR_NOT_EXECUTABLE
);
124 static int load_header(BPTR file
, struct elfheader
*eh
, SIPTR
*funcarray
, struct DosLibrary
*DOSBase
)
126 if (elf_read_block(file
, 0, eh
, sizeof(struct elfheader
), funcarray
, DOSBase
))
129 if (eh
->ident
[0] != 0x7f || eh
->ident
[1] != 'E' ||
130 eh
->ident
[2] != 'L' || eh
->ident
[3] != 'F') {
131 D(bug("[ELF Loader] Not an ELF object\n"));
132 SetIoErr(ERROR_NOT_EXECUTABLE
);
135 D(bug("[ELF Loader] ELF object\n"));
137 /* WANT_CLASS should be defined for your target */
138 if (eh
->ident
[EI_CLASS
] != AROS_ELF_CLASS
||
139 eh
->ident
[EI_VERSION
] != EV_CURRENT
||
140 eh
->type
!= ET_REL
||
141 eh
->ident
[EI_DATA
] != AROS_ELF_DATA
||
142 eh
->machine
!= AROS_ELF_MACHINE
)
144 D(bug("[ELF Loader] Object is of wrong type\n"));
145 D(bug("[ELF Loader] EI_CLASS is %d - should be %d\n", eh
->ident
[EI_CLASS
] , AROS_ELF_CLASS
));
146 D(bug("[ELF Loader] EI_VERSION is %d - should be %d\n", eh
->ident
[EI_VERSION
], EV_CURRENT
));
147 D(bug("[ELF Loader] type is %d - should be %d\n", eh
->type
, ET_REL
));
148 D(bug("[ELF Loader] EI_DATA is %d - should be %d\n", eh
->ident
[EI_DATA
] , AROS_ELF_DATA
));
149 D(bug("[ELF Loader] machine is %d - should be %d\n", eh
->machine
, AROS_ELF_MACHINE
));
151 SetIoErr(ERROR_NOT_EXECUTABLE
);
161 BPTR
**next_hunk_ptr
,
166 struct DosLibrary
*DOSBase
176 /* The size of the hunk is the size of the section, plus
177 the size of the hunk structure, plus the size of the alignment (if necessary)*/
178 hunk_size
= sh
->size
+ sizeof(struct hunk
);
182 hunk_size
+= sh
->addralign
;
184 /* Also create space for a trampoline, if necessary */
185 if (sh
->flags
& SHF_EXECINSTR
)
186 hunk_size
+= sizeof(struct FullJumpVec
);
190 CONST_STRPTR nameext
;
192 nameext
= strrchr(strtab
+ sh
->name
, '.');
194 if (strcmp(nameext
, ".MEMF_CHIP")==0) {
195 memflags
|= MEMF_CHIP
;
196 } else if (strcmp(nameext
, ".MEMF_LOCAL")==0) {
197 memflags
|= MEMF_LOCAL
;
198 } else if (strcmp(nameext
, ".MEMF_KICK")==0) {
199 memflags
|= MEMF_KICK
;
200 } else if (strcmp(nameext
, ".MEMF_FAST")==0) {
201 memflags
|= MEMF_FAST
;
202 } else if (strcmp(nameext
, ".MEMF_PUBLIC")==0) {
203 memflags
|= MEMF_PUBLIC
;
208 hunk
= ilsAllocMem(hunk_size
, memflags
| MEMF_PUBLIC
| (sh
->type
== SHT_NOBITS
? MEMF_CLEAR
: 0));
212 hunk
->size
= hunk_size
;
214 /* In case we are required to honour alignment, and If this section contains
215 executable code, create a trampoline to its beginning, so that even if the
216 alignment requirements make the actual code go much after the end of the
217 hunk structure, the code can still be reached in the usual way. */
220 if (sh
->flags
& SHF_EXECINSTR
)
222 sh
->addr
= (char *)AROS_ROUNDUP2
224 (IPTR
)hunk
->data
+ sizeof(struct FullJumpVec
), sh
->addralign
226 __AROS_SET_FULLJMP((struct FullJumpVec
*)hunk
->data
, sh
->addr
);
229 sh
->addr
= (char *)AROS_ROUNDUP2((IPTR
)hunk
->data
, sh
->addralign
);
232 sh
->addr
= hunk
->data
;
234 /* Link the previous one with the new one */
235 BPTR2HUNK(*next_hunk_ptr
)->next
= HUNK2BPTR(hunk
);
237 D(bug("[dos] hunk @ %p, size=%08x, addr @ %p\n", hunk
, hunk
->size
, sh
->addr
));
239 /* Update the pointer to the previous one, which is now the current one */
240 *next_hunk_ptr
= &hunk
->next
;
242 if (sh
->type
!= SHT_NOBITS
)
243 return !elf_read_block(file
, sh
->offset
, sh
->addr
, sh
->size
, funcarray
, DOSBase
);
249 SetIoErr(ERROR_NO_FREE_STORE
);
256 struct elfheader
*eh
,
259 struct sheader
*symtab_shndx
,
260 struct DosLibrary
*DOSBase
263 struct sheader
*shrel
= &sh
[shrel_idx
];
264 struct sheader
*shsymtab
= &sh
[SHINDEX(shrel
->link
)];
265 struct sheader
*toreloc
= &sh
[SHINDEX(shrel
->info
)];
267 struct symbol
*symtab
= (struct symbol
*)shsymtab
->addr
;
268 struct relo
*rel
= (struct relo
*)shrel
->addr
;
271 * Ignore relocs if the target section has no allocation. that can happen
272 * eg. with a .debug PROGBITS and a .rel.debug section
274 if (!(toreloc
->flags
& SHF_ALLOC
))
277 ULONG numrel
= shrel
->size
/ shrel
->entsize
;
280 #ifndef NO_SYSBASE_REMAP
281 struct symbol
*SysBase_sym
= NULL
;
284 for (i
=0; i
<numrel
; i
++, rel
++)
293 * R_ARM_V4BX are actually special marks for the linker.
294 * They even never have a target (shindex == SHN_UNDEF),
295 * so we simply ignore them before doing any checks.
297 if (ELF_R_TYPE(rel
->info
) == R_ARM_V4BX
)
301 sym
= &symtab
[ELF_R_SYM(rel
->info
)];
302 p
= toreloc
->addr
+ rel
->offset
;
304 if (sym
->shindex
!= SHN_XINDEX
)
305 shindex
= sym
->shindex
;
308 if (symtab_shndx
== NULL
) {
309 D(bug("[ELF Loader] got symbol with shndx 0xfff, but there's no symtab shndx table\n"));
310 SetIoErr(ERROR_BAD_HUNK
);
313 shindex
= ((ULONG
*)symtab_shndx
->addr
)[ELF_R_SYM(rel
->info
)];
316 DB2(bug("[ELF Loader] Processing symbol %s\n", sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
));
322 D(bug("[ELF Loader] COMMON symbol '%s'\n",
323 (STRPTR
)sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
));
324 SetIoErr(ERROR_BAD_HUNK
);
329 #ifdef NO_SYSBASE_REMAP
332 if (SysBase_sym
== NULL
)
334 if (strncmp((STRPTR
)sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
, "SysBase", 8) == 0)
343 if (SysBase_sym
== sym
)
345 SysBase_yes
: s
= (IPTR
)&SysBase
;
348 SysBase_no
: s
= sym
->value
;
353 if (ELF_R_TYPE(rel
->info
) != 0) {
354 D(bug("[ELF Loader] Undefined symbol '%s'\n",
355 (STRPTR
)sh
[SHINDEX(shsymtab
->link
)].addr
+ sym
->name
));
356 SetIoErr(ERROR_BAD_HUNK
);
362 s
= (IPTR
)sh
[SHINDEX(shindex
)].addr
+ sym
->value
;
365 switch (ELF_R_TYPE(rel
->info
))
367 #if defined(__i386__)
369 case R_386_32
: /* 32bit absolute */
373 case R_386_PC32
: /* 32bit PC relative */
380 #elif defined(__x86_64__)
381 case R_X86_64_64
: /* 64bit direct/absolute */
382 *(UQUAD
*)p
= s
+ rel
->addend
;
385 case R_X86_64_PC32
: /* PC relative 32 bit signed */
386 *(ULONG
*)p
= s
+ rel
->addend
- (IPTR
) p
;
390 *(ULONG
*)p
= (UQUAD
)s
+ (UQUAD
)rel
->addend
;
394 *(LONG
*)p
= (QUAD
)s
+ (QUAD
)rel
->addend
;
397 case R_X86_64_NONE
: /* No reloc */
400 #elif defined(__mc68000__)
403 *p
= s
+ rel
->addend
;
407 *(UWORD
*)p
= s
+ rel
->addend
;
411 *(UBYTE
*)p
= s
+ rel
->addend
;
415 *p
= s
+ rel
->addend
- (ULONG
)p
;
419 *(UWORD
*)p
= s
+ rel
->addend
- (ULONG
)p
;
423 *(UBYTE
*)p
= s
+ rel
->addend
- (ULONG
)p
;
429 #elif defined(__ppc__) || defined(__powerpc__)
432 *p
= s
+ rel
->addend
;
435 case R_PPC_ADDR16_LO
:
437 unsigned short *c
= (unsigned short *) p
;
438 *c
= (s
+ rel
->addend
) & 0xffff;
442 case R_PPC_ADDR16_HA
:
444 unsigned short *c
= (unsigned short *) p
;
445 ULONG temp
= s
+ rel
->addend
;
447 if ((temp
& 0x8000) != 0)
454 unsigned short *c
= (unsigned short *) p
;
455 *c
= (s
+ rel
->addend
- (ULONG
) p
) & 0xffff;
461 unsigned short *c
= (unsigned short *) p
;
462 ULONG temp
= s
+ rel
->addend
- (ULONG
) p
;
464 if ((temp
& 0x8000) != 0)
471 *p
|= (s
+ rel
->addend
- (ULONG
) p
) & 0x3fffffc;
475 *p
= s
+ rel
->addend
- (ULONG
) p
;
481 #elif defined(__arm__)
487 /* On ARM the 24 bit offset is shifted by 2 to the right */
488 signed long offset
= (*p
& 0x00ffffff) << 2;
489 /* If highest bit set, make offset negative */
490 if (offset
& 0x02000000)
491 offset
-= 0x04000000;
493 if (offset
>= 0x02000000 ||
494 offset
<= -0x02000000)
496 bug("[ELF Loader] Relocation type %d %d out of range!\n", i
, ELF_R_TYPE(rel
->info
));
497 SetIoErr(ERROR_BAD_HUNK
);
500 offset
+= s
- (ULONG
)p
;
504 *p
|= offset
& 0x00ffffff;
509 case R_ARM_THM_JUMP24
:
511 ULONG upper
,lower
,sign
,j1
,j2
;
514 upper
= *((UWORD
*)p
);
515 lower
= *((UWORD
*)p
+1);
517 sign
= (upper
>> 10) & 1;
518 j1
= (lower
>> 13) & 1;
519 j2
= (lower
>> 11) & 1;
521 offset
= (sign
<< 24) | ((~(j1
^ sign
) & 1) << 23) |
522 ((~(j2
^ sign
) & 1) << 22) |
523 ((upper
& 0x03ff) << 12) |
524 ((lower
& 0x07ff) << 1);
526 if (offset
& 0x01000000)
527 offset
-= 0x02000000;
529 if (offset
>= 0x01000000 ||
530 offset
<= -0x01000000)
532 bug("[ELF Loader] Relocation type %d %d out of range!\n", i
, ELF_R_TYPE(rel
->info
));
533 SetIoErr(ERROR_BAD_HUNK
);
536 offset
+= s
- (ULONG
)p
;
538 sign
= (offset
>> 24) & 1;
539 j1
= sign
^ (~(offset
>> 23) & 1);
540 j2
= sign
^ (~(offset
>> 22) & 1);
542 *(UWORD
*)p
= (UWORD
)((upper
& 0xf800) | (sign
<< 10) |
543 ((offset
>> 12) & 0x03ff));
544 *((UWORD
*)p
+ 1) = (UWORD
)((lower
& 0xd000) |
545 (j1
<< 13) | (j2
<< 11) | ((offset
>> 1) & 0x07ff));
550 case R_ARM_THM_MOVW_ABS_NC
:
551 case R_ARM_THM_MOVT_ABS
:
556 upper
= *((UWORD
*)p
);
557 lower
= *((UWORD
*)p
+1);
559 offset
= ((upper
& 0x000f) << 12) |
560 ((upper
& 0x0400) << 1) |
561 ((lower
& 0x7000) >> 4) |
564 offset
= (offset
^ 0x8000) - 0x8000;
568 if (ELF_R_TYPE(rel
->info
) == R_ARM_THM_MOVT_ABS
)
571 *(UWORD
*)p
= (UWORD
)((upper
& 0xfbf0) |
572 ((offset
& 0xf000) >> 12) |
573 ((offset
& 0x0800) >> 1));
574 *((UWORD
*)p
+ 1) = (UWORD
)((lower
& 0x8f00) |
575 ((offset
& 0x0700)<< 4) |
580 case R_ARM_MOVW_ABS_NC
:
583 signed long offset
= *p
;
584 offset
= ((offset
& 0xf0000) >> 4) | (offset
& 0xfff);
585 offset
= (offset
^ 0x8000) - 0x8000;
589 if (ELF_R_TYPE(rel
->info
) == R_ARM_MOVT_ABS
)
593 *p
|= ((offset
& 0xf000) << 4) | (offset
& 0x0fff);
605 # error Your architecture is not supported
609 D(bug("[ELF Loader] Unrecognized relocation type %d %d\n", i
, ELF_R_TYPE(rel
->info
)));
610 SetIoErr(ERROR_BAD_HUNK
);
621 * On ARM < v6 all LONG accesses must be LONG-aligned
622 * TODO: This is useful and can be moved to some public include file.
624 #if (__ARM_ARCH__ > 5)
626 #define READLONG_UNALIGNED(src) src
630 static inline ULONG
readlong_unaligned(ULONG
*src
)
635 "ldrb %0, [%2, #0]\n\t"
636 "ldrb %1, [%2, #1]\n\t"
637 "orr %0, %0, %1, lsl #8\n\t"
638 "ldrb %1, [%2, #2]\n\t"
639 "orr %0, %0, %1, lsl #16\n\t"
640 "ldrb %1, [%2, #3]\n\t"
641 "orr %0, %0, %1, lsl #24"
642 :"=&r"(res
), "=&r"(tmp
) : "r"(src
)
648 #define READLONG_UNALIGNED(src) readlong_unaligned(&src);
652 * This code parses special .ARM.Attributes section and
653 * extracts system requirements from it. Things like float ABI,
654 * minimum CPU and FPU version are described there.
657 static UBYTE arm_cpus
[] =
667 CPUFAMILY_ARM_6
, /* 6KZ */
668 CPUFAMILY_ARM_6
, /* 6T2 */
669 CPUFAMILY_ARM_6
, /* 6K */
671 CPUFAMILY_ARM_6
, /* 6-M */
672 CPUFAMILY_ARM_6
, /* 6S-M */
673 CPUFAMILY_ARM_7
/* 7E-M */
676 static BOOL
ARM_ParseAttrs(UBYTE
*data
, ULONG len
, struct DosLibrary
*DOSBase
)
678 struct attrs_section
*attrs
;
680 if (data
[0] != ATTR_VERSION_CURRENT
)
682 DATTR(bug("[ELF.ARM] Unknown attributes version: 0x%02\n", data
[0]));
686 attrs
= (void *)data
+ 1;
689 ULONG attrs_size
= READLONG_UNALIGNED(attrs
->size
);
691 if (!strcmp(attrs
->vendor
, "aeabi"))
693 struct attrs_subsection
*aeabi_attrs
= (void *)attrs
->vendor
+ 6;
694 ULONG aeabi_len
= attrs_size
- 10;
696 DATTR(bug("[ELF.ARM] Found aeabi attributes @ 0x%p (length %u)\n", aeabi_attrs
, aeabi_len
));
698 while (aeabi_len
> 0)
700 ULONG aeabi_attrs_size
= READLONG_UNALIGNED(aeabi_attrs
->size
);
702 if (aeabi_attrs
->tag
== Tag_File
)
704 UBYTE
*file_subsection
= (void *)aeabi_attrs
+ sizeof(struct attrs_subsection
);
705 UBYTE file_len
= aeabi_attrs_size
- sizeof(struct attrs_subsection
);
707 DATTR(bug("[ELF.ARM] Found file-wide attributes @ 0x%p (length %u)\n", file_subsection
, file_len
));
714 tag
= *file_subsection
++;
719 DATTR(bug("[ELF.ARM] Mailformed attribute tag %d (no data)\n", tag
));
725 case Tag_CPU_raw_name
:
727 case Tag_compatibility
:
728 case Tag_also_compatible_with
:
729 case Tag_conformance
:
730 /* These two are NULL-terminated strings. Just skip. */
734 if (*file_subsection
++ == 0)
740 /* Read ULEB128 value */
746 byte
= *file_subsection
++;
749 val
|= (byte
& 0x7F) << shift
;
760 DATTR(bug("[ELF.ARM] ARM CPU architecture set to %d\n", val
));
762 if (val
> ELF_CPU_ARMv7EM
)
764 DATTR(bug("[ELF.ARM] Unknown CPU tag value (%d)\n", val
));
768 if (arm_cpus
[val
] > IDosBase(DOSBase
)->arm_Arch
)
770 DATTR(bug("[ELF.ARM] CPU Requirements too high (system %d, file %d)\n", IDosBase(DOSBase
)->arm_Arch
, arm_cpus
[val
]));
776 DATTR(bug("[ELF.ARM] ARM FPU architecture set to %d\n", val
));
785 if (!IDosBase(DOSBase
)->arm_VFP
)
787 DATTR(bug("[ELF.ARM] VFP required but missing\n"));
793 case ELF_FP_v3_Short
:
794 if (!IDosBase(DOSBase
)->arm_VFP_v3
)
796 DATTR(bug("[ELF.ARM] VFPv3 required but missing\n"));
802 /* This includes VFPv4 for now */
803 DATTR(bug("[ELF.ARM] VFP %d required -- unsupported\n", val
));
811 /* We allow to execute only files which contain attributes section */
814 aeabi_attrs
= (void *)aeabi_attrs
+ aeabi_attrs_size
;
815 aeabi_len
-= aeabi_attrs_size
;
820 attrs
= (void *)attrs
+ attrs_size
;
828 BPTR InternalLoadSeg_ELF
833 LONG
*stack __unused
,
834 struct DosLibrary
*DOSBase
839 struct sheader
*symtab_shndx
= NULL
;
840 struct sheader
*strtab
= NULL
;
842 BPTR
*next_hunk_ptr
= &hunks
;
844 BOOL exec_hunk_seen
= FALSE
;
847 /* load and validate ELF header */
848 if (!load_header(file
, &eh
, funcarray
, DOSBase
))
851 int_shnum
= read_shnum(file
, &eh
, funcarray
, DOSBase
);
855 /* load section headers */
856 if (!(sh
= load_block(file
, eh
.shoff
, int_shnum
* eh
.shentsize
, funcarray
, DOSBase
)))
860 for (i
= 0; i
< int_shnum
; i
++)
862 if (sh
[i
].type
== SHT_ARM_ATTRIBUTES
)
864 ULONG len
= sh
[i
].size
;
865 UBYTE
*data
= load_block(file
, sh
[i
].offset
, len
, funcarray
, DOSBase
);
869 BOOL res
= ARM_ParseAttrs(data
, len
, DOSBase
);
871 ilsFreeMem(data
, len
);
875 SetIoErr(ERROR_NOT_EXECUTABLE
);
883 /* Iterate over the section headers in order to do some stuff... */
884 for (i
= 0; i
< int_shnum
; i
++)
887 Load the symbol and string table(s).
889 NOTICE: the ELF standard, at the moment (Nov 2002) explicitely states
890 that only one symbol table per file is allowed. However, it
891 also states that this may change in future... we already handle it.
893 if (sh
[i
].type
== SHT_SYMTAB
|| sh
[i
].type
== SHT_STRTAB
|| sh
[i
].type
== SHT_SYMTAB_SHNDX
)
895 sh
[i
].addr
= load_block(file
, sh
[i
].offset
, sh
[i
].size
, funcarray
, DOSBase
);
899 if (sh
[i
].type
== SHT_STRTAB
) {
900 if (strtab
== NULL
) {
903 D(bug("[ELF Loader] file contains multiple strtab tables. only using the first one\n"));
907 if (sh
[i
].type
== SHT_SYMTAB_SHNDX
) {
908 if (symtab_shndx
== NULL
)
909 symtab_shndx
= &sh
[i
];
911 D(bug("[ELF Loader] file contains multiple symtab shndx tables. only using the first one\n"));
916 /* Now that we have the string and symbol tables loaded,
917 * load the rest of the hunks.
919 for (i
= 0; i
< int_shnum
; i
++)
921 /* Skip the already loaded hunks */
922 if (sh
[i
].type
== SHT_SYMTAB
|| sh
[i
].type
== SHT_STRTAB
|| sh
[i
].type
== SHT_SYMTAB_SHNDX
)
925 /* Load the section in memory if needed, and make a hunk out of it */
926 if (sh
[i
].flags
& SHF_ALLOC
)
930 /* Only allow alignment if this is an executable hunk
931 or if an executable hunk has been loaded already,
932 so to avoid the situation in which a data hunk has its
933 content displaced from the hunk's header in case it's the
934 first hunk (this happens with Keymaps, for instance). */
935 if (sh
[i
].flags
& SHF_EXECINSTR
)
936 exec_hunk_seen
= TRUE
;
938 if (!load_hunk(file
, &next_hunk_ptr
, &sh
[i
], strtab
? strtab
->addr
: NULL
, funcarray
, exec_hunk_seen
, DOSBase
))
944 /* Relocate the sections */
945 for (i
= 0; i
< int_shnum
; i
++)
947 /* Does this relocation section refer to a hunk? If so, addr must be != 0 */
948 if ((sh
[i
].type
== AROS_ELF_REL
) && sh
[SHINDEX(sh
[i
].info
)].addr
)
950 sh
[i
].addr
= load_block(file
, sh
[i
].offset
, sh
[i
].size
, funcarray
, DOSBase
);
951 if (!sh
[i
].addr
|| !relocate(&eh
, sh
, i
, symtab_shndx
, DOSBase
))
954 ilsFreeMem(sh
[i
].addr
, sh
[i
].size
);
959 /* Everything is loaded now. Register the module at kernel.resource */
960 register_elf(file
, hunks
, &eh
, sh
, DOSBase
);
965 /* There were some errors, deallocate The hunks */
967 InternalUnLoadSeg(hunks
, (VOID_FUNC
)funcarray
[2]);
973 * Clear the caches to let the CPU see the new data and instructions.
974 * We check for SysBase's lib_Version, since this code is also built
975 * as linklib for AmigaOS version of AROS bootstrap, and it can be
976 * running on AOS 1.3 or lower.
978 if (SysBase
->LibNode
.lib_Version
>= 36)
984 struct hunk
*hunk
= BPTR2HUNK(BADDR(curr
));
986 CacheClearE(hunk
->data
, hunk
->size
, CACRF_ClearD
| CACRF_ClearI
);
992 /* deallocate the symbol tables */
993 for (i
= 0; i
< int_shnum
; i
++)
995 if (((sh
[i
].type
== SHT_SYMTAB
) || (sh
[i
].type
== SHT_STRTAB
)) && (sh
[i
].addr
!= NULL
))
996 ilsFreeMem(sh
[i
].addr
, sh
[i
].size
);
999 /* Free the section headers */
1000 ilsFreeMem(sh
, int_shnum
* eh
.shentsize
);