rtld: style adjustments

Consistently use `return ()'.
Fix some spacing issues with types formatting, and around binary ops.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
This commit is contained in:
Konstantin Belousov 2021-11-06 05:20:39 +02:00
parent c5637b8be8
commit 74aec9618f

View File

@ -974,7 +974,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp)
/* Return the exit procedure and the program entry point. */ /* Return the exit procedure and the program entry point. */
*exit_proc = rtld_exit_ptr; *exit_proc = rtld_exit_ptr;
*objp = obj_main; *objp = obj_main;
return (func_ptr_type) obj_main->entry; return ((func_ptr_type)obj_main->entry);
} }
void * void *
@ -1035,7 +1035,7 @@ _rtld_bind(Obj_Entry *obj, Elf_Size reloff)
*/ */
target = reloc_jmpslot(where, target, defobj, obj, rel); target = reloc_jmpslot(where, target, defobj, obj, rel);
lock_release(rtld_bind_lock, &lockstate); lock_release(rtld_bind_lock, &lockstate);
return target; return (target);
} }
/* /*
@ -1092,8 +1092,10 @@ errmsg_restore(struct dlerror_save *saved_msg)
static const char * static const char *
basename(const char *name) basename(const char *name)
{ {
const char *p = strrchr(name, '/'); const char *p;
return p != NULL ? p + 1 : name;
p = strrchr(name, '/');
return (p != NULL ? p + 1 : name);
} }
static struct utsname uts; static struct utsname uts;
@ -1696,11 +1698,11 @@ digest_phdr(const Elf_Phdr *phdr, int phnum, caddr_t entry, const char *path)
} }
if (nsegs < 1) { if (nsegs < 1) {
_rtld_error("%s: too few PT_LOAD segments", path); _rtld_error("%s: too few PT_LOAD segments", path);
return NULL; return (NULL);
} }
obj->entry = entry; obj->entry = entry;
return obj; return (obj);
} }
void void
@ -1761,9 +1763,9 @@ dlcheck(void *handle)
if (obj == NULL || obj->refcount == 0 || obj->dl_refcount == 0) { if (obj == NULL || obj->refcount == 0 || obj->dl_refcount == 0) {
_rtld_error("Invalid shared object handle %p", handle); _rtld_error("Invalid shared object handle %p", handle);
return NULL; return (NULL);
} }
return obj; return (obj);
} }
/* /*
@ -1777,7 +1779,7 @@ donelist_check(DoneList *dlp, const Obj_Entry *obj)
for (i = 0; i < dlp->num_used; i++) for (i = 0; i < dlp->num_used; i++)
if (dlp->objs[i] == obj) if (dlp->objs[i] == obj)
return true; return (true);
/* /*
* Our donelist allocation should always be sufficient. But if * Our donelist allocation should always be sufficient. But if
* our threads locking isn't working properly, more shared objects * our threads locking isn't working properly, more shared objects
@ -1786,7 +1788,7 @@ donelist_check(DoneList *dlp, const Obj_Entry *obj)
*/ */
if (dlp->num_used < dlp->num_alloc) if (dlp->num_used < dlp->num_alloc)
dlp->objs[dlp->num_used++] = obj; dlp->objs[dlp->num_used++] = obj;
return false; return (false);
} }
/* /*
@ -1806,7 +1808,7 @@ elf_hash(const char *name)
h ^= g >> 24; h ^= g >> 24;
h &= ~g; h &= ~g;
} }
return h; return (h);
} }
/* /*
@ -1975,10 +1977,10 @@ find_symdef(unsigned long symnum, const Obj_Entry *refobj,
* the cache. * the cache.
*/ */
if (symnum >= refobj->dynsymcount) if (symnum >= refobj->dynsymcount)
return NULL; /* Bad object */ return (NULL); /* Bad object */
if (cache != NULL && cache[symnum].sym != NULL) { if (cache != NULL && cache[symnum].sym != NULL) {
*defobj_out = cache[symnum].obj; *defobj_out = cache[symnum].obj;
return cache[symnum].sym; return (cache[symnum].sym);
} }
ref = refobj->symtab + symnum; ref = refobj->symtab + symnum;
@ -2035,7 +2037,7 @@ find_symdef(unsigned long symnum, const Obj_Entry *refobj,
_rtld_error("%s: Undefined symbol \"%s%s%s\"", refobj->path, name, _rtld_error("%s: Undefined symbol \"%s%s%s\"", refobj->path, name,
ve != NULL ? "@" : "", ve != NULL ? ve->name : ""); ve != NULL ? "@" : "", ve != NULL ? ve->name : "");
} }
return def; return (def);
} }
/* /*
@ -2736,7 +2738,7 @@ load_object(const char *name, int fd_u, const Obj_Entry *refobj, int flags)
_rtld_error("Cannot fstat \"%s\"", printable_path(path)); _rtld_error("Cannot fstat \"%s\"", printable_path(path));
close(fd); close(fd);
free(path); free(path);
return NULL; return (NULL);
} }
TAILQ_FOREACH(obj, &obj_list, next) { TAILQ_FOREACH(obj, &obj_list, next) {
if (obj->marker || obj->doomed) if (obj->marker || obj->doomed)
@ -2748,7 +2750,7 @@ load_object(const char *name, int fd_u, const Obj_Entry *refobj, int flags)
object_add_name(obj, name); object_add_name(obj, name);
free(path); free(path);
close(fd); close(fd);
return obj; return (obj);
} }
if (flags & RTLD_LO_NOLOAD) { if (flags & RTLD_LO_NOLOAD) {
free(path); free(path);
@ -2762,7 +2764,7 @@ load_object(const char *name, int fd_u, const Obj_Entry *refobj, int flags)
free(path); free(path);
close(fd); close(fd);
return obj; return (obj);
} }
static Obj_Entry * static Obj_Entry *
@ -2787,7 +2789,7 @@ do_load_object(int fd, const char *name, char *path, struct stat *sbp,
dbg("loading \"%s\"", printable_path(path)); dbg("loading \"%s\"", printable_path(path));
obj = map_object(fd, printable_path(path), sbp); obj = map_object(fd, printable_path(path), sbp);
if (obj == NULL) if (obj == NULL)
return NULL; return (NULL);
/* /*
* If DT_SONAME is present in the object, digest_dynamic2 already * If DT_SONAME is present in the object, digest_dynamic2 already
@ -2847,7 +2849,7 @@ obj_from_addr(const void *addr)
if (addr < (void *)(obj->mapbase + obj->mapsize)) if (addr < (void *)(obj->mapbase + obj->mapsize))
return obj; return obj;
} }
return NULL; return (NULL);
} }
static void static void
@ -3049,7 +3051,7 @@ objlist_find(Objlist *list, const Obj_Entry *obj)
STAILQ_FOREACH(elm, list, link) STAILQ_FOREACH(elm, list, link)
if (elm->obj == obj) if (elm->obj == obj)
return elm; return elm;
return NULL; return (NULL);
} }
static void static void
@ -3429,7 +3431,7 @@ search_library_path(const char *name, const char *path,
struct try_library_args arg; struct try_library_args arg;
if (path == NULL) if (path == NULL)
return NULL; return (NULL);
arg.name = name; arg.name = name;
arg.namelen = strlen(name); arg.namelen = strlen(name);
@ -3530,7 +3532,7 @@ dlclose_locked(void *handle, RtldLockState *lockstate)
root = dlcheck(handle); root = dlcheck(handle);
if (root == NULL) if (root == NULL)
return -1; return (-1);
LD_UTRACE(UTRACE_DLCLOSE_START, handle, NULL, 0, root->dl_refcount, LD_UTRACE(UTRACE_DLCLOSE_START, handle, NULL, 0, root->dl_refcount,
root->path); root->path);
@ -3554,7 +3556,7 @@ dlclose_locked(void *handle, RtldLockState *lockstate)
unref_dag(root); unref_dag(root);
LD_UTRACE(UTRACE_DLCLOSE_STOP, handle, NULL, 0, 0, NULL); LD_UTRACE(UTRACE_DLCLOSE_STOP, handle, NULL, 0, 0, NULL);
return 0; return (0);
} }
char * char *
@ -3772,7 +3774,7 @@ dlopen_object(const char *name, int fd, Obj_Entry *refobj, int lo_flags,
objlist_clear(&initlist); objlist_clear(&initlist);
if (lockstate == &mlockstate) if (lockstate == &mlockstate)
lock_release(rtld_bind_lock, lockstate); lock_release(rtld_bind_lock, lockstate);
return obj; return (obj);
trace: trace:
trace_loaded_objects(obj); trace_loaded_objects(obj);
if (lockstate == &mlockstate) if (lockstate == &mlockstate)
@ -3811,7 +3813,7 @@ do_dlsym(void *handle, const char *name, void *retaddr, const Ver_Entry *ve,
_rtld_error("Cannot determine caller's shared object"); _rtld_error("Cannot determine caller's shared object");
lock_release(rtld_bind_lock, &lockstate); lock_release(rtld_bind_lock, &lockstate);
LD_UTRACE(UTRACE_DLSYM_STOP, handle, NULL, 0, 0, name); LD_UTRACE(UTRACE_DLSYM_STOP, handle, NULL, 0, 0, name);
return NULL; return (NULL);
} }
if (handle == NULL) { /* Just the caller's shared object. */ if (handle == NULL) { /* Just the caller's shared object. */
res = symlook_obj(&req, obj); res = symlook_obj(&req, obj);
@ -3864,7 +3866,7 @@ do_dlsym(void *handle, const char *name, void *retaddr, const Ver_Entry *ve,
if ((obj = dlcheck(handle)) == NULL) { if ((obj = dlcheck(handle)) == NULL) {
lock_release(rtld_bind_lock, &lockstate); lock_release(rtld_bind_lock, &lockstate);
LD_UTRACE(UTRACE_DLSYM_STOP, handle, NULL, 0, 0, name); LD_UTRACE(UTRACE_DLSYM_STOP, handle, NULL, 0, 0, name);
return NULL; return (NULL);
} }
donelist_init(&donelist); donelist_init(&donelist);
@ -3924,14 +3926,14 @@ do_dlsym(void *handle, const char *name, void *retaddr, const Ver_Entry *ve,
ve != NULL ? ve->name : ""); ve != NULL ? ve->name : "");
lock_release(rtld_bind_lock, &lockstate); lock_release(rtld_bind_lock, &lockstate);
LD_UTRACE(UTRACE_DLSYM_STOP, handle, NULL, 0, 0, name); LD_UTRACE(UTRACE_DLSYM_STOP, handle, NULL, 0, 0, name);
return NULL; return (NULL);
} }
void * void *
dlsym(void *handle, const char *name) dlsym(void *handle, const char *name)
{ {
return do_dlsym(handle, name, __builtin_return_address(0), NULL, return (do_dlsym(handle, name, __builtin_return_address(0), NULL,
SYMLOOK_DLSYM); SYMLOOK_DLSYM));
} }
dlfunc_t dlfunc_t
@ -3956,8 +3958,8 @@ dlvsym(void *handle, const char *name, const char *version)
ventry.file = NULL; ventry.file = NULL;
ventry.hash = elf_hash(version); ventry.hash = elf_hash(version);
ventry.flags= 0; ventry.flags= 0;
return do_dlsym(handle, name, __builtin_return_address(0), &ventry, return (do_dlsym(handle, name, __builtin_return_address(0), &ventry,
SYMLOOK_DLSYM); SYMLOOK_DLSYM));
} }
int int
@ -3992,7 +3994,7 @@ dladdr(const void *addr, Dl_info *info)
if (obj == NULL) { if (obj == NULL) {
_rtld_error("No shared object contains address"); _rtld_error("No shared object contains address");
lock_release(rtld_bind_lock, &lockstate); lock_release(rtld_bind_lock, &lockstate);
return 0; return (0);
} }
info->dli_fname = obj->path; info->dli_fname = obj->path;
info->dli_fbase = obj->mapbase; info->dli_fbase = obj->mapbase;
@ -4031,7 +4033,7 @@ dladdr(const void *addr, Dl_info *info)
break; break;
} }
lock_release(rtld_bind_lock, &lockstate); lock_release(rtld_bind_lock, &lockstate);
return 1; return (1);
} }
int int
@ -5258,8 +5260,8 @@ allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign)
dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr)); dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr));
segbase = (Elf_Addr)(tls + roundup(tls_static_space, ralign)); segbase = (Elf_Addr)(tls + roundup(tls_static_space, ralign));
((Elf_Addr*)segbase)[0] = segbase; ((Elf_Addr *)segbase)[0] = segbase;
((Elf_Addr*)segbase)[1] = (Elf_Addr) dtv; ((Elf_Addr *)segbase)[1] = (Elf_Addr) dtv;
dtv[0] = tls_dtv_generation; dtv[0] = tls_dtv_generation;
dtv[1] = tls_max_index; dtv[1] = tls_max_index;
@ -5270,18 +5272,19 @@ allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign)
*/ */
oldsegbase = (Elf_Addr) oldtls; oldsegbase = (Elf_Addr) oldtls;
memcpy((void *)(segbase - tls_static_space), memcpy((void *)(segbase - tls_static_space),
(const void *)(oldsegbase - tls_static_space), (const void *)(oldsegbase - tls_static_space),
tls_static_space); tls_static_space);
/* /*
* If any dynamic TLS blocks have been created tls_get_addr(), * If any dynamic TLS blocks have been created tls_get_addr(),
* move them over. * move them over.
*/ */
olddtv = ((Elf_Addr**)oldsegbase)[1]; olddtv = ((Elf_Addr **)oldsegbase)[1];
for (i = 0; i < olddtv[1]; i++) { for (i = 0; i < olddtv[1]; i++) {
if (olddtv[i+2] < oldsegbase - size || olddtv[i+2] > oldsegbase) { if (olddtv[i + 2] < oldsegbase - size ||
dtv[i+2] = olddtv[i+2]; olddtv[i + 2] > oldsegbase) {
olddtv[i+2] = 0; dtv[i + 2] = olddtv[i + 2];
olddtv[i + 2] = 0;
} }
} }
@ -5289,23 +5292,23 @@ allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign)
* We assume that this block was the one we created with * We assume that this block was the one we created with
* allocate_initial_tls(). * allocate_initial_tls().
*/ */
free_tls(oldtls, 2*sizeof(Elf_Addr), sizeof(Elf_Addr)); free_tls(oldtls, 2 * sizeof(Elf_Addr), sizeof(Elf_Addr));
} else { } else {
for (obj = objs; obj != NULL; obj = TAILQ_NEXT(obj, next)) { for (obj = objs; obj != NULL; obj = TAILQ_NEXT(obj, next)) {
if (obj->marker || obj->tlsoffset == 0) if (obj->marker || obj->tlsoffset == 0)
continue; continue;
addr = segbase - obj->tlsoffset; addr = segbase - obj->tlsoffset;
memset((void*)(addr + obj->tlsinitsize), memset((void *)(addr + obj->tlsinitsize),
0, obj->tlssize - obj->tlsinitsize); 0, obj->tlssize - obj->tlsinitsize);
if (obj->tlsinit) { if (obj->tlsinit) {
memcpy((void*) addr, obj->tlsinit, obj->tlsinitsize); memcpy((void *)addr, obj->tlsinit, obj->tlsinitsize);
obj->static_tls_copied = true; obj->static_tls_copied = true;
} }
dtv[obj->tlsindex + 1] = addr; dtv[obj->tlsindex + 1] = addr;
} }
} }
return (void*) segbase; return ((void *)segbase);
} }
void void
@ -5325,18 +5328,19 @@ free_tls(void *tls, size_t tcbsize __unused, size_t tcbalign)
ralign = tls_static_max_align; ralign = tls_static_max_align;
size = roundup(tls_static_space, ralign); size = roundup(tls_static_space, ralign);
dtv = ((Elf_Addr**)tls)[1]; dtv = ((Elf_Addr **)tls)[1];
dtvsize = dtv[1]; dtvsize = dtv[1];
tlsend = (Elf_Addr) tls; tlsend = (Elf_Addr)tls;
tlsstart = tlsend - size; tlsstart = tlsend - size;
for (i = 0; i < dtvsize; i++) { for (i = 0; i < dtvsize; i++) {
if (dtv[i + 2] != 0 && (dtv[i + 2] < tlsstart || dtv[i + 2] > tlsend)) { if (dtv[i + 2] != 0 && (dtv[i + 2] < tlsstart ||
free_aligned((void *)dtv[i + 2]); dtv[i + 2] > tlsend)) {
free_aligned((void *)dtv[i + 2]);
} }
} }
free_aligned((void *)tlsstart); free_aligned((void *)tlsstart);
free((void*) dtv); free((void *)dtv);
} }
#endif /* TLS_VARIANT_II */ #endif /* TLS_VARIANT_II */
@ -5373,11 +5377,11 @@ allocate_tls_offset(Obj_Entry *obj)
size_t off; size_t off;
if (obj->tls_done) if (obj->tls_done)
return true; return (true);
if (obj->tlssize == 0) { if (obj->tlssize == 0) {
obj->tls_done = true; obj->tls_done = true;
return true; return (true);
} }
if (tls_last_offset == 0) if (tls_last_offset == 0)
@ -5400,7 +5404,7 @@ allocate_tls_offset(Obj_Entry *obj)
*/ */
if (tls_static_space != 0) { if (tls_static_space != 0) {
if (off > tls_static_space) if (off > tls_static_space)
return false; return (false);
} else if (obj->tlsalign > tls_static_max_align) { } else if (obj->tlsalign > tls_static_max_align) {
tls_static_max_align = obj->tlsalign; tls_static_max_align = obj->tlsalign;
} }
@ -5409,7 +5413,7 @@ allocate_tls_offset(Obj_Entry *obj)
tls_last_size = obj->tlssize; tls_last_size = obj->tlssize;
obj->tls_done = true; obj->tls_done = true;
return true; return (true);
} }
void void
@ -5490,7 +5494,7 @@ locate_dependency(const Obj_Entry *obj, const char *name)
STAILQ_FOREACH(entry, &list_main, link) { STAILQ_FOREACH(entry, &list_main, link) {
if (object_match_name(entry->obj, name)) if (object_match_name(entry->obj, name))
return entry->obj; return (entry->obj);
} }
for (needed = obj->needed; needed != NULL; needed = needed->next) { for (needed = obj->needed; needed != NULL; needed = needed->next) {
@ -5655,7 +5659,7 @@ rtld_verify_object_versions(Obj_Entry *obj)
break; break;
vn = (const Elf_Verneed *)((const char *)vn + vn->vn_next); vn = (const Elf_Verneed *)((const char *)vn + vn->vn_next);
} }
return 0; return (0);
} }
static int static int
@ -5680,7 +5684,7 @@ rtld_verify_versions(const Objlist *objlist)
} }
if (rc == 0 || ld_tracing != NULL) if (rc == 0 || ld_tracing != NULL)
rc = rtld_verify_object_versions(&obj_rtld); rc = rtld_verify_object_versions(&obj_rtld);
return rc; return (rc);
} }
const Ver_Entry * const Ver_Entry *
@ -5694,10 +5698,10 @@ fetch_ventry(const Obj_Entry *obj, unsigned long symnum)
_rtld_error("%s: symbol %s has wrong verneed value %d", _rtld_error("%s: symbol %s has wrong verneed value %d",
obj->path, obj->strtab + symnum, vernum); obj->path, obj->strtab + symnum, vernum);
} else if (obj->vertab[vernum].hash != 0) { } else if (obj->vertab[vernum].hash != 0) {
return &obj->vertab[vernum]; return (&obj->vertab[vernum]);
} }
} }
return NULL; return (NULL);
} }
int int