Subversion Repositories Kolibri OS

Rev

Rev 5197 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5197 Rev 6324
Line 1... Line 1...
1
/* simple.c -- BFD simple client routines
1
/* simple.c -- BFD simple client routines
2
   Copyright 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
-
 
3
   Free Software Foundation, Inc.
2
   Copyright (C) 2002-2015 Free Software Foundation, Inc.
4
   Contributed by MontaVista Software, Inc.
3
   Contributed by MontaVista Software, Inc.
Line 5... Line 4...
5
 
4
 
Line 6... Line 5...
6
   This file is part of BFD, the Binary File Descriptor library.
5
   This file is part of BFD, the Binary File Descriptor library.
Line 99... Line 98...
99
{
98
{
100
  bfd_vma offset;
99
  bfd_vma offset;
101
  asection *section;
100
  asection *section;
102
};
101
};
Line -... Line 102...
-
 
102
 
-
 
103
struct saved_offsets
-
 
104
{
-
 
105
  unsigned int section_count;
-
 
106
  struct saved_output_info *sections;
-
 
107
};
-
 
108
 
-
 
109
/* The sections in ABFD may already have output sections and offsets
-
 
110
   set if we are here during linking.
-
 
111
 
-
 
112
   DWARF-2 specifies offsets into debug sections in many cases and
-
 
113
   bfd_simple_get_relocated_section_contents is called to relocate
-
 
114
   debug info for a single relocatable object file.  So we want
-
 
115
   offsets relative to that object file's sections, not offsets in the
-
 
116
   output file.  For that reason, reset a debug section->output_offset
-
 
117
   to zero.
-
 
118
 
-
 
119
   If not called during linking then set section->output_section to
-
 
120
   point back to the input section, because output_section must not be
-
 
121
   NULL when calling the relocation routines.
-
 
122
 
-
 
123
   Save the original output offset and section to restore later.  */
103
 
124
 
104
static void
125
static void
105
simple_save_output_info (bfd *abfd ATTRIBUTE_UNUSED,
126
simple_save_output_info (bfd *abfd ATTRIBUTE_UNUSED,
106
			 asection *section,
127
			 asection *section,
107
			 void *ptr)
128
			 void *ptr)
108
{
129
{
-
 
130
  struct saved_offsets *saved_offsets = (struct saved_offsets *) ptr;
-
 
131
  struct saved_output_info *output_info;
-
 
132
 
109
  struct saved_output_info *output_info = (struct saved_output_info *) ptr;
133
  output_info = &saved_offsets->sections[section->index];
110
  output_info[section->index].offset = section->output_offset;
134
  output_info->offset = section->output_offset;
111
  output_info[section->index].section = section->output_section;
135
  output_info->section = section->output_section;
112
  if ((section->flags & SEC_DEBUGGING) != 0
136
  if ((section->flags & SEC_DEBUGGING) != 0
113
      || section->output_section == NULL)
137
      || section->output_section == NULL)
114
    {
138
    {
115
      section->output_offset = 0;
139
      section->output_offset = 0;
Line 120... Line 144...
120
static void
144
static void
121
simple_restore_output_info (bfd *abfd ATTRIBUTE_UNUSED,
145
simple_restore_output_info (bfd *abfd ATTRIBUTE_UNUSED,
122
			    asection *section,
146
			    asection *section,
123
			    void *ptr)
147
			    void *ptr)
124
{
148
{
125
  struct saved_output_info *output_info = (struct saved_output_info *) ptr;
149
  struct saved_offsets *saved_offsets = (struct saved_offsets *) ptr;
-
 
150
  struct saved_output_info *output_info;
-
 
151
 
-
 
152
  if (section->index >= saved_offsets->section_count)
-
 
153
    return;
-
 
154
 
-
 
155
  output_info = &saved_offsets->sections[section->index];
126
  section->output_offset = output_info[section->index].offset;
156
  section->output_offset = output_info->offset;
127
  section->output_section = output_info[section->index].section;
157
  section->output_section = output_info->section;
128
}
158
}
Line 129... Line 159...
129
 
159
 
130
/*
160
/*
131
FUNCTION
161
FUNCTION
Line 155... Line 185...
155
  struct bfd_link_info link_info;
185
  struct bfd_link_info link_info;
156
  struct bfd_link_order link_order;
186
  struct bfd_link_order link_order;
157
  struct bfd_link_callbacks callbacks;
187
  struct bfd_link_callbacks callbacks;
158
  bfd_byte *contents, *data;
188
  bfd_byte *contents, *data;
159
  int storage_needed;
189
  int storage_needed;
160
  void *saved_offsets;
190
  struct saved_offsets saved_offsets;
-
 
191
  bfd *link_next;
Line 161... Line 192...
161
 
192
 
162
  /* Don't apply relocation on executable and shared library.  See
193
  /* Don't apply relocation on executable and shared library.  See
163
     PR 4756.  */
194
     PR 4756.  */
164
  if ((abfd->flags & (HAS_RELOC | EXEC_P | DYNAMIC)) != HAS_RELOC
195
  if ((abfd->flags & (HAS_RELOC | EXEC_P | DYNAMIC)) != HAS_RELOC
Line 175... Line 206...
175
 
206
 
176
  /* Fill in the bare minimum number of fields for our purposes.  */
207
  /* Fill in the bare minimum number of fields for our purposes.  */
177
  memset (&link_info, 0, sizeof (link_info));
208
  memset (&link_info, 0, sizeof (link_info));
178
  link_info.output_bfd = abfd;
209
  link_info.output_bfd = abfd;
179
  link_info.input_bfds = abfd;
210
  link_info.input_bfds = abfd;
Line -... Line 211...
-
 
211
  link_info.input_bfds_tail = &abfd->link.next;
-
 
212
 
180
  link_info.input_bfds_tail = &abfd->link_next;
213
  link_next = abfd->link.next;
181
 
214
  abfd->link.next = NULL;
182
  link_info.hash = _bfd_generic_link_hash_table_create (abfd);
215
  link_info.hash = _bfd_generic_link_hash_table_create (abfd);
183
  link_info.callbacks = &callbacks;
216
  link_info.callbacks = &callbacks;
184
  callbacks.warning = simple_dummy_warning;
217
  callbacks.warning = simple_dummy_warning;
Line 200... Line 233...
200
  if (outbuf == NULL)
233
  if (outbuf == NULL)
201
    {
234
    {
202
      bfd_size_type amt = sec->rawsize > sec->size ? sec->rawsize : sec->size;
235
      bfd_size_type amt = sec->rawsize > sec->size ? sec->rawsize : sec->size;
203
      data = (bfd_byte *) bfd_malloc (amt);
236
      data = (bfd_byte *) bfd_malloc (amt);
204
      if (data == NULL)
237
      if (data == NULL)
-
 
238
	{
-
 
239
	  _bfd_generic_link_hash_table_free (abfd);
-
 
240
	  abfd->link.next = link_next;
205
	return NULL;
241
	return NULL;
-
 
242
	}
206
      outbuf = data;
243
      outbuf = data;
207
    }
244
    }
Line 208... Line -...
208
 
-
 
209
  /* The sections in ABFD may already have output sections and offsets set.
-
 
210
     Because this function is primarily for debug sections, and GCC uses the
-
 
211
     knowledge that debug sections will generally have VMA 0 when emitting
-
 
212
     relocations between DWARF-2 sections (which are supposed to be
-
 
213
     section-relative offsets anyway), we need to reset the output offsets
-
 
214
     to zero.  We also need to arrange for section->output_section->vma plus
-
 
215
     section->output_offset to equal section->vma, which we do by setting
245
 
216
     section->output_section to point back to section.  Save the original
-
 
217
     output offset and output section to restore later.  */
246
  saved_offsets.section_count = abfd->section_count;
218
  saved_offsets = malloc (sizeof (struct saved_output_info)
247
  saved_offsets.sections = malloc (sizeof (*saved_offsets.sections)
219
			  * abfd->section_count);
248
				   * saved_offsets.section_count);
220
  if (saved_offsets == NULL)
249
  if (saved_offsets.sections == NULL)
221
    {
250
    {
222
      if (data)
251
      if (data)
-
 
252
	free (data);
-
 
253
      _bfd_generic_link_hash_table_free (abfd);
223
	free (data);
254
      abfd->link.next = link_next;
224
      return NULL;
255
      return NULL;
225
    }
256
    }
Line 226... Line 257...
226
  bfd_map_over_sections (abfd, simple_save_output_info, saved_offsets);
257
  bfd_map_over_sections (abfd, simple_save_output_info, &saved_offsets);
227
 
258
 
228
  if (symbol_table == NULL)
259
  if (symbol_table == NULL)
Line 243... Line 274...
243
						 0,
274
						 0,
244
						 symbol_table);
275
						 symbol_table);
245
  if (contents == NULL && data != NULL)
276
  if (contents == NULL && data != NULL)
246
    free (data);
277
    free (data);
Line 247... Line 278...
247
 
278
 
248
  bfd_map_over_sections (abfd, simple_restore_output_info, saved_offsets);
279
  bfd_map_over_sections (abfd, simple_restore_output_info, &saved_offsets);
Line 249... Line 280...
249
  free (saved_offsets);
280
  free (saved_offsets.sections);
-
 
281
 
250
 
282
  _bfd_generic_link_hash_table_free (abfd);
251
  _bfd_generic_link_hash_table_free (link_info.hash);
283
  abfd->link.next = link_next;