1992-09-02 20:45:02 +00:00
|
|
|
/* seclet.c
|
1993-02-16 16:54:20 +00:00
|
|
|
Copyright (C) 1992, 1993 Free Software Foundation, Inc.
|
1992-09-02 20:45:02 +00:00
|
|
|
Written by Cygnus Support.
|
|
|
|
|
|
|
|
This file is part of BFD, the Binary File Descriptor library.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
|
|
1992-01-24 22:44:51 +00:00
|
|
|
/* This module is part of BFD */
|
|
|
|
|
|
|
|
|
|
|
|
/* The intention is that one day, all the code which uses sections
|
|
|
|
will change and use seclets instead - maybe seglet would have been
|
|
|
|
a better name..
|
|
|
|
|
|
|
|
Anyway, a seclet contains enough info to be able to describe an
|
|
|
|
area of output memory in one go.
|
|
|
|
|
|
|
|
The only description so far catered for is that of the
|
|
|
|
<<bfd_indirect_seclet>>, which is a select which points to a
|
|
|
|
<<section>> and the <<asymbols>> associated with the section, so
|
|
|
|
that relocation can be done when needed.
|
|
|
|
|
|
|
|
One day there will be more types - they will at least migrate from
|
|
|
|
the linker's data structures - also there could be extra stuff,
|
|
|
|
like a bss seclet, which descibes a lump of memory as containing
|
|
|
|
zeros compactly, without the horrible SEC_* flag cruft.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bfd.h"
|
|
|
|
#include "sysdep.h"
|
|
|
|
#include "libbfd.h"
|
|
|
|
#include "seclet.h"
|
|
|
|
#include "coff/internal.h"
|
1993-01-12 00:38:59 +00:00
|
|
|
|
|
|
|
/* Create a new seclet and attach it to a section. */
|
|
|
|
|
1992-01-24 22:44:51 +00:00
|
|
|
bfd_seclet_type *
|
|
|
|
DEFUN(bfd_new_seclet,(abfd, section),
|
|
|
|
bfd *abfd AND
|
|
|
|
asection *section)
|
|
|
|
{
|
|
|
|
bfd_seclet_type *n = (bfd_seclet_type *)bfd_alloc(abfd, sizeof(bfd_seclet_type));
|
|
|
|
if (section->seclets_tail != (bfd_seclet_type *)NULL) {
|
|
|
|
section->seclets_tail->next = n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
section->seclets_head = n;
|
|
|
|
}
|
|
|
|
section->seclets_tail = n;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1993-01-12 00:38:59 +00:00
|
|
|
/* Given an indirect seclet which points to an input section, relocate
|
|
|
|
the contents of the seclet and put the data in its final
|
|
|
|
destination. */
|
1992-01-24 22:44:51 +00:00
|
|
|
|
1993-01-12 00:38:59 +00:00
|
|
|
static boolean
|
|
|
|
DEFUN(rel,(abfd, seclet, output_section, data, relocateable),
|
1992-01-24 22:44:51 +00:00
|
|
|
bfd *abfd AND
|
|
|
|
bfd_seclet_type *seclet AND
|
1992-08-27 00:35:09 +00:00
|
|
|
asection *output_section AND
|
1993-01-12 00:38:59 +00:00
|
|
|
PTR data AND
|
|
|
|
boolean relocateable)
|
1992-01-24 22:44:51 +00:00
|
|
|
{
|
1993-04-06 00:53:41 +00:00
|
|
|
if ((output_section->flags & SEC_HAS_CONTENTS) != 0
|
1992-07-16 15:12:28 +00:00
|
|
|
&& seclet->size)
|
1992-01-24 22:44:51 +00:00
|
|
|
{
|
1993-01-12 00:38:59 +00:00
|
|
|
data = (PTR) bfd_get_relocated_section_contents(abfd, seclet, data,
|
|
|
|
relocateable);
|
1992-04-17 16:22:44 +00:00
|
|
|
if(bfd_set_section_contents(abfd,
|
|
|
|
output_section,
|
|
|
|
data,
|
|
|
|
seclet->offset,
|
|
|
|
seclet->size) == false)
|
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
1992-01-24 22:44:51 +00:00
|
|
|
}
|
1993-01-12 00:38:59 +00:00
|
|
|
return true;
|
1992-01-24 22:44:51 +00:00
|
|
|
}
|
|
|
|
|
1993-01-12 00:38:59 +00:00
|
|
|
/* Put the contents of a seclet in its final destination. */
|
|
|
|
|
|
|
|
static boolean
|
|
|
|
DEFUN(seclet_dump_seclet,(abfd, seclet, section, data, relocateable),
|
1992-01-24 22:44:51 +00:00
|
|
|
bfd *abfd AND
|
|
|
|
bfd_seclet_type *seclet AND
|
1992-08-27 00:35:09 +00:00
|
|
|
asection *section AND
|
1993-01-12 00:38:59 +00:00
|
|
|
PTR data AND
|
|
|
|
boolean relocateable)
|
1992-01-24 22:44:51 +00:00
|
|
|
{
|
|
|
|
switch (seclet->type)
|
1993-01-12 00:38:59 +00:00
|
|
|
{
|
|
|
|
case bfd_indirect_seclet:
|
|
|
|
/* The contents of this section come from another one somewhere
|
|
|
|
else */
|
|
|
|
return rel(abfd, seclet, section, data, relocateable);
|
|
|
|
|
|
|
|
case bfd_fill_seclet:
|
|
|
|
/* Fill in the section with us */
|
|
|
|
{
|
|
|
|
char *d = bfd_xmalloc(seclet->size);
|
|
|
|
unsigned int i;
|
|
|
|
for (i =0; i < seclet->size; i+=2) {
|
|
|
|
d[i] = seclet->u.fill.value >> 8;
|
|
|
|
}
|
|
|
|
for (i = 1; i < seclet->size; i+=2) {
|
|
|
|
d[i] = seclet->u.fill.value ;
|
|
|
|
}
|
1993-03-12 16:33:59 +00:00
|
|
|
/* Don't bother to fill in empty sections */
|
1993-04-02 22:36:04 +00:00
|
|
|
if (!(bfd_get_section_flags(abfd, section) & SEC_HAS_CONTENTS))
|
1993-03-12 16:33:59 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
1993-01-12 00:38:59 +00:00
|
|
|
return bfd_set_section_contents(abfd, section, d, seclet->offset,
|
|
|
|
seclet->size);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
1992-01-24 22:44:51 +00:00
|
|
|
}
|
|
|
|
|
1993-01-12 00:38:59 +00:00
|
|
|
/*
|
|
|
|
INTERNAL_FUNCTION
|
|
|
|
bfd_generic_seclet_link
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
boolean bfd_generic_seclet_link
|
|
|
|
(bfd *abfd,
|
|
|
|
PTR data,
|
|
|
|
boolean relocateable);
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
|
|
|
|
The generic seclet linking routine. The caller should have
|
|
|
|
set up seclets for all the output sections. The DATA argument
|
|
|
|
should point to a memory area large enough to hold the largest
|
|
|
|
section. This function looks through the seclets and moves
|
|
|
|
the contents into the output sections. If RELOCATEABLE is
|
|
|
|
true, the orelocation fields of the output sections must
|
|
|
|
already be initialized.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
boolean
|
|
|
|
DEFUN(bfd_generic_seclet_link,(abfd, data, relocateable),
|
1992-08-27 00:35:09 +00:00
|
|
|
bfd *abfd AND
|
1993-01-12 00:38:59 +00:00
|
|
|
PTR data AND
|
|
|
|
boolean relocateable)
|
1992-01-24 22:44:51 +00:00
|
|
|
{
|
|
|
|
asection *o = abfd->sections;
|
|
|
|
while (o != (asection *)NULL)
|
|
|
|
{
|
|
|
|
bfd_seclet_type *p = o->seclets_head;
|
|
|
|
while (p != (bfd_seclet_type *)NULL)
|
|
|
|
{
|
1993-01-12 00:38:59 +00:00
|
|
|
if (seclet_dump_seclet(abfd, p, o, data, relocateable) == false)
|
|
|
|
return false;
|
1992-01-24 22:44:51 +00:00
|
|
|
p = p ->next;
|
|
|
|
}
|
|
|
|
o = o->next;
|
|
|
|
}
|
1993-01-12 00:38:59 +00:00
|
|
|
|
|
|
|
return true;
|
1992-01-24 22:44:51 +00:00
|
|
|
}
|