summaryrefslogtreecommitdiff
path: root/libelf/elf32_getshdr.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-02-05 07:25:33 +0000
committerUlrich Drepper <drepper@redhat.com>2007-02-05 07:25:33 +0000
commitaa915fd3d70b4cbe4581f9ec170d986c6ba35063 (patch)
tree7345e23df9aa4cfcab4eb9afafa0dac6ed16e182 /libelf/elf32_getshdr.c
parentce0bdb6ee5f977af9e565f2871ba2b1b37d162a5 (diff)
downloadelfutils-aa915fd3d70b4cbe4581f9ec170d986c6ba35063.tar.gz
propagate from branch 'com.redhat.elfutils.roland.pending' (head c44dcfac5b545aecb173fede31f34cb003be0173)
to branch 'com.redhat.elfutils' (head 4196d4e01486bdeb0c0632291881d1c6d7163fab)
Diffstat (limited to 'libelf/elf32_getshdr.c')
-rw-r--r--libelf/elf32_getshdr.c69
1 files changed, 39 insertions, 30 deletions
diff --git a/libelf/elf32_getshdr.c b/libelf/elf32_getshdr.c
index 4abd2c10..cafb1d4f 100644
--- a/libelf/elf32_getshdr.c
+++ b/libelf/elf32_getshdr.c
@@ -1,5 +1,5 @@
/* Return section header.
- Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Red Hat, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2007 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 1998.
@@ -105,7 +105,7 @@ elfw2(LIBELFBITS,getshdr) (scn)
goto out;
size_t size = shnum * sizeof (ElfW2(LIBELFBITS,Shdr));
- /* Allocate memory for the program headers. We know the number
+ /* Allocate memory for the section headers. We know the number
of entries from the ELF header. */
ElfW2(LIBELFBITS,Shdr) *shdr = elf->state.ELFW(elf,LIBELFBITS).shdr =
(ElfW2(LIBELFBITS,Shdr) *) malloc (size);
@@ -122,41 +122,50 @@ elfw2(LIBELFBITS,getshdr) (scn)
/* All the data is already mapped. If we could use it
directly this would already have happened. */
+ void *file_shdr = ((char *) elf->map_address
+ + elf->start_offset + ehdr->e_shoff);
+
assert (ehdr->e_ident[EI_DATA] != MY_ELFDATA
|| (! ALLOW_UNALIGNED
- && (((uintptr_t) elf->map_address + elf->start_offset
- + ehdr->e_shoff)
+ && ((uintptr_t) file_shdr
& (__alignof__ (ElfW2(LIBELFBITS,Shdr)) - 1)) != 0));
- /* Now copy the data and at the same time convert the byte
- order. */
- if (ALLOW_UNALIGNED
- || (((uintptr_t) elf->map_address + elf->start_offset
- + ehdr->e_shoff)
- & (__alignof__ (ElfW2(LIBELFBITS,Shdr)) - 1)) == 0)
- notcvt = (ElfW2(LIBELFBITS,Shdr) *)
- ((char *) elf->map_address
- + elf->start_offset + ehdr->e_shoff);
- else
+ /* Now copy the data and at the same time convert the byte order. */
+ if (ehdr->e_ident[EI_DATA] == MY_ELFDATA)
{
- notcvt = (ElfW2(LIBELFBITS,Shdr) *) alloca (size);
- memcpy (notcvt, ((char *) elf->map_address
- + elf->start_offset + ehdr->e_shoff),
- size);
+ assert (! ALLOW_UNALIGNED);
+ memcpy (shdr, file_shdr, size);
}
-
- for (size_t cnt = 0; cnt < shnum; ++cnt)
+ else
{
- CONVERT_TO (shdr[cnt].sh_name, notcvt[cnt].sh_name);
- CONVERT_TO (shdr[cnt].sh_type, notcvt[cnt].sh_type);
- CONVERT_TO (shdr[cnt].sh_flags, notcvt[cnt].sh_flags);
- CONVERT_TO (shdr[cnt].sh_addr, notcvt[cnt].sh_addr);
- CONVERT_TO (shdr[cnt].sh_offset, notcvt[cnt].sh_offset);
- CONVERT_TO (shdr[cnt].sh_size, notcvt[cnt].sh_size);
- CONVERT_TO (shdr[cnt].sh_link, notcvt[cnt].sh_link);
- CONVERT_TO (shdr[cnt].sh_info, notcvt[cnt].sh_info);
- CONVERT_TO (shdr[cnt].sh_addralign, notcvt[cnt].sh_addralign);
- CONVERT_TO (shdr[cnt].sh_entsize, notcvt[cnt].sh_entsize);
+ if (ALLOW_UNALIGNED
+ || ((uintptr_t) file_shdr
+ & (__alignof__ (ElfW2(LIBELFBITS,Shdr)) - 1)) == 0)
+ notcvt = (ElfW2(LIBELFBITS,Shdr) *)
+ ((char *) elf->map_address
+ + elf->start_offset + ehdr->e_shoff);
+ else
+ {
+ notcvt = (ElfW2(LIBELFBITS,Shdr) *) alloca (size);
+ memcpy (notcvt, ((char *) elf->map_address
+ + elf->start_offset + ehdr->e_shoff),
+ size);
+ }
+
+ for (size_t cnt = 0; cnt < shnum; ++cnt)
+ {
+ CONVERT_TO (shdr[cnt].sh_name, notcvt[cnt].sh_name);
+ CONVERT_TO (shdr[cnt].sh_type, notcvt[cnt].sh_type);
+ CONVERT_TO (shdr[cnt].sh_flags, notcvt[cnt].sh_flags);
+ CONVERT_TO (shdr[cnt].sh_addr, notcvt[cnt].sh_addr);
+ CONVERT_TO (shdr[cnt].sh_offset, notcvt[cnt].sh_offset);
+ CONVERT_TO (shdr[cnt].sh_size, notcvt[cnt].sh_size);
+ CONVERT_TO (shdr[cnt].sh_link, notcvt[cnt].sh_link);
+ CONVERT_TO (shdr[cnt].sh_info, notcvt[cnt].sh_info);
+ CONVERT_TO (shdr[cnt].sh_addralign,
+ notcvt[cnt].sh_addralign);
+ CONVERT_TO (shdr[cnt].sh_entsize, notcvt[cnt].sh_entsize);
+ }
}
}
else if (likely (elf->fildes != -1))