summaryrefslogtreecommitdiff
path: root/src/copy/elf.c
blob: 445f98ca9f491de3deed011ff5a0fd850000a6db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>

#include <libelf.h>
#include <gelf.h>

#include <libelfu/libelfu.h>


void elfu_copyEhdr(Elf *eo, Elf *ei);
void elfu_copySections(Elf *eo, Elf *ei);
void elfu_copySegments1(Elf *eo, Elf *ei);
void elfu_copySegments2(Elf *eo, Elf *ei);


void elfu_copyElf(Elf *eo, Elf *ei)
{
  elfu_copyEhdr(eo, ei);
  elfu_copySections(eo, ei);
  elfu_copySegments1(eo, ei);

  /* Calculate file structure so we have section offsets */
  if (elf_update(eo, ELF_C_NULL) < 0) {
    fprintf(stderr, "elf_update(NULL) failed: %s\n", elf_errmsg(-1));
  }

  /* Update the segment offsets and lengths */
  elfu_copySegments2(eo, ei);

  elfu_fixupPhdrSelfRef(eo);
}