summaryrefslogtreecommitdiffstats
path: root/libelf/elf32_updatefile.c
diff options
context:
space:
mode:
Diffstat (limited to 'libelf/elf32_updatefile.c')
-rw-r--r--libelf/elf32_updatefile.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index 832f852d..09092197 100644
--- a/libelf/elf32_updatefile.c
+++ b/libelf/elf32_updatefile.c
@@ -101,6 +101,29 @@ sort_sections (Elf_Scn **scns, Elf_ScnList *list)
}
+static inline void
+fill_mmap (size_t offset, char *last_position, char *scn_start,
+ char *const shdr_start, char *const shdr_end)
+{
+ size_t written = 0;
+
+ if (last_position < shdr_start)
+ {
+ written = MIN (scn_start + offset - last_position,
+ shdr_start - last_position);
+
+ memset (last_position, __libelf_fill_byte, written);
+ }
+
+ if (last_position + written != scn_start + offset
+ && shdr_end < scn_start + offset)
+ {
+ char *fill_start = MAX (shdr_end, scn_start);
+ memset (fill_start, __libelf_fill_byte,
+ scn_start + offset - fill_start);
+ }
+}
+
int
internal_function
__elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
@@ -303,27 +326,6 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
Elf_Data_List *dl = &scn->data_list;
bool scn_changed = false;
- void fill_mmap (size_t offset)
- {
- size_t written = 0;
-
- if (last_position < shdr_start)
- {
- written = MIN (scn_start + offset - last_position,
- shdr_start - last_position);
-
- memset (last_position, __libelf_fill_byte, written);
- }
-
- if (last_position + written != scn_start + offset
- && shdr_end < scn_start + offset)
- {
- char *fill_start = MAX (shdr_end, scn_start);
- memset (fill_start, __libelf_fill_byte,
- scn_start + offset - fill_start);
- }
- }
-
if (scn->data_list_rear != NULL)
do
{
@@ -338,7 +340,8 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
|| ((scn->flags | dl->flags | elf->flags)
& ELF_F_DIRTY) != 0))
{
- fill_mmap (dl->data.d.d_off);
+ fill_mmap (dl->data.d.d_off, last_position, scn_start,
+ shdr_start, shdr_end);
last_position = scn_start + dl->data.d.d_off;
}
@@ -390,7 +393,8 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum)
/* If the previous section (or the ELF/program
header) changed we might have to fill the gap. */
if (scn_start > last_position && previous_scn_changed)
- fill_mmap (0);
+ fill_mmap (0, last_position, scn_start,
+ shdr_start, shdr_end);
/* We have to trust the existing section header information. */
last_position = scn_start + shdr->sh_size;