* mipsread.c (parse_partial_symbols): Do not add undefined
[deliverable/binutils-gdb.git] / bfd / seclet.c
CommitLineData
2afc285d 1/* seclet.c
0dc1bc8b 2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
2afc285d
PB
3 Written by Cygnus Support.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
e98e6ec1
SC
21/* This module is part of BFD */
22
23
24/* The intention is that one day, all the code which uses sections
25 will change and use seclets instead - maybe seglet would have been
26 a better name..
27
28 Anyway, a seclet contains enough info to be able to describe an
29 area of output memory in one go.
30
31 The only description so far catered for is that of the
32 <<bfd_indirect_seclet>>, which is a select which points to a
33 <<section>> and the <<asymbols>> associated with the section, so
34 that relocation can be done when needed.
35
36 One day there will be more types - they will at least migrate from
37 the linker's data structures - also there could be extra stuff,
38 like a bss seclet, which descibes a lump of memory as containing
39 zeros compactly, without the horrible SEC_* flag cruft.
40
41
42*/
43
44#include "bfd.h"
45#include "sysdep.h"
46#include "libbfd.h"
47#include "seclet.h"
48#include "coff/internal.h"
0c2fae09
ILT
49
50/* Create a new seclet and attach it to a section. */
51
e98e6ec1
SC
52bfd_seclet_type *
53DEFUN(bfd_new_seclet,(abfd, section),
54 bfd *abfd AND
55 asection *section)
56{
57 bfd_seclet_type *n = (bfd_seclet_type *)bfd_alloc(abfd, sizeof(bfd_seclet_type));
58 if (section->seclets_tail != (bfd_seclet_type *)NULL) {
59 section->seclets_tail->next = n;
60 }
61 else
62 {
63 section->seclets_head = n;
64 }
65 section->seclets_tail = n;
66
67 return n;
e98e6ec1
SC
68}
69
0c2fae09
ILT
70/* Given an indirect seclet which points to an input section, relocate
71 the contents of the seclet and put the data in its final
72 destination. */
e98e6ec1 73
0c2fae09
ILT
74static boolean
75DEFUN(rel,(abfd, seclet, output_section, data, relocateable),
e98e6ec1
SC
76 bfd *abfd AND
77 bfd_seclet_type *seclet AND
3be56062 78 asection *output_section AND
0c2fae09
ILT
79 PTR data AND
80 boolean relocateable)
e98e6ec1 81{
46bc1bf6 82 if ((output_section->flags & SEC_HAS_CONTENTS) != 0
b58e9180 83 && seclet->size)
e98e6ec1 84 {
0c2fae09
ILT
85 data = (PTR) bfd_get_relocated_section_contents(abfd, seclet, data,
86 relocateable);
e5932011
SC
87 if(bfd_set_section_contents(abfd,
88 output_section,
89 data,
90 seclet->offset,
91 seclet->size) == false)
92 {
93 abort();
94 }
e98e6ec1 95 }
0c2fae09 96 return true;
e98e6ec1
SC
97}
98
0c2fae09
ILT
99/* Put the contents of a seclet in its final destination. */
100
101static boolean
102DEFUN(seclet_dump_seclet,(abfd, seclet, section, data, relocateable),
e98e6ec1
SC
103 bfd *abfd AND
104 bfd_seclet_type *seclet AND
3be56062 105 asection *section AND
0c2fae09
ILT
106 PTR data AND
107 boolean relocateable)
e98e6ec1
SC
108{
109 switch (seclet->type)
0c2fae09
ILT
110 {
111 case bfd_indirect_seclet:
112 /* The contents of this section come from another one somewhere
113 else */
114 return rel(abfd, seclet, section, data, relocateable);
115
116 case bfd_fill_seclet:
117 /* Fill in the section with us */
118 {
119 char *d = bfd_xmalloc(seclet->size);
120 unsigned int i;
121 for (i =0; i < seclet->size; i+=2) {
122 d[i] = seclet->u.fill.value >> 8;
123 }
124 for (i = 1; i < seclet->size; i+=2) {
125 d[i] = seclet->u.fill.value ;
126 }
ad7009aa 127 /* Don't bother to fill in empty sections */
b580c2b5 128 if (!(bfd_get_section_flags(abfd, section) & SEC_HAS_CONTENTS))
ad7009aa
SC
129 {
130 return true;
131 }
0c2fae09
ILT
132 return bfd_set_section_contents(abfd, section, d, seclet->offset,
133 seclet->size);
134 }
135
136 default:
137 abort();
138 }
139
140 return true;
e98e6ec1
SC
141}
142
0c2fae09
ILT
143/*
144INTERNAL_FUNCTION
145 bfd_generic_seclet_link
146
147SYNOPSIS
148 boolean bfd_generic_seclet_link
149 (bfd *abfd,
150 PTR data,
151 boolean relocateable);
152
153DESCRIPTION
154
155 The generic seclet linking routine. The caller should have
156 set up seclets for all the output sections. The DATA argument
157 should point to a memory area large enough to hold the largest
158 section. This function looks through the seclets and moves
159 the contents into the output sections. If RELOCATEABLE is
160 true, the orelocation fields of the output sections must
161 already be initialized.
162
163*/
164
165boolean
166DEFUN(bfd_generic_seclet_link,(abfd, data, relocateable),
3be56062 167 bfd *abfd AND
0c2fae09
ILT
168 PTR data AND
169 boolean relocateable)
e98e6ec1 170{
e98e6ec1
SC
171 asection *o = abfd->sections;
172 while (o != (asection *)NULL)
173 {
174 bfd_seclet_type *p = o->seclets_head;
175 while (p != (bfd_seclet_type *)NULL)
176 {
0c2fae09
ILT
177 if (seclet_dump_seclet(abfd, p, o, data, relocateable) == false)
178 return false;
e98e6ec1
SC
179 p = p ->next;
180 }
e98e6ec1
SC
181 o = o->next;
182 }
0c2fae09
ILT
183
184 return true;
e98e6ec1 185}
This page took 0.080222 seconds and 4 git commands to generate.