Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/gen - don't compile unreachable code.
details: https://anonhg.NetBSD.org/src/rev/aa75bb096614
branches: trunk
changeset: 778268:aa75bb096614
user: christos <christos%NetBSD.org@localhost>
date: Wed Mar 21 02:18:14 2012 +0000
description:
- don't compile unreachable code.
- convert uintmax_t to uintptr_t
diffstat:
lib/libc/gen/nlist_elf32.c | 47 ++++++++++++++++++++++++++-------------------
1 files changed, 27 insertions(+), 20 deletions(-)
diffs (122 lines):
diff -r 3f61ac114340 -r aa75bb096614 lib/libc/gen/nlist_elf32.c
--- a/lib/libc/gen/nlist_elf32.c Wed Mar 21 00:38:34 2012 +0000
+++ b/lib/libc/gen/nlist_elf32.c Wed Mar 21 02:18:14 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nlist_elf32.c,v 1.34 2012/03/20 16:36:05 matt Exp $ */
+/* $NetBSD: nlist_elf32.c,v 1.35 2012/03/21 02:18:14 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou
@@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: nlist_elf32.c,v 1.34 2012/03/20 16:36:05 matt Exp $");
+__RCSID("$NetBSD: nlist_elf32.c,v 1.35 2012/03/21 02:18:14 christos Exp $");
#endif /* LIBC_SCCS and not lint */
/* If not included by nlist_elf64.c, ELFSIZE won't be defined. */
@@ -76,29 +76,32 @@
ELFNAMEEND(__fdnlist)(int fd, struct nlist *list)
{
struct stat st;
- struct nlist *p;
- char *mappedfile, *strtab;
- size_t mappedsize;
- Elf_Ehdr *ehdrp, ehdr;
- Elf_Shdr *shdrp, *symshdrp, *symstrshdrp;
- Elf_Sym *symp;
- Elf_Off shdr_off;
- Elf_Word shdr_size;
+ Elf_Ehdr ehdr;
+#if _LP64 || ELFSIZE == 32
#if (ELFSIZE == 32)
Elf32_Half nshdr;
#elif (ELFSIZE == 64)
Elf64_Word nshdr;
#endif
- size_t i, nsyms;
- int rv, nent;
+ /* Only support 64+32 mode on LP64; no support for 64 mode on ILP32 */
+ Elf_Ehdr *ehdrp;
+ Elf_Shdr *shdrp, *symshdrp, *symstrshdrp;
+ Elf_Sym *symp;
+ Elf_Off shdr_off;
+ Elf_Word shdr_size;
+ struct nlist *p;
+ char *mappedfile, *strtab;
+ size_t mappedsize, nsyms;
+ int nent;
+#endif
+ int rv;
+ size_t i;
_DIAGASSERT(fd != -1);
_DIAGASSERT(list != NULL);
rv = -1;
- symshdrp = symstrshdrp = NULL;
-
/*
* If we can't fstat() the file, something bad is going on.
*/
@@ -134,7 +137,10 @@
default:
BAD;
}
+#if _LP64 || ELFSIZE == 32
+ symshdrp = symstrshdrp = NULL;
+ /* Only support 64+32 mode on LP64; no support for 64 mode on ILP32 */
if (S_ISCHR(st.st_mode)) {
const char *nlistname;
struct ksyms_gsymbol kg;
@@ -155,7 +161,7 @@
kg.kg_name = nlistname;
kg.kg_sym = &sym;
if (ioctl(fd, KIOCGSYMBOL, &kg) == 0) {
- p->n_value = sym.st_value;
+ p->n_value = (uintptr_t)sym.st_value;
switch (ELF_ST_TYPE(sym.st_info)) {
case STT_NOTYPE:
p->n_type = N_UNDF;
@@ -211,7 +217,7 @@
if (check(shdr_off, shdr_size) ||
(sizeof *shdrp != ehdrp->e_shentsize))
BADUNMAP;
- shdrp = (Elf_Shdr *)(void *)&mappedfile[shdr_off];
+ shdrp = (void *)&mappedfile[(size_t)shdr_off];
for (i = 0; i < nshdr; i++) {
if (shdrp[i].sh_type == SHT_SYMTAB) {
@@ -230,9 +236,9 @@
if (check(symstrshdrp->sh_offset, symstrshdrp->sh_size))
BADUNMAP;
- symp = (Elf_Sym *)(void *)&mappedfile[symshdrp->sh_offset];
- nsyms = symshdrp->sh_size / sizeof(*symp);
- strtab = &mappedfile[symstrshdrp->sh_offset];
+ symp = (void *)&mappedfile[(size_t)symshdrp->sh_offset];
+ nsyms = (size_t)(symshdrp->sh_size / sizeof(*symp));
+ strtab = &mappedfile[(size_t)symstrshdrp->sh_offset];
/*
* Clean out any left-over information for all valid entries.
@@ -267,7 +273,7 @@
/*
* Translate (roughly) from ELF to nlist
*/
- p->n_value = symp[i].st_value;
+ p->n_value = (uintptr_t)symp[i].st_value;
switch (ELF_ST_TYPE(symp[i].st_info)) {
case STT_NOTYPE:
p->n_type = N_UNDF;
@@ -302,6 +308,7 @@
rv = nent;
unmap:
munmap(mappedfile, mappedsize);
+#endif /* _LP64 || ELFSIZE == 32 */
out:
return (rv);
}
Home |
Main Index |
Thread Index |
Old Index