Change applied flag to a three-state enum.
[ksplice.git] / objcommon.c
blobf766f92496ec1ffc020d598bd0713d7a9f35bff1
1 /* Copyright (C) 2008 Jeffrey Brian Arnold <jbarnold@mit.edu>
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License, version 2.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
14 * 02110-1301, USA.
17 #include "objcommon.h"
19 long
20 get_syms(bfd * abfd, asymbol *** syms_ptr)
22 long storage_needed = bfd_get_symtab_upper_bound(abfd);
23 if (storage_needed == 0)
24 return 0;
25 assert(storage_needed >= 0);
27 *syms_ptr = (asymbol **) malloc(storage_needed);
28 long num_syms = bfd_canonicalize_symtab(abfd, *syms_ptr);
29 assert(num_syms >= 0);
31 return num_syms;
34 struct supersect *
35 fetch_supersect(bfd * abfd, asection * sect, asymbol ** sympp)
37 static struct supersect *supersects = NULL;
39 struct supersect *ss;
40 for (ss = supersects; ss != NULL; ss = ss->next) {
41 if (strcmp(sect->name, ss->name) == 0 && ss->parent == abfd) {
42 return ss;
46 struct supersect *new = malloc(sizeof (*new));
47 new->parent = abfd;
48 new->name = malloc(strlen(sect->name) + 1);
49 strcpy(new->name, sect->name);
50 new->next = supersects;
51 supersects = new;
53 new->contents_size = bfd_get_section_size(sect);
54 new->contents = (void *) malloc(align(new->contents_size, 4));
55 assert(bfd_get_section_contents
56 (abfd, sect, new->contents, 0, new->contents_size));
58 int relsize = bfd_get_reloc_upper_bound(abfd, sect);
59 new->relocs = (void *) malloc(relsize);
60 new->num_relocs =
61 bfd_canonicalize_reloc(abfd, sect, new->relocs, sympp);
62 assert(new->num_relocs >= 0);
64 return new;