This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
merging executables
- From: "Jan Hoogerbrugge" <hoogerbrugge at hotmail dot com>
- To: binutils at sources dot redhat dot com
- Date: Fri, 15 Feb 2002 14:05:45 +0100
- Subject: merging executables
- Bcc:
Hi,
I want to use libbfd to merge multiple ELF executables into one. Just
copying the sections of a few input files to an output file. I wrote the
following code, which does not work for some reason. It core dumps in
bfd_copy_private_section_data. Any idea why??
Cheers,
Jan
-----
#include <strings.h>
#include <stdio.h>
#include <stdlib.h>
#include <bfd.h>
#include <assert.h>
main(int argc, char *argv[])
{
char sec_out_name[1024];
bfd *bfd_in, *bfd_out;
asection *sec_in, *sec_out;
int i;
bfd_init();
bfd_out = bfd_openw(argv[1], "elf32-big");
assert(bfd_out != NULL);
for(i = 2; i < argc; i++)
{
bfd_in = bfd_openr(argv[i], "elf32-big");
assert(bfd_in != NULL);
bfd_check_format(bfd_in, bfd_object);
for(sec_in = bfd_in->sections; sec_in; sec_in =
sec_in->next)
{
sprintf(sec_out_name, "%s_%d", sec_in->name, i - 1);
sec_out = bfd_make_section_anyway(bfd_out,
strdup(sec_out_name));
assert(sec_out != NULL);
bfd_copy_private_section_data(bfd_in, sec_in,
bfd_out, sec_out);
}
bfd_close(bfd_in);
}
bfd_close(bfd_out);
return 0;
}
_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com