Changeset View
Standalone View
libexec/rtld-elf/rtld.c
Show First 20 Lines • Show All 1,249 Lines • ▼ Show 20 Lines | digest_dynamic1(Obj_Entry *obj, int early, const Elf_Dyn **dyn_rpath, | ||||
case DT_RELASZ: | case DT_RELASZ: | ||||
obj->relasize = dynp->d_un.d_val; | obj->relasize = dynp->d_un.d_val; | ||||
break; | break; | ||||
case DT_RELAENT: | case DT_RELAENT: | ||||
assert(dynp->d_un.d_val == sizeof(Elf_Rela)); | assert(dynp->d_un.d_val == sizeof(Elf_Rela)); | ||||
break; | break; | ||||
case DT_RELR: | |||||
obj->relr = (const Elf_Relr *)(obj->relocbase + dynp->d_un.d_ptr); | |||||
break; | |||||
case DT_RELRSZ: | |||||
obj->relrsize = dynp->d_un.d_val; | |||||
break; | |||||
case DT_PLTREL: | case DT_PLTREL: | ||||
plttype = dynp->d_un.d_val; | plttype = dynp->d_un.d_val; | ||||
assert(dynp->d_un.d_val == DT_REL || plttype == DT_RELA); | assert(dynp->d_un.d_val == DT_REL || plttype == DT_RELA); | ||||
break; | break; | ||||
case DT_SYMTAB: | case DT_SYMTAB: | ||||
obj->symtab = (const Elf_Sym *) | obj->symtab = (const Elf_Sym *) | ||||
(obj->relocbase + dynp->d_un.d_ptr); | (obj->relocbase + dynp->d_un.d_ptr); | ||||
▲ Show 20 Lines • Show All 1,877 Lines • ▼ Show 20 Lines | if (mprotect(base, sz, prot) == -1) { | ||||
obj->path, before ? "en" : "dis", | obj->path, before ? "en" : "dis", | ||||
rtld_strerror(errno)); | rtld_strerror(errno)); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
/* Process RELR relative relocations. */ | |||||
static void | |||||
reloc_relr(Obj_Entry *obj) | |||||
{ | |||||
const Elf_Relr *relr, *relrlim; | |||||
kib: Please use normal style(9) conventions for the new code. Most important, use tab for indent… | |||||
fbsd-phab_maskray.meAuthorUnsubmitted Done Inline ActionsOK. I'll use this neovim script for my FreeBSD code: :so ~/Dev/freebsd/tools/tools/editing/freebsd.vim :call FreeBSD_Style() :set ts=8 sw=4 sts=0 noet fbsd-phab_maskray.me: OK. I'll use this neovim script for my FreeBSD code:
```
:so… | |||||
arichardsonUnsubmitted Not Done Inline ActionsFor most code git-clang-format should be almost correct. However rtld still uses different indentation for some functions... arichardson: For most code git-clang-format should be almost correct. However rtld still uses different… | |||||
Elf_Addr *where; | |||||
relrlim = (const Elf_Relr *)((const char *)obj->relr + obj->relrsize); | |||||
for (relr = obj->relr; relr < relrlim; relr++) { | |||||
Elf_Relr entry = *relr; | |||||
Done Inline ActionsThere should be a blank line after the local declaration. kib: There should be a blank line after the local declaration. | |||||
if (entry % 2 == 0) { | |||||
kibUnsubmitted Done Inline ActionsYou are checking the lowest bit there, right? I believe & 1 is much more common way to do this. Initially I was quite confused by the code, but apparently they changed encoding against the initial proposal. Also they made all entries 64bit, right? IMO the documentation in the tangled thread on some list/google groups is not enough argument to start supporting this stuff. The last activity occured in 2018. kib: You are checking the lowest bit there, right? I believe `& 1` is much more common way to do… | |||||
fbsd-phab_maskray.meAuthorUnsubmitted Done Inline ActionsYes, the format changed. Ali Bahrami's comment (scroll to the bottom) is the format used by ld.lld, llvm-readelf -r, Android bionic, Linux kernel, and Chrome OS. Someone may need to implement readelf -r for FreeBSD's readelf. fbsd-phab_maskray.me: Yes, the format changed. Ali Bahrami's comment (scroll to the bottom) is the format used by ld. | |||||
arichardsonUnsubmitted Not Done Inline ActionsOr we just switch to MK_LLVM_BINUTILS by default :) arichardson: Or we just switch to MK_LLVM_BINUTILS by default :) | |||||
emasteUnsubmitted Not Done Inline ActionsOr both - even when MK_LLVM_BINUTILS lands we presumably will not MFC it, but people may well run readelf from older FreeBSD branches to inspect objects built with RELR. emaste: Or both - even when `MK_LLVM_BINUTILS` lands we presumably will not MFC it, but people may well… | |||||
where = (Elf_Addr *)(obj->relocbase + entry); | |||||
*where++ += (Elf_Addr)obj->relocbase; | |||||
} else { | |||||
long i = 0; | |||||
for (; (entry >>= 1) != 0; i++) | |||||
Done Inline ActionsIf you use local inside block, why not move its declaration into for loop init clause? kib: If you use local inside block, why not move its declaration into for loop init clause? | |||||
if (entry % 2 != 0) | |||||
Not Done Inline Actions!= 0 kib: != 0 | |||||
where[i] += (Elf_Addr)obj->relocbase; | |||||
where += 8 * sizeof(Elf_Relr) - 1; | |||||
kibUnsubmitted Done Inline ActionsWhat does this 8 mean? kib: What does this 8 mean? | |||||
fbsd-phab_maskray.meAuthorUnsubmitted Done Inline ActionsCHAR_BIT = 8. I just switched to CHAR_BIT for clarity. A bitmap entry describes 63 locations on a 64-bit machine. where skips 63 locations. fbsd-phab_maskray.me: CHAR_BIT = 8. I just switched to CHAR_BIT for clarity.
A bitmap entry describes 63 locations… | |||||
} | |||||
} | |||||
} | |||||
/* | /* | ||||
* Relocate single object. | * Relocate single object. | ||||
* Returns 0 on success, or -1 on failure. | * Returns 0 on success, or -1 on failure. | ||||
*/ | */ | ||||
static int | static int | ||||
relocate_object(Obj_Entry *obj, bool bind_now, Obj_Entry *rtldobj, | relocate_object(Obj_Entry *obj, bool bind_now, Obj_Entry *rtldobj, | ||||
int flags, RtldLockState *lockstate) | int flags, RtldLockState *lockstate) | ||||
{ | { | ||||
Show All 10 Lines | relocate_object(Obj_Entry *obj, bool bind_now, Obj_Entry *rtldobj, | ||||
/* There are relocations to the write-protected text segment. */ | /* There are relocations to the write-protected text segment. */ | ||||
if (obj->textrel && reloc_textrel_prot(obj, true) != 0) | if (obj->textrel && reloc_textrel_prot(obj, true) != 0) | ||||
return (-1); | return (-1); | ||||
/* Process the non-PLT non-IFUNC relocations. */ | /* Process the non-PLT non-IFUNC relocations. */ | ||||
if (reloc_non_plt(obj, rtldobj, flags, lockstate)) | if (reloc_non_plt(obj, rtldobj, flags, lockstate)) | ||||
return (-1); | return (-1); | ||||
reloc_relr(obj); | |||||
/* Re-protected the text segment. */ | /* Re-protected the text segment. */ | ||||
if (obj->textrel && reloc_textrel_prot(obj, false) != 0) | if (obj->textrel && reloc_textrel_prot(obj, false) != 0) | ||||
return (-1); | return (-1); | ||||
/* Set the special PLT or GOT entries. */ | /* Set the special PLT or GOT entries. */ | ||||
init_pltgot(obj); | init_pltgot(obj); | ||||
▲ Show 20 Lines • Show All 2,902 Lines • Show Last 20 Lines |
Please use normal style(9) conventions for the new code. Most important, use tab for indent, not 4 spaces.