* [PATCH] Move nested functions in libelf.
@ 2015-10-14 2:06 Chih-Hung Hsieh
0 siblings, 0 replies; 2+ messages in thread
From: Chih-Hung Hsieh @ 2015-10-14 2:06 UTC (permalink / raw)
To: elfutils-devel
[-- Attachment #1: Type: text/plain, Size: 5340 bytes --]
* Move nested functions to file scope
in libelf/elf_begin.c and elf32_updatefile.c
to compile with clang.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
---
libelf/ChangeLog | 7 +++++++
libelf/elf32_updatefile.c | 50 +++++++++++++++++++++++++----------------------
libelf/elf_begin.c | 30 ++++++++++++++--------------
3 files changed, 49 insertions(+), 38 deletions(-)
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index af2438b..983b16b 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,10 @@
+2015-10-13 Chih-Hung Hsieh <chh@google.com>
+
+ * elf32_updatefile.c (__elfw2(LIBELFBITS,updatemmap)): Move nested
+ function 'fill_mmap' to file scope.
+ * elf_begin.c (elf_begin): Move nested function 'lock_dup_elf'
+ to file scope.
+
2015-10-05 Mark Wielaard <mjw@redhat.com>
* elf_update.c (write_file): Only use posix_fallocate when using
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index 832f852..0909219 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;
diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index 213b5c0..f26119c 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -1039,6 +1039,19 @@ write_file (int fd, Elf_Cmd cmd)
return result;
}
+/* Lock if necessary before dup an archive. */
+static inline Elf *
+lock_dup_elf (int fildes, Elf_Cmd cmd, Elf *ref)
+{
+ /* We need wrlock to dup an archive. */
+ if (ref->kind == ELF_K_AR)
+ {
+ rwlock_unlock (ref->lock);
+ rwlock_wrlock (ref->lock);
+ }
+ /* Duplicate the descriptor. */
+ return dup_elf (fildes, cmd, ref);
+}
/* Return a descriptor for the file belonging to FILDES. */
Elf *
@@ -1063,19 +1076,6 @@ elf_begin (int fildes, Elf_Cmd cmd, Elf *ref)
return NULL;
}
- Elf *lock_dup_elf (void)
- {
- /* We need wrlock to dup an archive. */
- if (ref->kind == ELF_K_AR)
- {
- rwlock_unlock (ref->lock);
- rwlock_wrlock (ref->lock);
- }
-
- /* Duplicate the descriptor. */
- return dup_elf (fildes, cmd, ref);
- }
-
switch (cmd)
{
case ELF_C_NULL:
@@ -1096,7 +1096,7 @@ elf_begin (int fildes, Elf_Cmd cmd, Elf *ref)
case ELF_C_READ:
case ELF_C_READ_MMAP:
if (ref != NULL)
- retval = lock_dup_elf ();
+ retval = lock_dup_elf (fildes, cmd, ref);
else
/* Create descriptor for existing file. */
retval = read_file (fildes, 0, ~((size_t) 0), cmd, NULL);
@@ -1117,7 +1117,7 @@ elf_begin (int fildes, Elf_Cmd cmd, Elf *ref)
retval = NULL;
}
else
- retval = lock_dup_elf ();
+ retval = lock_dup_elf (fildes, cmd, ref);
}
else
/* Create descriptor for existing file. */
--
2.6.0.rc2.230.g3dd15c0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Move nested functions in libelf.
@ 2015-10-22 21:00 Mark Wielaard
0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2015-10-22 21:00 UTC (permalink / raw)
To: elfutils-devel
[-- Attachment #1: Type: text/plain, Size: 362 bytes --]
On Tue, Oct 13, 2015 at 07:06:21PM -0700, Chih-Hung Hsieh wrote:
> +2015-10-13 Chih-Hung Hsieh <chh@google.com>
> +
> + * elf32_updatefile.c (__elfw2(LIBELFBITS,updatemmap)): Move nested
> + function 'fill_mmap' to file scope.
> + * elf_begin.c (elf_begin): Move nested function 'lock_dup_elf'
> + to file scope.
Pushed to master.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-10-22 21:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-14 2:06 [PATCH] Move nested functions in libelf Chih-Hung Hsieh
2015-10-22 21:00 Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).