Deleted Added
full compact
main.c (280932) main.c (283616)
1/*-
2 * Copyright (c) 2007-2013 Kai Wang
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 25 unchanged lines hidden (view full) ---

34#include <libelftc.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include <unistd.h>
39
40#include "elfcopy.h"
41
1/*-
2 * Copyright (c) 2007-2013 Kai Wang
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 25 unchanged lines hidden (view full) ---

34#include <libelftc.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include <unistd.h>
39
40#include "elfcopy.h"
41
42ELFTC_VCSID("$Id: main.c 3174 2015-03-27 17:13:41Z emaste $");
42ELFTC_VCSID("$Id: main.c 3216 2015-05-23 21:16:36Z kaiwang27 $");
43
44enum options
45{
46 ECP_ADD_GNU_DEBUGLINK,
47 ECP_ADD_SECTION,
48 ECP_CHANGE_ADDR,
49 ECP_CHANGE_SEC_ADDR,
50 ECP_CHANGE_SEC_LMA,

--- 348 unchanged lines hidden (view full) ---

399 if (gelf_getehdr(ecp->eout, &oeh) == NULL)
400 errx(EXIT_FAILURE, "gelf_getehdr() failed: %s",
401 elf_errmsg(-1));
402
403 /*
404 * Insert SHDR table into the internal section list as a "pseudo"
405 * section, so later it will get sorted and resynced just as "normal"
406 * sections.
43
44enum options
45{
46 ECP_ADD_GNU_DEBUGLINK,
47 ECP_ADD_SECTION,
48 ECP_CHANGE_ADDR,
49 ECP_CHANGE_SEC_ADDR,
50 ECP_CHANGE_SEC_LMA,

--- 348 unchanged lines hidden (view full) ---

399 if (gelf_getehdr(ecp->eout, &oeh) == NULL)
400 errx(EXIT_FAILURE, "gelf_getehdr() failed: %s",
401 elf_errmsg(-1));
402
403 /*
404 * Insert SHDR table into the internal section list as a "pseudo"
405 * section, so later it will get sorted and resynced just as "normal"
406 * sections.
407 *
408 * Under FreeBSD, Binutils objcopy always put the section header
409 * at the end of all the sections. We want to do the same here.
410 *
411 * However, note that the behaviour is still different with Binutils:
412 * elfcopy checks the FreeBSD OSABI tag to tell whether it needs to
413 * move the section headers, while Binutils is probably configured
414 * this way when it's compiled on FreeBSD.
407 */
415 */
408 shtab = insert_shtab(ecp, 0);
416 if (oeh.e_ident[EI_OSABI] == ELFOSABI_FREEBSD)
417 shtab = insert_shtab(ecp, 1);
418 else
419 shtab = insert_shtab(ecp, 0);
409
410 /*
411 * Resync section offsets in the output object. This is needed
412 * because probably sections are modified or new sections are added,
413 * as a result overlap/gap might appears.
414 */
415 resync_sections(ecp);
416

--- 63 unchanged lines hidden (view full) ---

480 free(sec->buf);
481 if (sec->newname != NULL)
482 free(sec->newname);
483 if (sec->pad != NULL)
484 free(sec->pad);
485 free(sec);
486 }
487 }
420
421 /*
422 * Resync section offsets in the output object. This is needed
423 * because probably sections are modified or new sections are added,
424 * as a result overlap/gap might appears.
425 */
426 resync_sections(ecp);
427

--- 63 unchanged lines hidden (view full) ---

491 free(sec->buf);
492 if (sec->newname != NULL)
493 free(sec->newname);
494 if (sec->pad != NULL)
495 free(sec->pad);
496 free(sec);
497 }
498 }
499
500 if (ecp->secndx != NULL) {
501 free(ecp->secndx);
502 ecp->secndx = NULL;
503 }
488}
489
490/* Create a temporary file. */
491void
492create_tempfile(char **fn, int *fd)
493{
494 const char *tmpdir;
495 char *cp, *tmpf;

--- 1035 unchanged lines hidden ---
504}
505
506/* Create a temporary file. */
507void
508create_tempfile(char **fn, int *fd)
509{
510 const char *tmpdir;
511 char *cp, *tmpf;

--- 1035 unchanged lines hidden ---