This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[COMMITTED PATCH] Use ElfW(Off) rather than off_t for offsets within ELF files.
- From: Roland McGrath <roland at hack dot frob dot com>
- To: libc-alpha at sourceware dot org
- Date: Tue, 2 Oct 2012 16:03:27 -0700 (PDT)
- Subject: [COMMITTED PATCH] Use ElfW(Off) rather than off_t for offsets within ELF files.
On configurations where off_t is larger than ElfW(Off), there was a warning
about casting to a pointer from a larger integer type in this line:
l->l_phdr = (void *) (c->mapstart + header->e_phoff - c->mapoff);
Since c->mapoff was off_t, it gave the whole expression a 64-bit type.
There's no need for mapoff to be off_t, since it only ever holds values
computed as ElfW(Off) anyway. Using ElfW(Off) instead saves a little
stack space as well as avoiding that warning.
Thanks,
Roland
2012-10-02 Roland McGrath <roland@hack.frob.com>
* elf/dl-load.c (_dl_map_object_from_fd: struct loadcmd):
Make 'mapoff' field ElfW(Off) rather than off_t.
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 7bf0c12..ea31417 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1090,7 +1090,7 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
struct loadcmd
{
ElfW(Addr) mapstart, mapend, dataend, allocend;
- off_t mapoff;
+ ElfW(Off) mapoff;
int prot;
} loadcmds[l->l_phnum], *c;
size_t nloadcmds = 0;
@@ -1347,7 +1347,7 @@ cannot allocate TLS data structures for initial thread");
l->l_text_end = l->l_addr + c->mapend;
if (l->l_phdr == 0
- && (ElfW(Off)) c->mapoff <= header->e_phoff
+ && c->mapoff <= header->e_phoff
&& ((size_t) (c->mapend - c->mapstart + c->mapoff)
>= header->e_phoff + header->e_phnum * sizeof (ElfW(Phdr))))
/* Found the program header in this segment. */