+ DEBUGS(" elf_relocate: Beginning Relocation");
+
+ void elf_doRelocate(Uint r_info, Uint32 *ptr, Uint32 addend, Elf32_Sym *symtab)
+ {
+ int type = ELF32_R_TYPE(r_info);
+ int sym = ELF32_R_SYM(r_info);
+ Uint32 val;
+ const char *symname = dynstrtab + symtab[sym].nameOfs;
+ switch( type )
+ {
+ // Standard 32 Bit Relocation (S+A)
+ case R_386_32:
+ val = (intptr_t) GetSymbol( symname );
+ DEBUGS(" elf_doRelocate: R_386_32 *0x%x += 0x%x('%s')",
+ ptr, val, symname);
+ *ptr = val + addend;
+ break;
+
+ // 32 Bit Relocation wrt. Offset (S+A-P)
+ case R_386_PC32:
+ DEBUGS(" elf_doRelocate: #%i: '%s'", sym, symname);
+ val = (intptr_t) GetSymbol( symname );
+ DEBUGS(" elf_doRelocate: R_386_PC32 *0x%x = 0x%x + 0x%x - 0x%x",
+ ptr, *ptr, val, (Uint)ptr );
+ *ptr = val + addend - (intptr_t)ptr;
+ //*ptr = val + addend - ((Uint)ptr - iBaseDiff);
+ break;
+
+ // Absolute Value of a symbol (S)
+ case R_386_GLOB_DAT:
+ case R_386_JMP_SLOT:
+ DEBUGS(" elf_doRelocate: #%i: '%s'", sym, symname);
+ val = (intptr_t) GetSymbol( symname );
+ DEBUGS(" elf_doRelocate: %s *0x%x = 0x%x", csaR_NAMES[type], ptr, val);
+ *ptr = val;
+ break;
+
+ // Base Address (B+A)
+ case R_386_RELATIVE:
+ DEBUGS(" elf_doRelocate: R_386_RELATIVE *0x%x = 0x%x + 0x%x", ptr, iBaseDiff, addend);
+ *ptr = iBaseDiff + addend;
+ break;
+
+ default:
+ DEBUGS(" elf_doRelocate: Rel 0x%x: 0x%x,%s", ptr, sym, csaR_NAMES[type]);
+ break;
+ }
+ }