* bout.c: added support for relaxable alignment relocs.
[deliverable/binutils-gdb.git] / bfd / seclet.c
CommitLineData
e98e6ec1
SC
1/* This module is part of BFD */
2
3
4/* The intention is that one day, all the code which uses sections
5 will change and use seclets instead - maybe seglet would have been
6 a better name..
7
8 Anyway, a seclet contains enough info to be able to describe an
9 area of output memory in one go.
10
11 The only description so far catered for is that of the
12 <<bfd_indirect_seclet>>, which is a select which points to a
13 <<section>> and the <<asymbols>> associated with the section, so
14 that relocation can be done when needed.
15
16 One day there will be more types - they will at least migrate from
17 the linker's data structures - also there could be extra stuff,
18 like a bss seclet, which descibes a lump of memory as containing
19 zeros compactly, without the horrible SEC_* flag cruft.
20
21
22*/
23
24#include "bfd.h"
25#include "sysdep.h"
26#include "libbfd.h"
27#include "seclet.h"
28#include "coff/internal.h"
29bfd_seclet_type *
30DEFUN(bfd_new_seclet,(abfd, section),
31 bfd *abfd AND
32 asection *section)
33{
34 bfd_seclet_type *n = (bfd_seclet_type *)bfd_alloc(abfd, sizeof(bfd_seclet_type));
35 if (section->seclets_tail != (bfd_seclet_type *)NULL) {
36 section->seclets_tail->next = n;
37 }
38 else
39 {
40 section->seclets_head = n;
41 }
42 section->seclets_tail = n;
43
44 return n;
e98e6ec1
SC
45}
46
47
48
49
50#define MAX_ERRORS_IN_A_ROW 10
51extern bfd_error_vector_type bfd_error_vector;
e98e6ec1 52
e98e6ec1
SC
53
54void
3be56062 55DEFUN(rel,(abfd, seclet, output_section, data),
e98e6ec1
SC
56 bfd *abfd AND
57 bfd_seclet_type *seclet AND
3be56062
SC
58 asection *output_section AND
59 PTR data)
e98e6ec1 60{
2cfd0562 61
ab98fd5d 62 if (output_section->flags & SEC_HAS_CONTENTS
b58e9180
SC
63 && !(output_section->flags & SEC_NEVER_LOAD)
64 && seclet->size)
e98e6ec1 65 {
2cfd0562 66 data = bfd_get_relocated_section_contents(abfd, seclet, data);
e5932011
SC
67 if(bfd_set_section_contents(abfd,
68 output_section,
69 data,
70 seclet->offset,
71 seclet->size) == false)
72 {
73 abort();
74 }
e98e6ec1 75 }
e98e6ec1
SC
76}
77
78void
3be56062 79DEFUN(seclet_dump_seclet,(abfd, seclet, section, data),
e98e6ec1
SC
80 bfd *abfd AND
81 bfd_seclet_type *seclet AND
3be56062
SC
82 asection *section AND
83 PTR data)
e98e6ec1
SC
84{
85 switch (seclet->type)
86 {
e5932011 87 case bfd_indirect_seclet:
e98e6ec1
SC
88 /* The contents of this section come from another one somewhere
89 else */
3be56062 90 rel(abfd, seclet, section, data);
e98e6ec1 91 break;
e5932011
SC
92 case bfd_fill_seclet:
93 /* Fill in the section with us */
94 {
95 char *d = malloc(seclet->size);
96 unsigned int i;
97 for (i =0; i < seclet->size; i+=2) {
98 d[i] = seclet->u.fill.value >> 8;
99 }
100 for (i = 1; i < seclet->size; i+=2) {
101 d[i] = seclet->u.fill.value ;
102 }
103 bfd_set_section_contents(abfd, section, d, seclet->offset, seclet->size);
104
105 }
106 break;
107 default:
e98e6ec1
SC
108 abort();
109 }
e98e6ec1
SC
110}
111
112void
3be56062
SC
113DEFUN(seclet_dump,(abfd, data),
114 bfd *abfd AND
115 PTR data)
e98e6ec1
SC
116{
117 /* Write all the seclets on the bfd out, relocate etc according to the
118 rules */
119
120 asection *o = abfd->sections;
121 while (o != (asection *)NULL)
122 {
123 bfd_seclet_type *p = o->seclets_head;
124 while (p != (bfd_seclet_type *)NULL)
125 {
3be56062 126 seclet_dump_seclet(abfd, p, o, data);
e98e6ec1
SC
127 p = p ->next;
128 }
e98e6ec1
SC
129 o = o->next;
130 }
e98e6ec1 131}
This page took 0.039315 seconds and 4 git commands to generate.