auto import from //depot/cupcake/@135843
diff --git a/tools/soslim/common.c b/tools/soslim/common.c
new file mode 100644
index 0000000..b90cf41
--- /dev/null
+++ b/tools/soslim/common.c
@@ -0,0 +1,35 @@
+#include <stdlib.h>
+#include <common.h>
+#include <debug.h>
+
+void map_over_sections(Elf *elf,
+ section_match_fn_t match,
+ void *user_data)
+{
+ Elf_Scn* section = NULL;
+ while ((section = elf_nextscn(elf, section)) != NULL) {
+ if (match(elf, section, user_data))
+ return;
+ }
+}
+
+void map_over_segments(Elf *elf,
+ segment_match_fn_t match,
+ void *user_data)
+{
+ Elf32_Ehdr *ehdr;
+ Elf32_Phdr *phdr;
+ int index;
+
+ ehdr = elf32_getehdr(elf);
+ phdr = elf32_getphdr(elf);
+
+ INFO("Scanning over %d program segments...\n",
+ ehdr->e_phnum);
+
+ for (index = ehdr->e_phnum; index; index--) {
+ if (match(elf, phdr++, user_data))
+ return;
+ }
+}
+