aboutsummaryrefslogtreecommitdiff
path: root/lib/libelf
diff options
context:
space:
mode:
authorKai Wang <kaiw@FreeBSD.org>2010-09-04 12:19:19 +0000
committerKai Wang <kaiw@FreeBSD.org>2010-09-04 12:19:19 +0000
commit0dadf6e184e7ea8a6eb57373adee19eef620b147 (patch)
treed403fa7501a93544cfca1db2c114bac653a0eabe /lib/libelf
parentc38316f849120f490206b1b02e67667d14e00bb4 (diff)
Notes
Diffstat (limited to 'lib/libelf')
-rw-r--r--lib/libelf/elf.34
-rw-r--r--lib/libelf/elf_update.c16
-rw-r--r--lib/libelf/gelf_ehdr.c4
-rw-r--r--lib/libelf/gelf_phdr.c4
-rw-r--r--lib/libelf/gelf_shdr.c4
5 files changed, 17 insertions, 15 deletions
diff --git a/lib/libelf/elf.3 b/lib/libelf/elf.3
index c649efe72be4..54d6d75437bc 100644
--- a/lib/libelf/elf.3
+++ b/lib/libelf/elf.3
@@ -36,8 +36,8 @@
.Sh DESCRIPTION
The
.Lb libelf
-library provides functions that allow an application to read and
-manipulate ELF object files, and to read
+provides functions that allow an application to read and manipulate
+ELF object files, and to read
.Xr ar 1
archives.
The library allows the manipulation of ELF objects in a byte ordering
diff --git a/lib/libelf/elf_update.c b/lib/libelf/elf_update.c
index 3c7cb0a54f61..a4290365d2e9 100644
--- a/lib/libelf/elf_update.c
+++ b/lib/libelf/elf_update.c
@@ -422,8 +422,8 @@ _libelf_resync_elf(Elf *e)
(E)->e_ident[EI_VERSION] = (V); \
(E)->e_ehsize = _libelf_fsize(ELF_T_EHDR, (EC), (V), \
(size_t) 1); \
- (E)->e_phentsize = _libelf_fsize(ELF_T_PHDR, (EC), (V), \
- (size_t) 1); \
+ (E)->e_phentsize = (phnum == 0) ? 0 : _libelf_fsize( \
+ ELF_T_PHDR, (EC), (V), (size_t) 1); \
(E)->e_shentsize = _libelf_fsize(ELF_T_SHDR, (EC), (V), \
(size_t) 1); \
} while (0)
@@ -534,22 +534,24 @@ _libelf_write_scn(Elf *e, char *nf, Elf_Scn *s, off_t rc)
int ec;
size_t fsz, msz, nobjects;
uint32_t sh_type;
- uint64_t sh_off;
+ uint64_t sh_off, sh_size;
int elftype;
Elf_Data *d, dst;
- if ((ec = e->e_class) == ELFCLASS32)
+ if ((ec = e->e_class) == ELFCLASS32) {
sh_type = s->s_shdr.s_shdr32.sh_type;
- else
+ sh_size = (uint64_t) s->s_shdr.s_shdr32.sh_size;
+ } else {
sh_type = s->s_shdr.s_shdr64.sh_type;
+ sh_size = s->s_shdr.s_shdr64.sh_size;
+ }
/*
* Ignore sections that do not allocate space in the file.
*/
- if (sh_type == SHT_NOBITS || sh_type == SHT_NULL)
+ if (sh_type == SHT_NOBITS || sh_type == SHT_NULL || sh_size == 0)
return (rc);
-
elftype = _libelf_xlate_shtype(sh_type);
assert(elftype >= ELF_T_FIRST && elftype <= ELF_T_LAST);
diff --git a/lib/libelf/gelf_ehdr.c b/lib/libelf/gelf_ehdr.c
index 4d7698af9351..f3e8c76f9e33 100644
--- a/lib/libelf/gelf_ehdr.c
+++ b/lib/libelf/gelf_ehdr.c
@@ -137,6 +137,8 @@ gelf_update_ehdr(Elf *e, GElf_Ehdr *s)
if ((ehdr = _libelf_ehdr(e, ec, 0)) == NULL)
return (0);
+ (void) elf_flagehdr(e, ELF_C_SET, ELF_F_DIRTY);
+
if (ec == ELFCLASS64) {
eh64 = (Elf64_Ehdr *) ehdr;
*eh64 = *s;
@@ -161,7 +163,5 @@ gelf_update_ehdr(Elf *e, GElf_Ehdr *s)
eh32->e_shnum = s->e_shnum;
eh32->e_shstrndx = s->e_shstrndx;
- (void) elf_flagehdr(e, ELF_C_SET, ELF_F_DIRTY);
-
return (1);
}
diff --git a/lib/libelf/gelf_phdr.c b/lib/libelf/gelf_phdr.c
index 6d82d7fdb4a6..654b99db3ebc 100644
--- a/lib/libelf/gelf_phdr.c
+++ b/lib/libelf/gelf_phdr.c
@@ -155,6 +155,8 @@ gelf_update_phdr(Elf *e, int ndx, GElf_Phdr *s)
return (0);
}
+ (void) elf_flagphdr(e, ELF_C_SET, ELF_F_DIRTY);
+
if (ec == ELFCLASS64) {
ph64 = e->e_u.e_elf.e_phdr.e_phdr64 + ndx;
*ph64 = *s;
@@ -172,7 +174,5 @@ gelf_update_phdr(Elf *e, int ndx, GElf_Phdr *s)
LIBELF_COPY_U32(ph32, s, p_memsz);
LIBELF_COPY_U32(ph32, s, p_align);
- (void) elf_flagphdr(e, ELF_C_SET, ELF_F_DIRTY);
-
return (1);
}
diff --git a/lib/libelf/gelf_shdr.c b/lib/libelf/gelf_shdr.c
index efe98b8b6757..3f8f56251a84 100644
--- a/lib/libelf/gelf_shdr.c
+++ b/lib/libelf/gelf_shdr.c
@@ -107,6 +107,8 @@ gelf_update_shdr(Elf_Scn *scn, GElf_Shdr *s)
return (0);
}
+ (void) elf_flagscn(scn, ELF_C_SET, ELF_F_DIRTY);
+
if (ec == ELFCLASS64) {
scn->s_shdr.s_shdr64 = *s;
return (1);
@@ -125,7 +127,5 @@ gelf_update_shdr(Elf_Scn *scn, GElf_Shdr *s)
LIBELF_COPY_U32(sh32, s, sh_addralign);
LIBELF_COPY_U32(sh32, s, sh_entsize);
- (void) elf_flagscn(scn, ELF_C_SET, ELF_F_DIRTY);
-
return (1);
}