2 AHI - Hardware independent audio subsystem
3 Copyright (C) 1996-2005 Martin Blom <martin@blom.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Cambridge,
22 ** Based on code from the ppc.library emulator by Frank Wille:
23 ** ppc.library emulation
24 ** (c)1998-99 Frank Wille <frank@phoenix.owl.de>
28 #include <exec/types.h>
29 #include <exec/memory.h>
30 #include <exec/nodes.h>
32 #include <proto/dos.h>
33 #include <proto/exec.h>
35 // Even though this is WarpUp only, we still need a few defines from PowerUp...
36 #include <powerup/ppclib/object.h>
41 #include "elfloader.h"
44 /*** elfcommon.h *************************************************************/
46 /* e_indent indexes */
58 #define ELFCLASSNONE 0
68 #define ET_NONE 0 /* No file type */
69 #define ET_REL 1 /* Relocatable file */
70 #define ET_EXEC 2 /* Executable file */
71 #define ET_DYN 3 /* Shared object file */
72 #define ET_CORE 4 /* Core file */
73 #define ET_LOPROC 0xFF00 /* Processor-specific */
74 #define ET_HIPROC 0xFFFF /* Processor-specific */
89 #define EM_MIPS_RS4_BE 10
93 #define EM_SPARC32PLUS 18
95 #define EM_CYGNUS_POWERPC 0x9025
96 #define EM_ALPHA 0x9026
98 /* values for program header, p_type field */
99 #define PT_NULL 0 /* Program header table entry unused */
100 #define PT_LOAD 1 /* Loadable program segment */
101 #define PT_DYNAMIC 2 /* Dynamic linking information */
102 #define PT_INTERP 3 /* Program interpreter */
103 #define PT_NOTE 4 /* Auxiliary information */
104 #define PT_SHLIB 5 /* Reserved, unspecified semantics */
105 #define PT_PHDR 6 /* Entry for header table itself */
106 #define PT_LOPROC 0x70000000 /* Processor-specific */
107 #define PT_HIPROC 0x7FFFFFFF /* Processor-specific */
109 /* Program segment permissions, in program header p_flags field */
110 #define PF_X (1 << 0) /* Segment is executable */
111 #define PF_W (1 << 1) /* Segment is writable */
112 #define PF_R (1 << 2) /* Segment is readable */
113 #define PF_MASKPROC 0xF0000000 /* Processor-specific reserved bits */
115 /* special sections indexes */
117 #define SHN_ABS 0xfff1
118 #define SHN_COMMON 0xfff2
121 #define SHT_NULL 0 /* Section header table entry unused */
122 #define SHT_PROGBITS 1 /* Program specific (private) data */
123 #define SHT_SYMTAB 2 /* Link editing symbol table */
124 #define SHT_STRTAB 3 /* A string table */
125 #define SHT_RELA 4 /* Relocation entries with addends */
126 #define SHT_HASH 5 /* A symbol hash table */
127 #define SHT_DYNAMIC 6 /* Information for dynamic linking */
128 #define SHT_NOTE 7 /* Information that marks file */
129 #define SHT_NOBITS 8 /* Section occupies no space in file */
130 #define SHT_REL 9 /* Relocation entries, no addends */
131 #define SHT_SHLIB 10 /* Reserved, unspecified semantics */
132 #define SHT_DYNSYM 11 /* Dynamic linking symbol table */
133 #define SHT_LOPROC 0x70000000 /* Processor-specific semantics, lo */
134 #define SHT_HIPROC 0x7FFFFFFF /* Processor-specific semantics, hi */
135 #define SHT_LOUSER 0x80000000 /* Application-specific semantics */
136 #define SHT_HIUSER 0x8FFFFFFF /* Application-specific semantics */
139 #define SHF_WRITE (1 << 0) /* Writable data during execution */
140 #define SHF_ALLOC (1 << 1) /* Occupies memory during execution */
141 #define SHF_EXECINSTR (1 << 2) /* Executable machine instructions */
142 #define SHF_MASKPROC 0xF0000000 /* Processor-specific semantics */
144 /* Values of note segment descriptor types for core files. */
145 #define NT_PRSTATUS 1 /* Contains copy of prstatus struct */
146 #define NT_FPREGSET 2 /* Contains copy of fpregset struct */
147 #define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */
149 #define STN_UNDEF 0 /* undefined symbol index */
152 #define STB_LOCAL 0 /* Symbol not visible outside obj */
153 #define STB_GLOBAL 1 /* Symbol visible outside obj */
154 #define STB_WEAK 2 /* Like globals, lower precedence */
155 #define STB_LOPROC 13 /* Application-specific semantics */
156 #define STB_HIPROC 15 /* Application-specific semantics */
159 #define STT_NOTYPE 0 /* Symbol type is unspecified */
160 #define STT_OBJECT 1 /* Symbol is a data object */
161 #define STT_FUNC 2 /* Symbol is a code object */
162 #define STT_SECTION 3 /* Symbol associated with a section */
163 #define STT_FILE 4 /* Symbol gives a file name */
164 #define STT_LOPROC 13 /* Application-specific semantics */
165 #define STT_HIPROC 15 /* Application-specific semantics */
167 /* Dynamic section tags */
170 #define DT_PLTRELSZ 2
184 #define DT_SYMBOLIC 16
190 #define DT_TEXTREL 22
192 #define DT_LOPROC 0x70000000
193 #define DT_HIPROC 0x7fffffff
195 /*** elf32.h *****************************************************************/
197 typedef unsigned char uint8
;
198 typedef unsigned short uint16
;
199 typedef unsigned long uint32
;
203 unsigned char e_ident
[EI_NIDENT
];
242 #define ELF32_ST_BIND(i) ((i)>>4)
243 #define ELF32_ST_TYPE(i) ((i)&0xf)
244 #define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
258 #define ELF32_R_SYM(i) ((i)>>8)
259 #define ELF32_R_TYPE(i) ((unsigned char)(i))
260 #define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t))
262 /*** elfobject.h *************************************************************/
264 struct ELFSection
{ /* prog. sections for new tasks */
266 APTR address
; /* physical RAM address or NULL */
269 long offset
; /* file offset and section size */
271 int nrel
; /* number of relocs */
272 struct Elf32_Rela
*relocs
; /* array of Elf32_Rela structs */
275 #define ElfSecB_NOBITS 0 /* bss section */
276 #define ElfSecF_NOBITS 1
277 #define ElfSecB_RELA 1 /* Relocs are of .rela type */
278 #define ElfSecF_RELA 2
282 // struct Node n; /* contains object's name ptr */
284 // struct PPCLibBase *ppcbase;
285 // void *pool; /* pooled memory for object data */
286 BPTR handle
; /* ELF file handle */
287 // APTR handle; /* ELF file handle */
288 // struct Hook *hook; /* hook functions for read/seek */
289 // struct Hook defaultHook;
290 char *secnames
; /* .shstrtab - section names */
291 char *symnames
; /* .strtab - symbol mames */
292 struct Elf32_Ehdr
*header
; /* the ELF file header */
293 struct Elf32_Sym
*symtab
; /* .symtab - symbol table */
294 uint32 nsyms
; /* number of symbols */
295 uint32 gsyms
; /* first global symbol */
296 struct ELFSection
**sections
; /* ELFSection pointers */
297 uint32 nsects
; /* number of sections */
298 // struct SignalSemaphore ElfSS; /* ElfObject access arbitration */
301 #define ElfObjB_Relocated 0 /* Object is relocated */
302 #define ElfObjF_Relocated 1
304 /*** relocnames.c ************************************************************/
306 const char *reloc_name
[] = {
315 "R_PPC_ADDR14_BRTAKEN",
316 "R_PPC_ADDR14_BRNTAKEN",
319 "R_PPC_REL14_BRTAKEN",
320 "R_PPC_REL14_BRNTAKEN",
346 /*** ppcobject.c *************************************************************/
349 /* Bug fix for powerup/ppclib/object.h */
350 #ifdef R_PPC_ADDR16_L
351 #ifndef R_PPC_ADDR16_LO
352 #define R_PPC_ADDR16_LO R_PPC_ADDR16_L
357 freeelfobj(struct ElfObject
*elfobj
);
360 loadelf32(struct ElfObject
*eo
,struct Elf32_Shdr
*shdrs
);
363 scanElfSymbols(struct ElfObject
*eo
,struct PPCObjectInfo
*info
,
367 getsyminfo(struct ElfObject
*eo
,struct PPCObjectInfo
*info
,
368 struct Elf32_Sym
*stab
);
371 loadprogram(struct ElfObject
*eo
);
374 freeprogram(struct ElfObject
*eo
);
377 relocate(struct ElfObject
*eo
);
380 allocstr( const char* string
);
383 alloc32c( size_t size
);
386 alloc32( size_t size
);
389 free32( void* addr
);
392 opstream(struct ElfObject
*eo
, const char* name
);
395 clstream(struct ElfObject
*eo
);
398 rdstream(struct ElfObject
*eo
,void *buf
,long len
);
401 skstream(struct ElfObject
*eo
,long offs
,long mode
);
404 prstream(struct ElfObject
*eo
,long offs
,void *buf
,long len
);
407 readsection(struct ElfObject
*eo
,struct Elf32_Shdr
*sh
);
409 static struct ELFSection
*
410 progsection(struct ElfObject
*eo
, struct Elf32_Shdr
*sh
);
413 common_symbols(struct ElfObject
*eo
);
416 getrelocs(struct ElfObject
*eo
,struct Elf32_Shdr
*sh
);
418 static const char ELFid
[4] = {
423 ELFLoadObject( const char* objname
)
425 struct ElfObject
*elfobj
= NULL
;
427 /* allocate ElfObject structure */
429 elfobj
= alloc32( sizeof( struct ElfObject
) );
433 memset(elfobj
,0,sizeof(struct ElfObject
));
435 elfobj
->header
= alloc32( sizeof( struct Elf32_Ehdr
) );
437 if( elfobj
->header
!= NULL
)
439 /* open ELF stream for reading */
441 elfobj
->handle
= opstream( elfobj
, objname
);
443 if( elfobj
->handle
!= NULL
)
445 /* read and identify ELF 32bit PowerPC BigEndian header */
447 if( rdstream( elfobj
, elfobj
->header
, sizeof(struct Elf32_Ehdr
) ) )
449 struct Elf32_Ehdr
*hdr
= elfobj
->header
;
451 if (!strncmp(hdr
->e_ident
,ELFid
,4) &&
452 hdr
->e_ident
[EI_CLASS
]==ELFCLASS32
&&
453 hdr
->e_ident
[EI_DATA
]==ELFDATA2MSB
&&
454 hdr
->e_ident
[EI_VERSION
]==1 && hdr
->e_version
==1 &&
455 (hdr
->e_machine
==EM_PPC
|| hdr
->e_machine
==EM_PPC_OLD
||
456 hdr
->e_machine
==EM_CYGNUS_POWERPC
) && hdr
->e_type
==ET_REL
)
458 struct Elf32_Shdr
*shdrs
;
459 ULONG shdrsize
= (ULONG
) hdr
->e_shnum
* (ULONG
) hdr
->e_shentsize
;
461 // KPrintF("elf32ppcbe format recognized\n");
463 shdrs
= alloc32( shdrsize
);
467 /* read section header table and parse rest of object */
469 if( prstream( elfobj
, hdr
->e_shoff
, shdrs
, shdrsize
) )
471 if( loadelf32( elfobj
, shdrs
) )
474 // KPrintF("ELF object loaded (0x%08lx)\n", elfobj );
475 start
= loadprogram( elfobj
);
476 // KPrintF("Start of PPC code: 0x%08lx\n", start );
485 KPrintF( "Not an ELF32-PPC-BE\nrelocatable object.");
497 ELFUnLoadObject( void* obj
)
499 struct ElfObject
* elfobj
= (struct ElfObject
*) obj
;
501 if(elfobj
->sections
!= NULL
&& elfobj
->nsects
> 0 )
510 ELFGetSymbol( void* obj
,
514 struct PPCObjectInfo oi
=
518 PPCELFINFOTYPE_SYMBOL
,
526 oi
.Name
= (char*) name
;
527 rc
= scanElfSymbols( (struct ElfObject
*) obj
, &oi
, FALSE
);
531 *ptr
= (void*) oi
.Address
;
538 static void freeelfobj(struct ElfObject
*elfobj
)
539 /* free all memory connected to an ElfObject */
549 static BOOL
loadelf32(struct ElfObject
*eo
,struct Elf32_Shdr
*shdrs
)
550 /* parse ELF object, initialize ElfObject structure */
552 struct Elf32_Ehdr
*hdr
= eo
->header
;
553 struct ELFSection
*s
;
556 if ((eo
->secnames
= readsection(eo
,&shdrs
[hdr
->e_shstrndx
])) &&
557 (eo
->sections
= alloc32((hdr
->e_shnum
+1)*sizeof(void *)))) {
558 memset(eo
->sections
,0,(hdr
->e_shnum
+1)*sizeof(void *));
559 eo
->nsects
= hdr
->e_shnum
+ 1; /* +1 section for COMMON symbols */
560 for (i
=1; i
<hdr
->e_shnum
; i
++) {
561 switch (shdrs
[i
].sh_type
) {
564 if (!(eo
->sections
[i
] = progsection(eo
,&shdrs
[i
])))
568 if (!(eo
->symnames
= readsection(eo
,&shdrs
[shdrs
[i
].sh_link
]))
569 || !(eo
->symtab
= readsection(eo
,&shdrs
[i
])))
571 eo
->nsyms
= shdrs
[i
].sh_size
/ sizeof(struct Elf32_Sym
);
572 eo
->gsyms
= shdrs
[i
].sh_info
;
578 for (i
=1; i
<hdr
->e_shnum
; i
++) {
579 switch (shdrs
[i
].sh_type
) {
582 if (!getrelocs(eo
,&shdrs
[i
]))
589 /* allocate space for Common symbols */
590 return (common_symbols(eo
));
596 static BOOL
scanElfSymbols(struct ElfObject
*eo
,struct PPCObjectInfo
*info
,
598 /* Find an ELF symbol by its name or address and return all infos */
599 /* in the supplied PPCObjectInfo structure. Return FALSE if symbol */
601 /* ATTENTION: PPCLibBase may be locked at that stage! */
603 ULONG addr
= info
->Address
;
604 char *name
= info
->Name
;
605 //KPrintF( "scanElfSymbols( 0x%08lx, 0x%08lx, %ld\n", eo, info, relmode );
609 struct ELFSection
*es
;
610 struct Elf32_Rela
*r
;
612 for (i
=1; i
<(eo
->nsects
-1); i
++) {
613 if( (es
= eo
->sections
[i
]) != NULL
) {
614 for (j
=0,r
=es
->relocs
; j
<es
->nrel
; j
++,r
++) {
615 if (getsyminfo(eo
,info
,&eo
->symtab
[ELF32_R_SYM(r
->r_info
)])) {
616 info
->Address
= (ULONG
)es
->address
+ r
->r_offset
;
617 info
->Type
= PPCELFINFOTYPE_RELOC
;
618 info
->SubType
= (ULONG
)ELF32_R_TYPE(r
->r_info
);
619 if (info
->Address
== addr
) {
621 if (!strcmp(name
,info
->Name
))
634 struct Elf32_Sym
*stab
= eo
->symtab
;
637 //KPrintF( "i=%ld\n", i );
638 if (getsyminfo(eo
,info
,++stab
)) {
641 if (addr
>=info
->Address
&& addr
<(info
->Address
+info
->Size
))
645 if (addr
== info
->Address
)
650 //KPrintF( "comparing %s and %s\n", name,info->Name );
651 if (!strcmp(name
,info
->Name
))
661 static BOOL
getsyminfo(struct ElfObject
*eo
,struct PPCObjectInfo
*info
,
662 struct Elf32_Sym
*stab
)
664 struct ELFSection
*es
;
667 subtype
= (ULONG
)ELF32_ST_TYPE(stab
->st_info
);
668 if (subtype
< STT_FILE
) {
669 info
->Type
= subtype
==STT_SECTION
? PPCELFINFOTYPE_SECTION
670 : PPCELFINFOTYPE_SYMBOL
;
671 switch (stab
->st_shndx
) {
673 /* undefined symbols will disappear after relocation */
675 info
->Address
= stab
->st_value
;
678 /* @@@ common symbols should have disappeared after common_symbols() */
679 info
->Type
= PPCELFINFOTYPE_COMSYMBOL
;
683 if( (es
= eo
->sections
[stab
->st_shndx
]) != NULL
)
684 info
->Address
= (ULONG
)es
->address
+ stab
->st_value
;
686 info
->Address
= stab
->st_value
;
689 info
->Name
= eo
->symnames
+ stab
->st_name
;
690 info
->SubType
= subtype
;
691 info
->Binding
= (ULONG
)ELF32_ST_BIND(stab
->st_info
);
692 info
->Size
= stab
->st_size
;
698 static APTR
loadprogram(struct ElfObject
*eo
)
699 /* load all sections into memory and relocate them */
701 static const char *FN
= "loadprogram(): ";
702 struct ELFSection
*s
;
703 uint8
*p
,*entry
=NULL
;
706 for (i
=0; i
<(eo
->nsects
-1); i
++) {
707 if( (s
= eo
->sections
[i
]) != NULL
) {
708 BOOL text
= !strcmp(s
->name
,".text"); /* .text section flag */
709 ULONG size
= s
->size
;
711 /* align to 32 bytes and allocate 32-byte aligned memory */
712 size
= (size
+31)&~31;
713 if( (p
= alloc32c(size
)) != NULL
) {
714 s
->address
= (APTR
)p
; /* store section's base address */
715 if (!(s
->flags
& ElfSecF_NOBITS
)) {
716 /* a PROGBITS section - load it from file */
718 // KPrintF("%sreading section %s\n",FN,s->name);
719 if (prstream(eo
,s
->offset
,p
,s
->size
)) {
721 /* get start address of PPC program in .text */
723 if ((*entry
& 0xfc) == 0) {
724 // KPrintF("%sgcc traceback status word "
726 entry
+= 4; /* 1st long reserved for gcc traceback word */
728 /* copy kernel stubs */
730 KPrintF("%sentry=0x%08lx, "
731 "invoking dynamic linker\n",FN,entry);
732 if (!dynamic_linker(i,eo,p)) {
746 KPrintF("Failed to allocate %ld bytes\n"
747 "for PPC %s section.",size
,s
->name
);
755 if (!relocate(eo
)) { /* relocate sections */
763 // KPrintF("%sreturning with entry=0x%08lx\n",FN,entry);
768 static void freeprogram(struct ElfObject
*eo
)
770 struct ELFSection
*s
;
773 for (i
=0; i
<eo
->nsects
; i
++) {
774 if( (s
= eo
->sections
[i
]) != NULL
) {
784 static BOOL
relocate(struct ElfObject
*eo
)
786 struct ELFSection
*es
;
789 for (shndx
=0; shndx
<(eo
->nsects
-1); shndx
++) {
790 if( (es
= eo
->sections
[shndx
]) != NULL
) {
791 BOOL rela
= (es
->flags
& ElfSecF_RELA
) != 0;
792 struct Elf32_Rela
*r
;
795 // KPrintF("relocate(): relocating section %s "
796 // "at 0x%08lx\n",es->name,es->address);
797 for (i
=0,r
=es
->relocs
; i
<es
->nrel
; i
++,r
++) {
798 struct Elf32_Sym
*sym
= &eo
->symtab
[ELF32_R_SYM(r
->r_info
)];
799 long s
= (long)eo
->sections
[sym
->st_shndx
]->address
+ sym
->st_value
;
800 uint8
*p
= (uint8
*)es
->address
+ r
->r_offset
;
802 switch (ELF32_R_TYPE(r
->r_info
)) {
808 *(long *)p
= s
+ r
->r_addend
;
815 *(short *)p
= s
+ r
->r_addend
;
820 case R_PPC_ADDR16_LO
:
822 *(short *)p
= (s
+ r
->r_addend
) & 0xffff;
824 *(short *)p
= (s
+ *(short *)p
) & 0xffff;
827 case R_PPC_ADDR16_HI
:
829 *(short *)p
= (s
+ r
->r_addend
) >> 16;
831 *(short *)p
= (s
+ *(short *)p
) >> 16;
834 case R_PPC_ADDR16_HA
:
839 *(short *)p
= (s
>>16) + ((s
&0x8000) ? 1 : 0);
844 s
= (s
+ r
->r_addend
) - (long)p
;
848 s
= (s
+ ((*(long *)p
& 0x03fffffc) - 0x04000000)) - (long)p
;
850 s
= (s
+ (*(long *)p
& 0x03fffffc)) - (long)p
;
852 *(unsigned long *)p
= (*(unsigned long *)p
& 0xfc000003) |
853 ((unsigned long)s
& 0x03fffffc);
858 *(long *)p
= (s
+ r
->r_addend
) - (long)p
;
860 *(long *)p
= (s
+ *(long *)p
) - (long)p
;
864 KPrintF("Relocation type %s\nat %s+%ld referencing\n"
865 "symbol %s+%ld\nis not supported.",
866 reloc_name
[ELF32_R_TYPE(r
->r_info
)],es
->name
,r
->r_offset
,
867 eo
->symnames
+sym
->st_name
,sym
->st_value
);
877 alloc32( size_t size
)
879 return AHIAllocVec( size
, MEMF_ANY
);
883 alloc32c( size_t size
)
885 return AHIAllocVec( size
, MEMF_ANY
| MEMF_CLEAR
);
896 allocstr( const char* string
)
900 mem
= AllocVec( strlen( string
) + 1, MEMF_ANY
);
904 strcpy( mem
, string
);
912 opstream(struct ElfObject
*eo
, const char* name
)
918 handle
= Open( (char*) name
, MODE_OLDFILE
);
926 clstream(struct ElfObject
*eo
)
934 rdstream(struct ElfObject
*eo
,void *buf
,long len
)
938 r
= Read( eo
->handle
, buf
, len
);
949 skstream(struct ElfObject
*eo
,long offs
,long mode
)
953 r
= Seek( eo
->handle
, offs
, mode
);
959 prstream(struct ElfObject
*eo
,long offs
,void *buf
,long len
)
960 /* position and read stream */
962 if (skstream(eo
,offs
,OFFSET_BEGINNING
) != -1)
963 return (rdstream(eo
,buf
,len
));
968 static void *readsection(struct ElfObject
*eo
,struct Elf32_Shdr
*sh
)
969 /* allocate memory and read section contents */
973 if( (p
= AllocVec(sh
->sh_size
,MEMF_ANY
)) != NULL
)
974 if (prstream(eo
,sh
->sh_offset
,p
,sh
->sh_size
))
980 static struct ELFSection
*progsection(struct ElfObject
*eo
,
981 struct Elf32_Shdr
*sh
)
982 /* Create Section structure from Elf32_Shdr. The contents of these */
983 /* sections will be loaded and relocated on demand, e.g. if a new task */
986 struct ELFSection
*s
;
988 if( (s
= AllocVec(sizeof(struct ELFSection
),MEMF_ANY
)) != NULL
) {
989 memset(s
,0,sizeof(struct ELFSection
));
990 s
->name
= eo
->secnames
+ sh
->sh_name
;
991 s
->flags
= sh
->sh_type
==SHT_NOBITS
? ElfSecF_NOBITS
:0;
992 s
->alignment
= (uint8
)sh
->sh_addralign
;
993 s
->offset
= sh
->sh_offset
;
994 s
->size
= sh
->sh_size
;
1001 static BOOL
common_symbols(struct ElfObject
*eo
)
1002 /* Create a and initialize Section structure for Common symbols. */
1004 static const char *FN
= "common_symbols(): ";
1005 static const char *bssname
= ".bss";
1006 struct ELFSection
*s
= NULL
;
1007 struct Elf32_Sym
*sym
;
1009 uint32 offset
= 0,idx
= 0,cnt
=0;
1012 /* First try to find a .bss, where Common symbols could be appended */
1013 for (i
=0; i
<(eo
->nsects
-1); i
++) {
1014 if( (s
= eo
->sections
[i
]) != NULL
) {
1015 if (!strcmp(s
->name
,bssname
) && (s
->flags
& ElfSecF_NOBITS
)) {
1018 // KPrintF("%sfound %s at index %ld with size=%ld\n",
1019 // FN,bssname,idx,offset);
1028 /* No .bss section present, allocate an own one */
1029 if( (s
= AllocVec(sizeof(struct ELFSection
),MEMF_ANY
)) != NULL
) {
1030 memset(s
,0,sizeof(struct ELFSection
));
1031 s
->name
= allocstr((char *)bssname
);
1032 s
->flags
= ElfSecF_NOBITS
;
1036 eo
->sections
[idx
] = s
;
1037 // KPrintF("%screated new %s at index %ld\n",FN,bssname,idx);
1043 /* Ok, search for COMMON symbols now */
1044 for (i
=1,sym
=&eo
->symtab
[1]; i
<eo
->nsyms
; i
++,sym
++) {
1045 if (sym
->st_shndx
== SHN_COMMON
) {
1046 offset
= (offset
+ sym
->st_value
-1) & ~(sym
->st_value
-1);
1047 sym
->st_value
= offset
;
1048 sym
->st_shndx
= idx
;
1049 offset
+= sym
->st_size
;
1053 // KPrintF("%sassigned %ld common symbols (%ld bytes)\n",
1054 // FN,cnt,offset-s->size);
1055 s
->size
= offset
; /* set new .bss section size */
1061 static BOOL
getrelocs(struct ElfObject
*eo
,struct Elf32_Shdr
*sh
)
1062 /* read relocation entries for a section */
1064 uint32 rsize
= sh
->sh_entsize
;
1065 int nrelocs
= (int)(sh
->sh_size
/rsize
);
1066 struct ELFSection
*s
= eo
->sections
[sh
->sh_info
];
1070 if (sh
->sh_type
== SHT_RELA
) {
1071 s
->flags
|= ElfSecF_RELA
;
1072 if( (s
->relocs
= readsection(eo
,sh
)) != NULL
)
1076 struct Elf32_Rela
*r
;
1078 if ((r
= s
->relocs
= AllocVec(nrelocs
*sizeof(struct Elf32_Rela
),
1080 (skstream(eo
,sh
->sh_offset
,OFFSET_BEGINNING
) != -1)) {
1083 if (!rdstream(eo
,r
,sizeof(struct Elf32_Rel
)))