elf_clone, strip on archives

Roland McGrath roland at redhat.com
Wed Aug 5 20:05:36 UTC 2009


I'm really sure I understand the intent of elf_clone, and it does not have
comments that make anything any more clear.  Solaris does not have this
interface.  Is it your invention?

It is only used in strip, for the in-place case (without -o).

eu-strip on archives is completely broken.  I'm not really sure what the
plan was.  The patch below makes it stop crashing.  But it produces
completely bogus output (it comes out with an ELF file header for some
reason, and I have no idea about the contents).

binutils strip on an archive actually makes a temporary directory, fills it
with stripped versions of the member files, then creates a fresh archive in
a temporary file, removes the directory, and renames the output file into
place.  (It doesn't fork ar, but it almost might as well.)

I think we could reasonably easily do better than that, anyway.  It's
probably easiest just to do it by supporting -o for archives, and making
the "in place" case (no -o) actually just work line -o to a temp file.
Modifying in place could work too, but it could entail a lot of copying
member contents around.  We could keep the old long name table and so
forth, but each member gets shorter from stripping, so we both have to
write later members back earlier after shortening each earlier one, and
have to go back and update the symdef table offsets.


Thanks,
Roland

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 7bcc235..0000000 100644  
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,7 @@
+2009-08-05  Roland McGrath  <roland at redhat.com>
+
+	* elf_clone.c: Chain onto the ELF->parent->state.ar.children list.
+
 2009-07-26  Ulrich Drepper  <drepper at redhat.com>
 
 	* elf.h: Update from glibc.
diff --git a/libelf/elf_clone.c b/libelf/elf_clone.c
index 8b699fa..0000000 100644  
--- a/libelf/elf_clone.c
+++ b/libelf/elf_clone.c
@@ -1,5 +1,5 @@
 /* Create clone of a given descriptor.
-   Copyright (C) 2003, 2004 Red Hat, Inc.
+   Copyright (C) 2003, 2004, 2009 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper at redhat.com>, 2003.
 
@@ -92,6 +92,14 @@ elf_clone (Elf *elf, Elf_Cmd cmd)
       retval->state.elf32.scns.max = elf->state.elf32.scns.max;
 
       retval->class = elf->class;
+
+      if (retval->parent != NULL)
+	{
+	  /* Enlist this new descriptor in the list of children.  */
+	  assert (retval->parent->kind == ELF_K_AR);
+	  retval->next = retval->parent->state.ar.children;
+	  retval->parent->state.ar.children = retval;
+	}
     }
 
   /* Release the lock.  */


More information about the elfutils-devel mailing list