1991-11-02 23:37:07 +01:00
|
|
|
/* BFD library support routines for constructors
|
|
|
|
Copyright (C) 1990-1991 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Hacked by Steve Chamberlain of Cygnus Support. With some help from
|
|
|
|
Judy Chamberlain too.
|
|
|
|
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
1991-12-01 01:39:12 +01:00
|
|
|
/*
|
|
|
|
SECTION
|
|
|
|
Constructors
|
|
|
|
|
|
|
|
Classes in C++ have 'constructors' and 'destructors'. These
|
|
|
|
are functions which are called automatically by the language
|
|
|
|
whenever data of a class is created or destroyed. Class data
|
|
|
|
which is static data may also be have a type which requires
|
|
|
|
'construction', the contructor must be called before the data
|
|
|
|
can be referenced, so the contructor must be called before the
|
|
|
|
program begins.
|
|
|
|
|
|
|
|
The common solution to this problem is for the compiler to
|
|
|
|
call a magic function as the first statement <<main>>.
|
|
|
|
This magic function, (often called <<__main>>) runs around
|
|
|
|
calling the constructors for all the things needing it.
|
|
|
|
|
|
|
|
With COFF the compile has a bargain with the linker et al.
|
|
|
|
All constructors are given strange names, for example
|
|
|
|
<<__GLOBAL__$I$foo>> might be the label of a contructor for
|
|
|
|
the class @var{foo}. The solution on unfortunate systems
|
|
|
|
(most system V machines) is to perform a partial link on all
|
|
|
|
the .o files, do an <<nm>> on the result, run <<awk>> or some
|
|
|
|
such over the result looking for strange <<__GLOBAL__$>>
|
|
|
|
symbols, generate a C program from this, compile it and link
|
|
|
|
with the partially linked input. This process is usually
|
|
|
|
called <<collect>>.
|
|
|
|
|
|
|
|
Some versions of <<a.out>> use something called the
|
|
|
|
<<set_vector>> mechanism. The constructor symbols are output
|
|
|
|
from the compiler with a special stab code saying that they
|
|
|
|
are constructors, and the linker can deal with them directly.
|
|
|
|
|
|
|
|
BFD allows applications (ie the linker) to deal with
|
|
|
|
constructor information independently of their external
|
|
|
|
implimentation by providing a set of entry points for the
|
|
|
|
indiviual object back ends to call which maintains a database
|
|
|
|
of the contructor information. The application can
|
|
|
|
interrogate the database to find out what it wants. The
|
|
|
|
construction data essential for the linker to be able to
|
|
|
|
perform its job are:
|
|
|
|
|
1992-08-26 00:04:53 +02:00
|
|
|
o asymbol -
|
1991-12-01 01:39:12 +01:00
|
|
|
The asymbol of the contructor entry point contains all the
|
|
|
|
information necessary to call the function.
|
|
|
|
|
1992-08-26 00:04:53 +02:00
|
|
|
o table id -
|
1991-12-01 01:39:12 +01:00
|
|
|
The type of symbol, ie is it a contructor, a destructor or
|
|
|
|
something else someone dreamed up to make our lives difficult.
|
|
|
|
|
|
|
|
This module takes this information and then builds extra
|
|
|
|
sections attached to the bfds which own the entry points. It
|
|
|
|
creates these sections as if they were tables of pointers to
|
|
|
|
the entry points, and builds relocation entries to go with
|
|
|
|
them so that the tables can be relocated along with the data
|
|
|
|
they reference.
|
|
|
|
|
|
|
|
These sections are marked with a special bit
|
|
|
|
(<<SEC_CONSTRUCTOR>>) which the linker notices and do with
|
|
|
|
what it wants.
|
1991-11-02 23:37:07 +01:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <bfd.h>
|
|
|
|
#include <sysdep.h>
|
|
|
|
#include <libbfd.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
1991-12-01 01:39:12 +01:00
|
|
|
/*
|
* aoutx.h, archive.c, archures.c, bfd.c, cache.c, coff-m88k.c,
coffcode.h, core.c, ctor.c, elf.c, format.c, ieee.c, init.c,
libbfd.c, libbfd.h, libcoff.h, opncls.c, reloc.c, section.c,
srec.c, syms.c, targets.c : all new documentation and lint
removal.
1991-12-08 01:56:56 +01:00
|
|
|
INTERNAL_FUNCTION
|
1991-12-01 01:39:12 +01:00
|
|
|
bfd_constructor_entry
|
1991-11-02 23:37:07 +01:00
|
|
|
|
* aoutx.h, archive.c, archures.c, bfd.c, cache.c, coff-m88k.c,
coffcode.h, core.c, ctor.c, elf.c, format.c, ieee.c, init.c,
libbfd.c, libbfd.h, libcoff.h, opncls.c, reloc.c, section.c,
srec.c, syms.c, targets.c : all new documentation and lint
removal.
1991-12-08 01:56:56 +01:00
|
|
|
SYNOPSIS
|
|
|
|
void bfd_constructor_entry(bfd *abfd,
|
|
|
|
asymbol **symbol_ptr_ptr,
|
|
|
|
CONST char*type);
|
|
|
|
|
|
|
|
|
1991-12-01 01:39:12 +01:00
|
|
|
DESCRIPTION
|
|
|
|
This function is called with an a symbol describing the
|
|
|
|
function to be called, an string which descibes the xtor type,
|
syms.c (asymbol): Added new field "app_data", for data particular to the
application. Some of the linker flags ought to get moved to this field
someday.
archures.c (bfd_default_scan): Recognize a few more numbers: 80486, 80960,
and 960.
bfd-in.h, bfd.c, targets.c, coffcode.h, coff-mips.c, other targets: Moved COFF
swap table to backend data.
hosts/i386linux.h: Include unistd.h.
aoutx.h, libaout.h, stab-syms.c: stab names are now in constant storage.
trad-core.c: Fixed some `PARAMS' uses that were missing parentheses.
aoutx.h, archive.c, archures.c, coffcode.h, ctor.c, reloc.c, syms.c: Doc fixes.
1992-12-04 00:03:17 +01:00
|
|
|
e.g., something like "CTOR" or "DTOR" would be fine. And the bfd
|
1991-12-01 01:39:12 +01:00
|
|
|
which owns the function. Its duty is to create a section
|
|
|
|
called "CTOR" or "DTOR" or whatever if the bfd doesn't already
|
|
|
|
have one, and grow a relocation table for the entry points as
|
|
|
|
they accumulate.
|
1991-11-02 23:37:07 +01:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void DEFUN(bfd_constructor_entry,(abfd, symbol_ptr_ptr, type),
|
|
|
|
bfd *abfd AND
|
|
|
|
asymbol **symbol_ptr_ptr AND
|
|
|
|
CONST char *type)
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Look up the section we're using to store the table in */
|
|
|
|
asection *rel_section = bfd_get_section_by_name (abfd, type);
|
|
|
|
if (rel_section == (asection *)NULL) {
|
|
|
|
rel_section = bfd_make_section (abfd, type);
|
|
|
|
rel_section->flags = SEC_CONSTRUCTOR;
|
|
|
|
rel_section->alignment_power = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a relocation into the section which references the entry
|
|
|
|
point */
|
|
|
|
{
|
|
|
|
arelent_chain *reloc = (arelent_chain *)bfd_alloc(abfd,
|
|
|
|
sizeof(arelent_chain));
|
|
|
|
|
1992-01-24 23:44:51 +01:00
|
|
|
/* reloc->relent.section = (asection *)NULL;*/
|
1991-11-02 23:37:07 +01:00
|
|
|
reloc->relent.addend = 0;
|
|
|
|
|
|
|
|
reloc->relent.sym_ptr_ptr = symbol_ptr_ptr;
|
|
|
|
reloc->next = rel_section->constructor_chain;
|
|
|
|
rel_section->constructor_chain = reloc;
|
1992-01-24 23:44:51 +01:00
|
|
|
reloc->relent.address = rel_section->_cooked_size;
|
1991-11-02 23:37:07 +01:00
|
|
|
/* ask the cpu which howto to use */
|
1992-05-26 05:45:31 +02:00
|
|
|
reloc->relent.howto = bfd_reloc_type_lookup(abfd, BFD_RELOC_CTOR);
|
1992-01-24 23:44:51 +01:00
|
|
|
rel_section->_cooked_size += sizeof(int *);
|
1991-11-02 23:37:07 +01:00
|
|
|
rel_section->reloc_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|