summaryrefslogtreecommitdiffstats
path: root/libelf/elf_getdata.c
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2015-11-20 00:12:37 +0100
committerMark Wielaard <mjw@redhat.com>2016-01-06 14:27:10 +0100
commit5ddb50af4a488fdec358570502cbe058acb8ae93 (patch)
tree050c8d623b4832395b39eeebc30ad8ad63e2f0cb /libelf/elf_getdata.c
parent0c32b6f086b9838fe4b7d93575068554d0c420f7 (diff)
downloadandroid_external_elfutils-5ddb50af4a488fdec358570502cbe058acb8ae93.tar.gz
android_external_elfutils-5ddb50af4a488fdec358570502cbe058acb8ae93.tar.bz2
android_external_elfutils-5ddb50af4a488fdec358570502cbe058acb8ae93.zip
libelf: Add elf32_getchdr, elf64_getchdr and gelf_getchdr.
Elf_Data of a compressed section has type ELF_T_CHDR. This type can be xlated to the file or memory representation. This will make sure the Chdr is in the correct endianess. The compressed data following the Chdr isn't translated. Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'libelf/elf_getdata.c')
-rw-r--r--libelf/elf_getdata.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/libelf/elf_getdata.c b/libelf/elf_getdata.c
index 9a567e51..bd1f0682 100644
--- a/libelf/elf_getdata.c
+++ b/libelf/elf_getdata.c
@@ -106,6 +106,7 @@ const uint_fast8_t __libelf_type_aligns[EV_NUM - 1][ELFCLASSNUM - 1][ELF_T_NUM]
[ELF_T_NHDR] = __alignof__ (ElfW2(Bits,Nhdr)), \
[ELF_T_GNUHASH] = __alignof__ (Elf32_Word), \
[ELF_T_AUXV] = __alignof__ (ElfW2(Bits,auxv_t)), \
+ [ELF_T_CHDR] = __alignof__ (ElfW2(Bits,Chdr)), \
}
[EV_CURRENT - 1] =
{
@@ -204,6 +205,7 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
Elf64_Off offset;
Elf64_Xword size;
Elf64_Xword align;
+ Elf64_Xword flags;
int type;
Elf *elf = scn->elf;
@@ -220,6 +222,7 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
size = shdr->sh_size;
type = shdr->sh_type;
align = shdr->sh_addralign;
+ flags = shdr->sh_flags;
}
else
{
@@ -234,6 +237,7 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
size = shdr->sh_size;
type = shdr->sh_type;
align = shdr->sh_addralign;
+ flags = shdr->sh_flags;
}
/* If the section has no data (for whatever reason), leave the `d_buf'
@@ -243,7 +247,10 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
/* First a test whether the section is valid at all. */
size_t entsize;
- if (type == SHT_HASH)
+ /* Compressed data has a header, but then compressed data. */
+ if ((flags & SHF_COMPRESSED) != 0)
+ entsize = 1;
+ else if (type == SHT_HASH)
{
GElf_Ehdr ehdr_mem;
GElf_Ehdr *ehdr = __gelf_getehdr_rdlock (elf, &ehdr_mem);
@@ -320,10 +327,15 @@ __libelf_set_rawdata_wrlock (Elf_Scn *scn)
}
scn->rawdata.d.d_size = size;
- /* Some broken ELF ABI for 64-bit machines use the wrong hash table
- entry size. See elf-knowledge.h for more information. */
- if (type == SHT_HASH && elf->class == ELFCLASS64)
+
+ /* Compressed data always has type ELF_T_CHDR regardless of the
+ section type. */
+ if ((flags & SHF_COMPRESSED) != 0)
+ scn->rawdata.d.d_type = ELF_T_CHDR;
+ else if (type == SHT_HASH && elf->class == ELFCLASS64)
{
+ /* Some broken ELF ABI for 64-bit machines use the wrong hash table
+ entry size. See elf-knowledge.h for more information. */
GElf_Ehdr ehdr_mem;
GElf_Ehdr *ehdr = __gelf_getehdr_rdlock (elf, &ehdr_mem);
scn->rawdata.d.d_type