PERFORCE change 31739 for review
Peter Wemm
peter at FreeBSD.org
Fri May 23 17:00:24 PDT 2003
http://perforce.freebsd.org/chv.cgi?CH=31739
Change 31739 by peter at peter_hammer on 2003/05/23 16:59:28
Get it to the point that something happens. Quite what yet
remains to be seen, but something makes a syscall. :-)
Affected files ...
.. //depot/projects/hammer/libexec/rtld-elf/amd64/reloc.c#6 edit
.. //depot/projects/hammer/libexec/rtld-elf/amd64/rtld_start.S#6 edit
Differences ...
==== //depot/projects/hammer/libexec/rtld-elf/amd64/reloc.c#6 (text+ko) ====
@@ -57,14 +57,14 @@
int
do_copy_relocations(Obj_Entry *dstobj)
{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
+ const Elf_Rela *relalim;
+ const Elf_Rela *rela;
assert(dstobj->mainprog); /* COPY relocations are invalid elsewhere */
- rellim = (const Elf_Rel *) ((caddr_t) dstobj->rel + dstobj->relsize);
- for (rel = dstobj->rel; rel < rellim; rel++) {
- if (ELF_R_TYPE(rel->r_info) == R_X86_64_COPY) {
+ relalim = (const Elf_Rela *) ((caddr_t) dstobj->rela + dstobj->relasize);
+ for (rela = dstobj->rela; rela < relalim; rela++) {
+ if (ELF_R_TYPE(rela->r_info) == R_X86_64_COPY) {
void *dstaddr;
const Elf_Sym *dstsym;
const char *name;
@@ -74,8 +74,8 @@
const Elf_Sym *srcsym;
Obj_Entry *srcobj;
- dstaddr = (void *) (dstobj->relocbase + rel->r_offset);
- dstsym = dstobj->symtab + ELF_R_SYM(rel->r_info);
+ dstaddr = (void *) (dstobj->relocbase + rela->r_offset);
+ dstsym = dstobj->symtab + ELF_R_SYM(rela->r_info);
name = dstobj->strtab + dstsym->st_name;
hash = elf_hash(name);
size = dstsym->st_size;
@@ -112,8 +112,8 @@
int
reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
+ const Elf_Rela *relalim;
+ const Elf_Rela *rela;
SymCache *cache;
int bytes = obj->nchains * sizeof(SymCache);
int r = -1;
@@ -126,11 +126,11 @@
if (cache == MAP_FAILED)
cache = NULL;
- rellim = (const Elf_Rel *) ((caddr_t) obj->rel + obj->relsize);
- for (rel = obj->rel; rel < rellim; rel++) {
- Elf_Addr *where = (Elf_Addr *) (obj->relocbase + rel->r_offset);
+ relalim = (const Elf_Rela *) ((caddr_t) obj->rela + obj->relasize);
+ for (rela = obj->rela; rela < relalim; rela++) {
+ Elf_Addr *where = (Elf_Addr *) (obj->relocbase + rela->r_offset);
- switch (ELF_R_TYPE(rel->r_info)) {
+ switch (ELF_R_TYPE(rela->r_info)) {
case R_X86_64_NONE:
break;
@@ -140,12 +140,12 @@
const Elf_Sym *def;
const Obj_Entry *defobj;
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
+ def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
false, cache);
if (def == NULL)
goto done;
- *where += (Elf_Addr) (defobj->relocbase + def->st_value);
+ *where += (Elf_Addr) (defobj->relocbase + def->st_value /* + rela->r_addend*/);
}
break;
@@ -159,13 +159,13 @@
const Elf_Sym *def;
const Obj_Entry *defobj;
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
+ def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
false, cache);
if (def == NULL)
goto done;
*where +=
- (Elf_Addr) (defobj->relocbase + def->st_value) -
+ (Elf_Addr) (defobj->relocbase + def->st_value /* + rela->r_addend */) -
(Elf_Addr) where;
}
break;
@@ -190,7 +190,7 @@
const Elf_Sym *def;
const Obj_Entry *defobj;
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
+ def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
false, cache);
if (def == NULL)
goto done;
@@ -200,7 +200,7 @@
break;
case R_X86_64_RELATIVE:
- *where += (Elf_Addr) obj->relocbase;
+ *where += (Elf_Addr)(obj->relocbase /*+ rela->r_addend*/);
break;
/* missing: R_X86_64_GOTPCREL, R_X86_64_32, R_X86_64_32S, R_X86_64_16, R_X86_64_PC16, R_X86_64_8, R_X86_64_PC8 */
@@ -208,7 +208,7 @@
default:
_rtld_error("%s: Unsupported relocation type %d"
" in non-PLT relocations\n", obj->path,
- ELF_R_TYPE(rel->r_info));
+ ELF_R_TYPE(rela->r_info));
goto done;
}
}
@@ -223,17 +223,17 @@
int
reloc_plt(Obj_Entry *obj)
{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
+ const Elf_Rela *relalim;
+ const Elf_Rela *rela;
- rellim = (const Elf_Rel *)((char *)obj->pltrel + obj->pltrelsize);
- for (rel = obj->pltrel; rel < rellim; rel++) {
+ relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
+ for (rela = obj->pltrela; rela < relalim; rela++) {
Elf_Addr *where;
- assert(ELF_R_TYPE(rel->r_info) == R_X86_64_JMP_SLOT);
+ assert(ELF_R_TYPE(rela->r_info) == R_X86_64_JMP_SLOT);
/* Relocate the GOT slot pointing into the PLT. */
- where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
+ where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
*where += (Elf_Addr)obj->relocbase;
}
return 0;
@@ -243,24 +243,24 @@
int
reloc_jmpslots(Obj_Entry *obj)
{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
+ const Elf_Rela *relalim;
+ const Elf_Rela *rela;
if (obj->jmpslots_done)
return 0;
- rellim = (const Elf_Rel *)((char *)obj->pltrel + obj->pltrelsize);
- for (rel = obj->pltrel; rel < rellim; rel++) {
+ relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
+ for (rela = obj->pltrela; rela < relalim; rela++) {
Elf_Addr *where, target;
const Elf_Sym *def;
const Obj_Entry *defobj;
- assert(ELF_R_TYPE(rel->r_info) == R_X86_64_JMP_SLOT);
- where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true, NULL);
+ assert(ELF_R_TYPE(rela->r_info) == R_X86_64_JMP_SLOT);
+ where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
+ def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj, true, NULL);
if (def == NULL)
return -1;
- target = (Elf_Addr)(defobj->relocbase + def->st_value);
- reloc_jmpslot(where, target, defobj, obj, rel);
+ target = (Elf_Addr)(defobj->relocbase + def->st_value /* + rela->r_addend */);
+ reloc_jmpslot(where, target, defobj, obj, (const Elf_Rel *)rela);
}
obj->jmpslots_done = true;
return 0;
==== //depot/projects/hammer/libexec/rtld-elf/amd64/rtld_start.S#6 (text+ko) ====
@@ -31,17 +31,12 @@
.type .rtld_start, at function
.rtld_start:
xorq %rbp,%rbp # Clear frame pointer for good form
- movq %rsp,%rax # Save initial stack pointer
subq $16,%rsp # A place to store exit procedure addr
- movq %rsp,%rbx # save address of exit proc
- movq %rsp,%rcx # construct address of obj_main
- addq $8,%rcx
- pushq %rcx # Pass address of obj_main
- pushq %rbx # Pass address of exit proc
- pushq %rax # Pass initial stack pointer to rtld
+ movq %rsp,%rsi # save address of exit proc
+ movq %rsp,%rdx # construct address of obj_main
+ addq $8,%rdx
call _rtld at PLT # Call rtld(sp); returns entry point
- addq $24,%rsp # Remove arguments from stack
- popq %rdx # Get exit procedure address
+ popq %rsi # Get exit procedure address
addq $8,%rsp # Ignore obj_main
/*
* At this point, %rax contains the entry point of the main program, and
More information about the p4-projects
mailing list