svn commit: r212201 - stable/7/lib/libelf
Kai Wang
kaiw at FreeBSD.org
Sat Sep 4 12:19:26 UTC 2010
Author: kaiw
Date: Sat Sep 4 12:19:25 2010
New Revision: 212201
URL: http://svn.freebsd.org/changeset/base/212201
Log:
MFC r210325,r210326,r210328,r210349
r210325:
Bug fix: when updating headers using the gelf_update_*() functions,
the appropriate `dirty' bit needs to be set for both the Elf32 and
Elf64 case.
r210326:
Improve compatibility with other implementations of the ELF(3) API:
when an output file has no program headers, set the 'e_phentsize'
field of the ELF executable header to zero.
r210328:
Bug fix: permit the creation of zero-sized sections.
r210349:
Remove a redundant word.
Modified:
stable/7/lib/libelf/elf.3
stable/7/lib/libelf/elf_update.c
stable/7/lib/libelf/gelf_ehdr.c
stable/7/lib/libelf/gelf_phdr.c
stable/7/lib/libelf/gelf_shdr.c
Directory Properties:
stable/7/lib/libelf/ (props changed)
Modified: stable/7/lib/libelf/elf.3
==============================================================================
--- stable/7/lib/libelf/elf.3 Sat Sep 4 12:19:19 2010 (r212200)
+++ stable/7/lib/libelf/elf.3 Sat Sep 4 12:19:25 2010 (r212201)
@@ -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
Modified: stable/7/lib/libelf/elf_update.c
==============================================================================
--- stable/7/lib/libelf/elf_update.c Sat Sep 4 12:19:19 2010 (r212200)
+++ stable/7/lib/libelf/elf_update.c Sat Sep 4 12:19:25 2010 (r212201)
@@ -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_
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);
Modified: stable/7/lib/libelf/gelf_ehdr.c
==============================================================================
--- stable/7/lib/libelf/gelf_ehdr.c Sat Sep 4 12:19:19 2010 (r212200)
+++ stable/7/lib/libelf/gelf_ehdr.c Sat Sep 4 12:19:25 2010 (r212201)
@@ -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);
}
Modified: stable/7/lib/libelf/gelf_phdr.c
==============================================================================
--- stable/7/lib/libelf/gelf_phdr.c Sat Sep 4 12:19:19 2010 (r212200)
+++ stable/7/lib/libelf/gelf_phdr.c Sat Sep 4 12:19:25 2010 (r212201)
@@ -155,6 +155,8 @@ gelf_update_phdr(Elf *e, int ndx, GElf_P
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_P
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);
}
Modified: stable/7/lib/libelf/gelf_shdr.c
==============================================================================
--- stable/7/lib/libelf/gelf_shdr.c Sat Sep 4 12:19:19 2010 (r212200)
+++ stable/7/lib/libelf/gelf_shdr.c Sat Sep 4 12:19:25 2010 (r212201)
@@ -107,6 +107,8 @@ gelf_update_shdr(Elf_Scn *scn, GElf_Shdr
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
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);
}
More information about the svn-src-stable-7
mailing list