head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.4
	netbsd-11-0-RC3:1.1.1.4
	netbsd-11-0-RC2:1.1.1.4
	binutils-2-46:1.1.1.6
	netbsd-11-0-RC1:1.1.1.4
	binutils-2-45:1.1.1.5
	perseant-exfatfs-base-20250801:1.1.1.4
	netbsd-11:1.1.1.4.0.2
	netbsd-11-base:1.1.1.4
	netbsd-10-1-RELEASE:1.1.1.2
	perseant-exfatfs-base-20240630:1.1.1.4
	binutils-2-42:1.1.1.4
	perseant-exfatfs:1.1.1.3.0.2
	perseant-exfatfs-base:1.1.1.3
	netbsd-9-4-RELEASE:1.1.1.1
	netbsd-10-0-RELEASE:1.1.1.2
	netbsd-10-0-RC6:1.1.1.2
	netbsd-10-0-RC5:1.1.1.2
	netbsd-10-0-RC4:1.1.1.2
	netbsd-10-0-RC3:1.1.1.2
	netbsd-10-0-RC2:1.1.1.2
	netbsd-10-0-RC1:1.1.1.2
	binutils-2-39:1.1.1.3
	netbsd-10:1.1.1.2.0.6
	netbsd-10-base:1.1.1.2
	netbsd-9-3-RELEASE:1.1.1.1
	cjep_sun2x-base1:1.1.1.2
	cjep_sun2x:1.1.1.2.0.4
	cjep_sun2x-base:1.1.1.2
	cjep_staticlib_x-base1:1.1.1.2
	netbsd-9-2-RELEASE:1.1.1.1
	cjep_staticlib_x:1.1.1.2.0.2
	cjep_staticlib_x-base:1.1.1.2
	netbsd-9-1-RELEASE:1.1.1.1
	phil-wifi-20200421:1.1.1.2
	phil-wifi-20200411:1.1.1.2
	is-mlppp:1.1.1.1.0.8
	is-mlppp-base:1.1.1.1
	phil-wifi-20200406:1.1.1.2
	binutils-2-34:1.1.1.2
	netbsd-9-0-RELEASE:1.1.1.1
	netbsd-9-0-RC2:1.1.1.1
	netbsd-9-0-RC1:1.1.1.1
	phil-wifi-20191119:1.1.1.1
	netbsd-9:1.1.1.1.0.6
	netbsd-9-base:1.1.1.1
	phil-wifi:1.1.1.1.0.4
	phil-wifi-20190609:1.1.1.1
	pgoyette-compat-merge-20190127:1.1.1.1.2.2
	pgoyette-compat-20190127:1.1.1.1
	pgoyette-compat-20190118:1.1.1.1
	pgoyette-compat-1226:1.1.1.1
	pgoyette-compat:1.1.1.1.0.2
	pgoyette-compat-1126:1.1.1.1
	binutils-2-31-1:1.1.1.1
	FSF:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2018.11.06.21.19.02;	author christos;	state Exp;
branches
	1.1.1.1;
next	;
commitid	6Ndf2Zuj4yZRAVYA;

1.1.1.1
date	2018.11.06.21.19.02;	author christos;	state Exp;
branches
	1.1.1.1.2.1
	1.1.1.1.4.1;
next	1.1.1.2;
commitid	6Ndf2Zuj4yZRAVYA;

1.1.1.2
date	2020.04.03.23.40.02;	author christos;	state Exp;
branches;
next	1.1.1.3;
commitid	qJOWzDWs5P5cQZ2C;

1.1.1.3
date	2022.12.23.19.01.12;	author christos;	state Exp;
branches
	1.1.1.3.2.1;
next	1.1.1.4;
commitid	AaAP7ITTx5JnmI6E;

1.1.1.4
date	2024.06.30.16.01.10;	author christos;	state Exp;
branches;
next	1.1.1.5;
commitid	Eqxmo2uubpM9w1gF;

1.1.1.5
date	2025.08.25.14.43.26;	author christos;	state Exp;
branches;
next	1.1.1.6;
commitid	aUBKFf4jmEzPv78G;

1.1.1.6
date	2026.02.11.19.50.28;	author christos;	state Exp;
branches;
next	;
commitid	vybCSY05tblOMZtG;

1.1.1.1.2.1
date	2018.11.06.21.19.02;	author pgoyette;	state dead;
branches;
next	1.1.1.1.2.2;
commitid	Zj4q5SspGdKXto1B;

1.1.1.1.2.2
date	2018.11.26.01.50.19;	author pgoyette;	state Exp;
branches;
next	;
commitid	Zj4q5SspGdKXto1B;

1.1.1.1.4.1
date	2018.11.06.21.19.02;	author christos;	state dead;
branches;
next	1.1.1.1.4.2;
commitid	jtc8rnCzWiEEHGqB;

1.1.1.1.4.2
date	2019.06.10.21.52.23;	author christos;	state Exp;
branches;
next	1.1.1.1.4.3;
commitid	jtc8rnCzWiEEHGqB;

1.1.1.1.4.3
date	2020.04.08.14.04.46;	author martin;	state Exp;
branches;
next	;
commitid	Qli2aW9E74UFuA3C;

1.1.1.3.2.1
date	2024.07.01.01.00.19;	author perseant;	state Exp;
branches;
next	;
commitid	NkoYLLCQWWw9v4gF;


desc
@@


1.1
log
@Initial revision
@
text
@\input texinfo
@@setfilename ldint.info
@@c Copyright (C) 1992-2018 Free Software Foundation, Inc.

@@ifnottex
@@dircategory Software development
@@direntry
* Ld-Internals: (ldint).	The GNU linker internals.
@@end direntry
@@end ifnottex

@@copying
This file documents the internals of the GNU linker ld.

Copyright @@copyright{} 1992-2018 Free Software Foundation, Inc.
Contributed by Cygnus Support.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``GNU General Public License'' and ``Funding
Free Software'', the Front-Cover texts being (a) (see below), and with
the Back-Cover Texts being (b) (see below).  A copy of the license is
included in the section entitled ``GNU Free Documentation License''.

(a) The FSF's Front-Cover Text is:

     A GNU Manual

(b) The FSF's Back-Cover Text is:

     You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development.
@@end copying

@@iftex
@@finalout
@@setchapternewpage off
@@settitle GNU Linker Internals
@@titlepage
@@title{A guide to the internals of the GNU linker}
@@author Per Bothner, Steve Chamberlain, Ian Lance Taylor, DJ Delorie
@@author Cygnus Support
@@page

@@tex
\def\$#1${{#1}}  % Kluge: collect RCS revision info without $...$
\xdef\manvers{2.10.91}  % For use in headers, footers too
{\parskip=0pt
\hfill Cygnus Support\par
\hfill \manvers\par
\hfill \TeX{}info \texinfoversion\par
}
@@end tex

@@vskip 0pt plus 1filll
Copyright @@copyright{} 1992-2018 Free Software Foundation, Inc.

      Permission is granted to copy, distribute and/or modify this document
      under the terms of the GNU Free Documentation License, Version 1.3
      or any later version published by the Free Software Foundation;
      with no Invariant Sections, with no Front-Cover Texts, and with no
      Back-Cover Texts.  A copy of the license is included in the
      section entitled "GNU Free Documentation License".

@@end titlepage
@@end iftex

@@node Top
@@top

This file documents the internals of the GNU linker @@code{ld}.  It is a
collection of miscellaneous information with little form at this point.
Mostly, it is a repository into which you can put information about
GNU @@code{ld} as you discover it (or as you design changes to @@code{ld}).

This document is distributed under the terms of the GNU Free
Documentation License.  A copy of the license is included in the
section entitled "GNU Free Documentation License".

@@menu
* README::			The README File
* Emulations::			How linker emulations are generated
* Emulation Walkthrough::	A Walkthrough of a Typical Emulation
* Architecture Specific::	Some Architecture Specific Notes
* GNU Free Documentation License::  GNU Free Documentation License
@@end menu

@@node README
@@chapter The @@file{README} File

Check the @@file{README} file; it often has useful information that does not
appear anywhere else in the directory.

@@node Emulations
@@chapter How linker emulations are generated

Each linker target has an @@dfn{emulation}.  The emulation includes the
default linker script, and certain emulations also modify certain types
of linker behaviour.

Emulations are created during the build process by the shell script
@@file{genscripts.sh}.

The @@file{genscripts.sh} script starts by reading a file in the
@@file{emulparams} directory.  This is a shell script which sets various
shell variables used by @@file{genscripts.sh} and the other shell scripts
it invokes.

The @@file{genscripts.sh} script will invoke a shell script in the
@@file{scripttempl} directory in order to create default linker scripts
written in the linker command language.  The @@file{scripttempl} script
will be invoked 5 (or, in some cases, 6) times, with different
assignments to shell variables, to create different default scripts.
The choice of script is made based on the command line options.

After creating the scripts, @@file{genscripts.sh} will invoke yet another
shell script, this time in the @@file{emultempl} directory.  That shell
script will create the emulation source file, which contains C code.
This C code permits the linker emulation to override various linker
behaviours.  Most targets use the generic emulation code, which is in
@@file{emultempl/generic.em}.

To summarize, @@file{genscripts.sh} reads three shell scripts: an
emulation parameters script in the @@file{emulparams} directory, a linker
script generation script in the @@file{scripttempl} directory, and an
emulation source file generation script in the @@file{emultempl}
directory.

For example, the Sun 4 linker sets up variables in
@@file{emulparams/sun4.sh}, creates linker scripts using
@@file{scripttempl/aout.sc}, and creates the emulation code using
@@file{emultempl/sunos.em}.

Note that the linker can support several emulations simultaneously,
depending upon how it is configured.  An emulation can be selected with
the @@code{-m} option.  The @@code{-V} option will list all supported
emulations.

@@menu
* emulation parameters::        @@file{emulparams} scripts
* linker scripts::              @@file{scripttempl} scripts
* linker emulations::           @@file{emultempl} scripts
@@end menu

@@node emulation parameters
@@section @@file{emulparams} scripts

Each target selects a particular file in the @@file{emulparams} directory
by setting the shell variable @@code{targ_emul} in @@file{configure.tgt}.
This shell variable is used by the @@file{configure} script to control
building an emulation source file.

Certain conventions are enforced.  Suppose the @@code{targ_emul} variable
is set to @@var{emul} in @@file{configure.tgt}.  The name of the emulation
shell script will be @@file{emulparams/@@var{emul}.sh}.  The
@@file{Makefile} must have a target named @@file{e@@var{emul}.c}; this
target must depend upon @@file{emulparams/@@var{emul}.sh}, as well as the
appropriate scripts in the @@file{scripttempl} and @@file{emultempl}
directories.  The @@file{Makefile} target must invoke @@code{GENSCRIPTS}
with two arguments: @@var{emul}, and the value of the make variable
@@code{tdir_@@var{emul}}.  The value of the latter variable will be set by
the @@file{configure} script, and is used to set the default target
directory to search.

By convention, the @@file{emulparams/@@var{emul}.sh} shell script should
only set shell variables.  It may set shell variables which are to be
interpreted by the @@file{scripttempl} and the @@file{emultempl} scripts.
Certain shell variables are interpreted directly by the
@@file{genscripts.sh} script.

Here is a list of shell variables interpreted by @@file{genscripts.sh},
as well as some conventional shell variables interpreted by the
@@file{scripttempl} and @@file{emultempl} scripts.

@@table @@code
@@item SCRIPT_NAME
This is the name of the @@file{scripttempl} script to use.  If
@@code{SCRIPT_NAME} is set to @@var{script}, @@file{genscripts.sh} will use
the script @@file{scripttempl/@@var{script}.sc}.

@@item TEMPLATE_NAME
This is the name of the @@file{emultempl} script to use.  If
@@code{TEMPLATE_NAME} is set to @@var{template}, @@file{genscripts.sh} will
use the script @@file{emultempl/@@var{template}.em}.  If this variable is
not set, the default value is @@samp{generic}.

@@item GENERATE_SHLIB_SCRIPT
If this is set to a nonempty string, @@file{genscripts.sh} will invoke
the @@file{scripttempl} script an extra time to create a shared library
script.  @@ref{linker scripts}.

@@item OUTPUT_FORMAT
This is normally set to indicate the BFD output format use (e.g.,
@@samp{"a.out-sunos-big"}.  The @@file{scripttempl} script will normally
use it in an @@code{OUTPUT_FORMAT} expression in the linker script.

@@item ARCH
This is normally set to indicate the architecture to use (e.g.,
@@samp{sparc}).  The @@file{scripttempl} script will normally use it in an
@@code{OUTPUT_ARCH} expression in the linker script.

@@item ENTRY
Some @@file{scripttempl} scripts use this to set the entry address, in an
@@code{ENTRY} expression in the linker script.

@@item TEXT_START_ADDR
Some @@file{scripttempl} scripts use this to set the start address of the
@@samp{.text} section.

@@item SEGMENT_SIZE
The @@file{genscripts.sh} script uses this to set the default value of
@@code{DATA_ALIGNMENT} when running the @@file{scripttempl} script.

@@item TARGET_PAGE_SIZE
If @@code{SEGMENT_SIZE} is not defined, the @@file{genscripts.sh} script
uses this to define it.

@@item ALIGNMENT
Some @@file{scripttempl} scripts set this to a number to pass to
@@code{ALIGN} to set the required alignment for the @@code{end} symbol.
@@end table

@@node linker scripts
@@section @@file{scripttempl} scripts

Each linker target uses a @@file{scripttempl} script to generate the
default linker scripts.  The name of the @@file{scripttempl} script is
set by the @@code{SCRIPT_NAME} variable in the @@file{emulparams} script.
If @@code{SCRIPT_NAME} is set to @@var{script}, @@code{genscripts.sh} will
invoke @@file{scripttempl/@@var{script}.sc}.

The @@file{genscripts.sh} script will invoke the @@file{scripttempl}
script 5 to 9 times.  Each time it will set the shell variable
@@code{LD_FLAG} to a different value.  When the linker is run, the
options used will direct it to select a particular script.  (Script
selection is controlled by the @@code{get_script} emulation entry point;
this describes the conventional behaviour).

The @@file{scripttempl} script should just write a linker script, written
in the linker command language, to standard output.  If the emulation
name--the name of the @@file{emulparams} file without the @@file{.sc}
extension--is @@var{emul}, then the output will be directed to
@@file{ldscripts/@@var{emul}.@@var{extension}} in the build directory,
where @@var{extension} changes each time the @@file{scripttempl} script is
invoked.

Here is the list of values assigned to @@code{LD_FLAG}.

@@table @@code
@@item (empty)
The script generated is used by default (when none of the following
cases apply).  The output has an extension of @@file{.x}.
@@item n
The script generated is used when the linker is invoked with the
@@code{-n} option.  The output has an extension of @@file{.xn}.
@@item N
The script generated is used when the linker is invoked with the
@@code{-N} option.  The output has an extension of @@file{.xbn}.
@@item r
The script generated is used when the linker is invoked with the
@@code{-r} option.  The output has an extension of @@file{.xr}.
@@item u
The script generated is used when the linker is invoked with the
@@code{-Ur} option.  The output has an extension of @@file{.xu}.
@@item shared
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_SHLIB_SCRIPT} is defined in the
@@file{emulparams} file.  The @@file{emultempl} script must arrange to use
this script at the appropriate time, normally when the linker is invoked
with the @@code{-shared} option.  The output has an extension of
@@file{.xs}.
@@item c
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_COMBRELOC_SCRIPT} is defined in the
@@file{emulparams} file or if @@code{SCRIPT_NAME} is @@code{elf}. The
@@file{emultempl} script must arrange to use this script at the appropriate
time, normally when the linker is invoked with the @@code{-z combreloc}
option.  The output has an extension of
@@file{.xc}.
@@item cshared
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_COMBRELOC_SCRIPT} is defined in the
@@file{emulparams} file or if @@code{SCRIPT_NAME} is @@code{elf} and
@@code{GENERATE_SHLIB_SCRIPT} is defined in the @@file{emulparams} file.
The @@file{emultempl} script must arrange to use this script at the
appropriate time, normally when the linker is invoked with the @@code{-shared
-z combreloc} option.  The output has an extension of @@file{.xsc}.
@@item auto_import
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_AUTO_IMPORT_SCRIPT} is defined in the
@@file{emulparams} file.  The @@file{emultempl} script must arrange to
use this script at the appropriate time, normally when the linker is
invoked with the @@code{--enable-auto-import} option.  The output has
an extension of @@file{.xa}.
@@end table

Besides the shell variables set by the @@file{emulparams} script, and the
@@code{LD_FLAG} variable, the @@file{genscripts.sh} script will set
certain variables for each run of the @@file{scripttempl} script.

@@table @@code
@@item RELOCATING
This will be set to a non-empty string when the linker is doing a final
relocation (e.g., all scripts other than @@code{-r} and @@code{-Ur}).

@@item CONSTRUCTING
This will be set to a non-empty string when the linker is building
global constructor and destructor tables (e.g., all scripts other than
@@code{-r}).

@@item DATA_ALIGNMENT
This will be set to an @@code{ALIGN} expression when the output should be
page aligned, or to @@samp{.} when generating the @@code{-N} script.

@@item CREATE_SHLIB
This will be set to a non-empty string when generating a @@code{-shared}
script.

@@item COMBRELOC
This will be set to a non-empty string when generating @@code{-z combreloc}
scripts to a temporary file name which can be used during script generation.
@@end table

The conventional way to write a @@file{scripttempl} script is to first
set a few shell variables, and then write out a linker script using
@@code{cat} with a here document.  The linker script will use variable
substitutions, based on the above variables and those set in the
@@file{emulparams} script, to control its behaviour.

When there are parts of the @@file{scripttempl} script which should only
be run when doing a final relocation, they should be enclosed within a
variable substitution based on @@code{RELOCATING}.  For example, on many
targets special symbols such as @@code{_end} should be defined when doing
a final link.  Naturally, those symbols should not be defined when doing
a relocatable link using @@code{-r}.  The @@file{scripttempl} script
could use a construct like this to define those symbols:
@@smallexample
  $@@{RELOCATING+ _end = .;@@}
@@end smallexample
This will do the symbol assignment only if the @@code{RELOCATING}
variable is defined.

The basic job of the linker script is to put the sections in the correct
order, and at the correct memory addresses.  For some targets, the
linker script may have to do some other operations.

For example, on most MIPS platforms, the linker is responsible for
defining the special symbol @@code{_gp}, used to initialize the
@@code{$gp} register.  It must be set to the start of the small data
section plus @@code{0x8000}.  Naturally, it should only be defined when
doing a final relocation.  This will typically be done like this:
@@smallexample
  $@@{RELOCATING+ _gp = ALIGN(16) + 0x8000;@@}
@@end smallexample
This line would appear just before the sections which compose the small
data section (@@samp{.sdata}, @@samp{.sbss}).  All those sections would be
contiguous in memory.

Many COFF systems build constructor tables in the linker script.  The
compiler will arrange to output the address of each global constructor
in a @@samp{.ctor} section, and the address of each global destructor in
a @@samp{.dtor} section (this is done by defining
@@code{ASM_OUTPUT_CONSTRUCTOR} and @@code{ASM_OUTPUT_DESTRUCTOR} in the
@@code{gcc} configuration files).  The @@code{gcc} runtime support
routines expect the constructor table to be named @@code{__CTOR_LIST__}.
They expect it to be a list of words, with the first word being the
count of the number of entries.  There should be a trailing zero word.
(Actually, the count may be -1 if the trailing word is present, and the
trailing word may be omitted if the count is correct, but, as the
@@code{gcc} behaviour has changed slightly over the years, it is safest
to provide both).  Here is a typical way that might be handled in a
@@file{scripttempl} file.
@@smallexample
    $@@{CONSTRUCTING+ __CTOR_LIST__ = .;@@}
    $@@{CONSTRUCTING+ LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)@@}
    $@@{CONSTRUCTING+ *(.ctors)@@}
    $@@{CONSTRUCTING+ LONG(0)@@}
    $@@{CONSTRUCTING+ __CTOR_END__ = .;@@}
    $@@{CONSTRUCTING+ __DTOR_LIST__ = .;@@}
    $@@{CONSTRUCTING+ LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)@@}
    $@@{CONSTRUCTING+ *(.dtors)@@}
    $@@{CONSTRUCTING+ LONG(0)@@}
    $@@{CONSTRUCTING+ __DTOR_END__ = .;@@}
@@end smallexample
The use of @@code{CONSTRUCTING} ensures that these linker script commands
will only appear when the linker is supposed to be building the
constructor and destructor tables.  This example is written for a target
which uses 4 byte pointers.

Embedded systems often need to set a stack address.  This is normally
best done by using the @@code{PROVIDE} construct with a default stack
address.  This permits the user to easily override the stack address
using the @@code{--defsym} option.  Here is an example:
@@smallexample
  $@@{RELOCATING+ PROVIDE (__stack = 0x80000000);@@}
@@end smallexample
The value of the symbol @@code{__stack} would then be used in the startup
code to initialize the stack pointer.

@@node linker emulations
@@section @@file{emultempl} scripts

Each linker target uses an @@file{emultempl} script to generate the
emulation code.  The name of the @@file{emultempl} script is set by the
@@code{TEMPLATE_NAME} variable in the @@file{emulparams} script.  If the
@@code{TEMPLATE_NAME} variable is not set, the default is
@@samp{generic}.  If the value of @@code{TEMPLATE_NAME} is @@var{template},
@@file{genscripts.sh} will use @@file{emultempl/@@var{template}.em}.

Most targets use the generic @@file{emultempl} script,
@@file{emultempl/generic.em}.  A different @@file{emultempl} script is
only needed if the linker must support unusual actions, such as linking
against shared libraries.

The @@file{emultempl} script is normally written as a simple invocation
of @@code{cat} with a here document.  The document will use a few
variable substitutions.  Typically each function names uses a
substitution involving @@code{EMULATION_NAME}, for ease of debugging when
the linker supports multiple emulations.

Every function and variable in the emitted file should be static.  The
only globally visible object must be named
@@code{ld_@@var{EMULATION_NAME}_emulation}, where @@var{EMULATION_NAME} is
the name of the emulation set in @@file{configure.tgt} (this is also the
name of the @@file{emulparams} file without the @@file{.sh} extension).
The @@file{genscripts.sh} script will set the shell variable
@@code{EMULATION_NAME} before invoking the @@file{emultempl} script.

The @@code{ld_@@var{EMULATION_NAME}_emulation} variable must be a
@@code{struct ld_emulation_xfer_struct}, as defined in @@file{ldemul.h}.
It defines a set of function pointers which are invoked by the linker,
as well as strings for the emulation name (normally set from the shell
variable @@code{EMULATION_NAME} and the default BFD target name (normally
set from the shell variable @@code{OUTPUT_FORMAT} which is normally set
by the @@file{emulparams} file).

The @@file{genscripts.sh} script will set the shell variable
@@code{COMPILE_IN} when it invokes the @@file{emultempl} script for the
default emulation.  In this case, the @@file{emultempl} script should
include the linker scripts directly, and return them from the
@@code{get_scripts} entry point.  When the emulation is not the default,
the @@code{get_scripts} entry point should just return a file name.  See
@@file{emultempl/generic.em} for an example of how this is done.

At some point, the linker emulation entry points should be documented.

@@node Emulation Walkthrough
@@chapter A Walkthrough of a Typical Emulation

This chapter is to help people who are new to the way emulations
interact with the linker, or who are suddenly thrust into the position
of having to work with existing emulations.  It will discuss the files
you need to be aware of.  It will tell you when the given "hooks" in
the emulation will be called.  It will, hopefully, give you enough
information about when and how things happen that you'll be able to
get by.  As always, the source is the definitive reference to this.

The starting point for the linker is in @@file{ldmain.c} where
@@code{main} is defined.  The bulk of the code that's emulation
specific will initially be in @@code{emultempl/@@var{emulation}.em} but
will end up in @@code{e@@var{emulation}.c} when the build is done.
Most of the work to select and interface with emulations is in
@@code{ldemul.h} and @@code{ldemul.c}.  Specifically, @@code{ldemul.h}
defines the @@code{ld_emulation_xfer_struct} structure your emulation
exports.

Your emulation file exports a symbol
@@code{ld_@@var{EMULATION_NAME}_emulation}.  If your emulation is
selected (it usually is, since usually there's only one),
@@code{ldemul.c} sets the variable @@var{ld_emulation} to point to it.
@@code{ldemul.c} also defines a number of API functions that interface
to your emulation, like @@code{ldemul_after_parse} which simply calls
your @@code{ld_@@var{EMULATION}_emulation.after_parse} function.  For
the rest of this section, the functions will be mentioned, but you
should assume the indirect reference to your emulation also.

We will also skip or gloss over parts of the link process that don't
relate to emulations, like setting up internationalization.

After initialization, @@code{main} selects an emulation by pre-scanning
the command line arguments.  It calls @@code{ldemul_choose_target} to
choose a target.  If you set @@code{choose_target} to
@@code{ldemul_default_target}, it picks your @@code{target_name} by
default.

@@code{main} calls @@code{ldemul_before_parse}, then @@code{parse_args}.
@@code{parse_args} calls @@code{ldemul_parse_args} for each arg, which
must update the @@code{getopt} globals if it recognizes the argument.
If the emulation doesn't recognize it, then parse_args checks to see
if it recognizes it.

Now that the emulation has had access to all its command-line options,
@@code{main} calls @@code{ldemul_set_symbols}.  This can be used for any
initialization that may be affected by options.  It is also supposed
to set up any variables needed by the emulation script.

@@code{main} now calls @@code{ldemul_get_script} to get the emulation
script to use (based on arguments, no doubt, @@pxref{Emulations}) and
runs it.  While parsing, @@code{ldgram.y} may call @@code{ldemul_hll} or
@@code{ldemul_syslib} to handle the @@code{HLL} or @@code{SYSLIB}
commands.  It may call @@code{ldemul_unrecognized_file} if you asked
the linker to link a file it doesn't recognize.  It will call
@@code{ldemul_recognized_file} for each file it does recognize, in case
the emulation wants to handle some files specially.  All the while,
it's loading the files (possibly calling
@@code{ldemul_open_dynamic_archive}) and symbols and stuff.  After it's
done reading the script, @@code{main} calls @@code{ldemul_after_parse}.
Use the after-parse hook to set up anything that depends on stuff the
script might have set up, like the entry point.

@@code{main} next calls @@code{lang_process} in @@code{ldlang.c}.  This
appears to be the main core of the linking itself, as far as emulation
hooks are concerned(*).  It first opens the output file's BFD, calling
@@code{ldemul_set_output_arch}, and calls
@@code{ldemul_create_output_section_statements} in case you need to use
other means to find or create object files (i.e. shared libraries
found on a path, or fake stub objects).  Despite the name, nobody
creates output sections here.

(*) In most cases, the BFD library does the bulk of the actual
linking, handling symbol tables, symbol resolution, relocations, and
building the final output file.  See the BFD reference for all the
details.  Your emulation is usually concerned more with managing
things at the file and section level, like "put this here, add this
section", etc.

Next, the objects to be linked are opened and BFDs created for them,
and @@code{ldemul_after_open} is called.  At this point, you have all
the objects and symbols loaded, but none of the data has been placed
yet.

Next comes the Big Linking Thingy (except for the parts BFD does).
All input sections are mapped to output sections according to the
script.  If a section doesn't get mapped by default,
@@code{ldemul_place_orphan} will get called to figure out where it goes.
Next it figures out the offsets for each section, calling
@@code{ldemul_before_allocation} before and
@@code{ldemul_after_allocation} after deciding where each input section
ends up in the output sections.

The last part of @@code{lang_process} is to figure out all the symbols'
values.  After assigning final values to the symbols,
@@code{ldemul_finish} is called, and after that, any undefined symbols
are turned into fatal errors.

OK, back to @@code{main}, which calls @@code{ldwrite} in
@@file{ldwrite.c}.  @@code{ldwrite} calls BFD's final_link, which does
all the relocation fixups and writes the output bfd to disk, and we're
done.

In summary,

@@itemize @@bullet

@@item @@code{main()} in @@file{ldmain.c}
@@item @@file{emultempl/@@var{EMULATION}.em} has your code
@@item @@code{ldemul_choose_target} (defaults to your @@code{target_name})
@@item @@code{ldemul_before_parse}
@@item Parse argv, calls @@code{ldemul_parse_args} for each
@@item @@code{ldemul_set_symbols}
@@item @@code{ldemul_get_script}
@@item parse script

@@itemize @@bullet
@@item may call @@code{ldemul_hll} or @@code{ldemul_syslib}
@@item may call @@code{ldemul_open_dynamic_archive}
@@end itemize

@@item @@code{ldemul_after_parse}
@@item @@code{lang_process()} in @@file{ldlang.c}

@@itemize @@bullet
@@item create @@code{output_bfd}
@@item @@code{ldemul_set_output_arch}
@@item @@code{ldemul_create_output_section_statements}
@@item read objects, create input bfds - all symbols exist, but have no values
@@item may call @@code{ldemul_unrecognized_file}
@@item will call @@code{ldemul_recognized_file}
@@item @@code{ldemul_after_open}
@@item map input sections to output sections
@@item may call @@code{ldemul_place_orphan} for remaining sections
@@item @@code{ldemul_before_allocation}
@@item gives input sections offsets into output sections, places output sections
@@item @@code{ldemul_after_allocation} - section addresses valid
@@item assigns values to symbols
@@item @@code{ldemul_finish} - symbol values valid
@@end itemize

@@item output bfd is written to disk

@@end itemize

@@node Architecture Specific
@@chapter Some Architecture Specific Notes

This is the place for notes on the behavior of @@code{ld} on
specific platforms.  Currently, only Intel x86 is documented (and
of that, only the auto-import behavior for DLLs).

@@menu
* ix86::                        Intel x86
@@end menu

@@node ix86
@@section Intel x86

@@table @@emph
@@code{ld} can create DLLs that operate with various runtimes available
on a common x86 operating system.  These runtimes include native (using
the mingw "platform"), cygwin, and pw.

@@item auto-import from DLLs
@@enumerate
@@item
With this feature on, DLL clients can import variables from DLL
without any concern from their side (for example, without any source
code modifications).  Auto-import can be enabled using the
@@code{--enable-auto-import} flag, or disabled via the
@@code{--disable-auto-import} flag.  Auto-import is disabled by default.

@@item
This is done completely in bounds of the PE specification (to be fair,
there's a minor violation of the spec at one point, but in practice
auto-import works on all known variants of that common x86 operating
system)  So, the resulting DLL can be used with any other PE
compiler/linker.

@@item
Auto-import is fully compatible with standard import method, in which
variables are decorated using attribute modifiers. Libraries of either
type may be mixed together.

@@item
Overhead (space): 8 bytes per imported symbol, plus 20 for each
reference to it; Overhead (load time): negligible; Overhead
(virtual/physical memory): should be less than effect of DLL
relocation.
@@end enumerate

Motivation

The obvious and only way to get rid of dllimport insanity is
to make client access variable directly in the DLL, bypassing
the extra dereference imposed by ordinary DLL runtime linking.
I.e., whenever client contains something like

@@code{mov dll_var,%eax,}

address of dll_var in the command should be relocated to point
into loaded DLL. The aim is to make OS loader do so, and than
make ld help with that.  Import section of PE made following
way: there's a vector of structures each describing imports
from particular DLL. Each such structure points to two other
parallel vectors: one holding imported names, and one which
will hold address of corresponding imported name. So, the
solution is de-vectorize these structures, making import
locations be sparse and pointing directly into code.

Implementation

For each reference of data symbol to be imported from DLL (to
set of which belong symbols with name <sym>, if __imp_<sym> is
found in implib), the import fixup entry is generated. That
entry is of type IMAGE_IMPORT_DESCRIPTOR and stored in .idata$3
subsection. Each fixup entry contains pointer to symbol's address
within .text section (marked with __fuN_<sym> symbol, where N is
integer), pointer to DLL name (so, DLL name is referenced by
multiple entries), and pointer to symbol name thunk. Symbol name
thunk is singleton vector (__nm_th_<symbol>) pointing to
IMAGE_IMPORT_BY_NAME structure (__nm_<symbol>) directly containing
imported name. Here comes that "om the edge" problem mentioned above:
PE specification rambles that name vector (OriginalFirstThunk) should
run in parallel with addresses vector (FirstThunk), i.e. that they
should have same number of elements and terminated with zero. We violate
this, since FirstThunk points directly into machine code. But in
practice, OS loader implemented the sane way: it goes thru
OriginalFirstThunk and puts addresses to FirstThunk, not something
else. It once again should be noted that dll and symbol name
structures are reused across fixup entries and should be there
anyway to support standard import stuff, so sustained overhead is
20 bytes per reference. Other question is whether having several
IMAGE_IMPORT_DESCRIPTORS for the same DLL is possible. Answer is yes,
it is done even by native compiler/linker (libth32's functions are in
fact resident in windows9x kernel32.dll, so if you use it, you have
two IMAGE_IMPORT_DESCRIPTORS for kernel32.dll). Yet other question is
whether referencing the same PE structures several times is valid.
The answer is why not, prohibiting that (detecting violation) would
require more work on behalf of loader than not doing it.

@@end table

@@node GNU Free Documentation License
@@chapter GNU Free Documentation License

@@include fdl.texi

@@contents
@@bye
@


1.1.1.1
log
@2018-07-18  Nick Clifton  <nickc@@redhat.com>

	2.31.1 Release point.

2018-07-18  Nick Clifton  <nickc@@redhat.com>

	* (DEVO_SUPPORT): Fix typo in previous delta.
	(do_proto_toplev): Add --quiet option to configure command line.

2018-07-16  Nick Clifton  <nickc@@redhat.com>

	* src-release.sh (DEVO_SUPPORT): Add test-driver and ar-lib.

2018-07-06  Sebastian Huber  <sebastian.huber@@embedded-brains.de>

	* config.sub: Sync with upstream version 2018-07-03.

2018-07-05  Sebastian Huber  <sebastian.huber@@embedded-brains.de>

	* config.guess: Sync with upstream version 2018-06-26.
	* config.sub: Sync with upstream version 2018-07-02.

2018-06-24  Nick Clifton  <nickc@@redhat.com>

	* configure: Regenerate.

2018-06-19  Simon Marchi  <simon.marchi@@ericsson.com>

	* libtool.m4: Use AC_LANG_SOURCE.
	* configure.ac: Remove AC_PREREQ, use AC_LANG_SOURCE.
	* README-maintainer-mode: Update version requirements.
	* ar-lib: New file.
	* test-driver: New file.
	* configure: Re-generate.

2018-06-18  Eric Botcazou  <ebotcazou@@adacore.com>

	* Makefile.def (fortran): Add check-target-libgomp-fortran.
	* Makefile.tpl (check-target-libgomp-fortran): New phony target.
	* Makefile.in: Regenerate.

	* configure: Regenerate.

2018-06-18  Simon Marchi  <simon.marchi@@ericsson.com>

	* configure.ac: Sync with GCC, remove MPX-related things.

2018-05-01  Nick Clifton  <nickc@@redhat.com>

	* config.guess: Synchronize with config project master sources.
	* config.sub: Likewise.

2018-05-01  Francois H. Theron  <francois.theron@@netronome.com>

	* configure.ac: Added "nfp" target.
	* configure: Regenerate.

2018-02-13  Maciej W. Rozycki  <macro@@mips.com>

	* configure.ac <wasm32-*-*> (noconfigdirs): Add `ld'.
	* configure: Regenerate.

2018-01-30  Nick Clifton  <nickc@@redhat.com>

	* src-release.sh (do_proto_toplev): Add patterns for more junk files
	to delete before creating the tarball.

2018-01-29  Nick Clifton  <nickc@@redhat.com>

	* src-release.sh (do_proto_toplev): Strip patch remnant files from
	the sources before creating the tarball.

2018-01-13  Nick Clifton  <nickc@@redhat.com>

	* src-release.sh: Update copyright notice.  Change reference to devo
	to be a reference to root.
@
text
@@


1.1.1.2
log
@Import binutils-2.34

2020-01-18  Nick Clifton  <nickc@@redhat.com>

	Binutils 2.34 branch created.

2020-01-18  Nick Clifton  <nickc@@redhat.com>

	Synchronize top level configure files with master version:

	2020-01-01  Ben Elliston  <bje@@gnu.org>

	* config.guess: Update copyright years.
	* config.sub: Likewise.

	2019-12-21  Ben Elliston  <bje@@gnu.org>

	* config.guess (set_cc_for_build): Prevent multiple calls by
	checking if $tmp is already set. We can't check CC_FOR_BUILD as
	the user may set it externally. Thanks to Torbjörn Granlund for
	the bug report.

	2019-12-21  Torbjörn Granlund  <tg@@gmplib.org>

	* config.guess (alpha:Linux:*:*): Guard against missing
	/proc/cpuinfo by redirecting standard error to /dev/null.

	2019-09-12  Daniel Bittman  <danielbittman1@@gmail.com>

	* config.guess (*:Twizzler:*:*): New.
	* config.sub (-twizzler*): New.

	2019-07-24  Ben Elliston  <bje@@gnu.org>

	* config.guess (mips:OSF1:*.*): Whitespace cleanup.

	2019-06-30  Ben Elliston  <bje@@gnu.org>

	* config.sub (case $os): Match nsk* and powerunix. Don't later
	match nsk* and set os=nsk which removes the OS version number.

	2019-06-30  Ben Elliston  <bje@@gnu.org>

	* config.sub: Recognise os108*.

	2019-06-26  Ben Elliston  <bje@@gnu.org>

	* config.sub (hp300): Set $os to hpux.

	2019-06-26  Ben Elliston  <bje@@gnu.org>

	* config.sub (vsta): Move into alphabetical order.

	2019-06-10  Ben Elliston  <bje@@gnu.org>

	* config.guess (*:OS108:*:*): Recognise new OS.

	2019-05-28  Ben Elliston  <bje@@gnu.org>

	* config.guess (*:Darwin:*:*): Run xcode-select to determine if a
	system compiler is installed. If not, do not run set_cc_for_build,
	as the default cc will open a dialog box asking to install
	Xcode. If no C compiler is available, guess based on uname -p and
	uname -m.

	2019-05-28  Ben Elliston  <bje@@gnu.org>

	* config.guess (*:Darwin:*:*): Simplify UNAME_PROCESSOR.

2020-01-17  Simon Marchi  <simon.marchi@@efficios.com>

	* Makefile.def: Add dependencies of all-gdbsupport on all-bfd.
	* Makefile.in: Re-generate.

2020-01-14  Tom Tromey  <tom@@tromey.com>

	* src-release.sh (GDB_SUPPORT_DIRS): Add gdbsupport.
	* MAINTAINERS: Add gdbsupport.
	* configure: Rebuild.
	* configure.ac (configdirs): Add gdbsupport.
	* gdbsupport: New directory, move from gdb/gdbsupport.
	* Makefile.def (host_modules, dependencies): Add gnulib.
	* Makefile.in: Rebuild.

2020-01-09  Aaron Merey  <amerey@@redhat.com>

        * config/debuginfod.m4: New file. Add macro AC_DEBUGINFOD. Adds
        new configure option --with-debuginfod.
        * configure: Regenerate.
        * configure.ac: Call AC_DEBUGINFOD.

2019-12-26  Christian Biesinger  <cbiesinger@@google.com>

	* .gitignore: Add perf.data and perf.data.old.

2019-10-17  Sergio Durigan Junior  <sergiodj@@redhat.com>

	* src-release.sh (GDB_SUPPORT_DIRS): Add libctf.

2019-10-17  Alan Modra  <amodra@@gmail.com>

	PR 29
	* src-release.sh (getver): Replace "head -1" with "head -n 1".

2019-07-30  Nick Alcock  <nick.alcock@@oracle.com>

	* Makefile.def (host_modules): libctf is no longer no_install.
	* Makefile.in: Regenerated.

2019-07-13  Nick Alcock  <nick.alcock@@oracle.com>

	* Makefile.def (dependencies): all-ld depends on all-libctf.
	* Makefile.in: Regenerated.

2019-09-09  Phil Blundell  <pb@@pbcl.net>

	binutils 2.33 branch created

2019-08-19  Tom Tromey  <tom@@tromey.com>

	* configure: Rebuild.
	* configure.ac: Add --with-static-standard-libraries.

2019-08-09  Nick Clifton  <nickc@@redhat.com>

	* libiberty: Sync with gcc.  Bring in:
	2019-08-08  Martin Liska  <mliska@@suse.cz>

	PR bootstrap/91352
	* lrealpath.c (is_valid_fd): New function.

	2019-07-24  Martin Liska  <mliska@@suse.cz>

	PR lto/91228
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	Find first '\0' starting from gnu_lto + 1.

	2019-07-12  Ren Kimura  <rkx1209dev@@gmail.com>

	* simple-object-elf.c (simple_object_elf_match): Check zero value shstrndx.
	This fixes a Bug 90924.

	2019-07-22  Martin Liska  <mliska@@suse.cz>

	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	Do not search for gnu_lto_v1, but search for first '\0'.

	2019-07-18  Eduard-Mihai Burtescu  <eddyb@@lyken.rs>

	* cplus-dem.c: Include rust-demangle.h.
	* rust-demangle.c: Include rust-demangle.h.
	* rust-demangle.h: New file.

	2019-05-31  Michael Forney  <mforney@@mforney.org>

	* cp-demangle.c: Don't define CP_DYNAMIC_ARRAYS if __STDC_NO_VLA__
	is non-zero.

	2019-04-30  Ben L  <bobsayshilol@@live.co.uk>

	* d-demangle.c (dlang_parse_assocarray): Correctly handle error result.
	* testsuite/d-demangle-expected: Add testcase.

	* d-demangle.c (dlang_parse_tuple): Correctly handle error result.
	* testsuite/d-demangle-expected: Add testcase.

	* d-demangle.c (dlang_parse_structlit): Correctly handle error result.
	* testsuite/d-demangle-expected: Add testcase.

	* d-demangle.c (dlang_parse_arrayliteral): Correctly handle error result.
	* testsuite/d-demangle-expected: Add testcase.

	* d-demangle.c (dlang_parse_integer): Fix stack underflow.
	* testsuite/d-demangle-expected: Add testcase.

	* cp-demangle (d_print_comp_inner): Guard against a NULL 'typed_name'.
	* testsuite/demangle-expected: Add testcase.

	* cp-demangle.c (d_encoding): Guard against NULL return values from
	d_right (dc).
	* testsuite/demangle-expected: Add testcase.

	2019-04-29  Ben L  <bobsayshilol@@live.co.uk>

	* cp-demangle.c (d_expression_1): Don't peek ahead unless the current
	char is valid.
	* testsuite/demangle-expected: Add testcase.

	2019-04-10  Nick Clifton  <nickc@@redhat.com>

	PR 89394
	* cp-demangle.c (cplus_demangle_fill_name): Reject negative
	lengths.
	(d_count_templates_scopes): Replace num_templates and num_scopes
	parameters with a struct d_print_info pointer parameter.  Adjust
	body of the function accordingly.  Add recursion counter and check
	that the recursion limit is not reached.
	(d_print_init): Pass dpi parameter to d_count_templates_scopes.
	Reset recursion counter afterwards, unless the recursion limit was
	reached.

2019-07-13  Joel Brobecker  <brobecker@@adacore.com>

	* src-release (getver): If $tool/gdbsupport/create-version.sh
	exists, use that to determine the version number.

2019-06-21  Andreas Schwab  <schwab@@linux-m68k.org>

	* src-release.sh (GDB_SUPPORT_DIRS): Add gnulib.

2019-06-14  Tom Tromey  <tom@@tromey.com>

	* MAINTAINERS: Add gnulib.
	* gnulib: New directory, move from gdb/gnulib.
	* configure.ac (host_libs): Add gnulib.
	* configure: Rebuild.
	* Makefile.def (host_modules, dependencies): Add gnulib.
	* Makefile.in: Rebuild.

2019-06-03  Nick Clifton  <nickc@@redhat.com>

	Revert:
	2019-05-29  Nick Clifton  <nickc@@redhat.com>

	* configure.ac (noconfigdirs): Add libctf if the target does not use
	the ELF file format.
	* configure: Regenerate.

2019-05-29  Nick Clifton  <nickc@@redhat.com>

	* src-release.sh (do_proto_toplev): Add libctf to list of
	directories that can be disabled.

2019-05-29  Nick Clifton  <nickc@@redhat.com>

	* configure.ac (noconfigdirs): Add libctf if the target does not use
	the ELF file format.
	* configure: Regenerate.

2019-05-28  Nick Alcock  <nick.alcock@@oracle.com>

	* Makefile.def (dependencies): configure-libctf depends on all-bfd
	and all its deps.
	* Makefile.in: Regenerated.

2019-05-28  Nick Alcock  <nick.alcock@@oracle.com>

	* MAINTAINERS: Add libctf.

2019-05-28  Nick Alcock  <nick.alcock@@oracle.com>

	* Makefile.def (host_modules): Add libctf.
	* Makefile.def (dependencies): Likewise.
	libctf depends on zlib, libiberty, and bfd.
	* Makefile.in: Regenerated.
	* configure.ac (host_libs): Add libctf.
	* configure: Regenerated.

2019-05-23  Jose E. Marchesi  <jose.marchesi@@oracle.com>

	* config.guess: Synchronize with config project master sources.
	* config.sub: Likewise.
	* readline/support/config.guess: Likewise.
	* readline/support/config.sub: Likewise.

2019-04-10  Nick Clifton  <nickc@@redhat.com>

	* libiberty: Sync with gcc.  Bring in:
	2019-04-10  Nick Clifton  <nickc@@redhat.com>

	PR 89394
	* cp-demangle.c (cplus_demangle_fill_name): Reject negative
	lengths.
	(d_count_templates_scopes): Replace num_templates and num_scopes
	parameters with a struct d_print_info pointer parameter.  Adjust
	body of the function accordingly.  Add recursion counter and check
	that the recursion limit is not reached.
	(d_print_init): Pass dpi parameter to d_count_templates_scopes.
	Reset recursion counter afterwards, unless the recursion limit was
	reached.

2018-06-24  Nick Clifton  <nickc@@redhat.com>

	2.32 branch created.

2019-01-14  Rainer Orth  <ro@@CeBiTec.Uni-Bielefeld.DE>

	Merge from GCC:
	PR target/88535
	* config.guess: Import upstream version 2019-01-03.
	* config.sub: Import upstream version 2019-01-01.

2019-01-10  Nick Clifton  <nickc@@redhat.com>

	* libiberty: Sync with gcc.  Bring in:
	2019-01-09  Sandra Loosemore  <sandra@@codesourcery.com>

	PR other/16615

	* cp-demangle.c: Mechanically replace "can not" with "cannot".
	* floatformat.c: Likewise.
	* strerror.c: Likewise.

	2018-12-22  Jason Merrill  <jason@@redhat.com>

	Remove support for demangling GCC 2.x era mangling schemes.
	* cplus-dem.c: Remove cplus_mangle_opname, cplus_demangle_opname,
	internal_cplus_demangle, and all subroutines.
	(libiberty_demanglers): Remove entries for ancient GNU (pre-3.0),
	Lucid, ARM, HP, and EDG demangling styles.
	(cplus_demangle): Remove 'work' variable.  Don't call
	internal_cplus_demangle.

2019-01-03  Дилян Палаузов  <dilyan.palauzov@@aegee.org>

	* configure.ac: Don't configure readline if --with-system-readline is
	used.
	* configure: Re-generate.

2018-10-31  Joseph Myers  <joseph@@codesourcery.com>

	Merge from GCC:
	PR bootstrap/82856
	* multilib.am: New file.  From automake.

2018-09-12  Sergio Durigan Junior  <sergiodj@@redhat.com>

	* src-release.sh (GDB_SUPPORT_DIRS): Add "contrib".

2018-07-16  Nick Clifton  <nickc@@redhat.com>

@@ -20,6 +338,18 @@@@
	* config.guess: Sync with upstream version 2018-06-26.
	* config.sub: Sync with upstream version 2018-07-02.

2018-06-29  Alexandre Oliva <oliva@@adacore.com>

	* configure.ac: Introduce support for @@unless/@@endunless.
	* Makefile.tpl (dep-kind): Rewrite with cond; return
	postbootstrap in some cases.
	(make-postboot-dep, postboot-targets): New.
	(dependencies): Do not output postbootstrap dependencies at
	first.  Output non-target ones changed for configure to depend
	on stage_last @@if gcc-bootstrap, and the original deps @@unless
	gcc-bootstrap.
	* configure.in, Makefile.in: Rebuilt.

2018-06-24  Nick Clifton  <nickc@@redhat.com>

	* configure: Regenerate.
@
text
@d3 1
a3 1
@@c Copyright (C) 1992-2020 Free Software Foundation, Inc.
d15 1
a15 1
Copyright @@copyright{} 1992-2020 Free Software Foundation, Inc.
d58 1
a58 1
Copyright @@copyright{} 1992-2020 Free Software Foundation, Inc.
d116 1
a116 1
The choice of script is made based on the command-line options.
d483 1
a483 1
the command-line arguments.  It calls @@code{ldemul_choose_target} to
@


1.1.1.3
log
@Update binutils from 2.34 to 2.39

2022-07-08  Nick Clifton  <nickc@@redhat.com>

	* 2.39 branch created.

2022-07-04  Nick Clifton  <nickc@@redhat.com>

	* libiberty: Synchronize with GCC.  Bring in:
	2022-07-01  Nick Clifton  <nickc@@redhat.com>

	PR demangler/105039
	* rust-demangle.c (demangle_const): Add recursion limit.

	2022-06-26  Simon Marchi  <simon.marchi@@efficios.com>

	* configure.ac: Add AC_CONFIG_MACRO_DIRS call.
	* configure: Re-generate.

2022-04-12  Nick Clifton  <nickc@@redhat.com>

	* zlib: Rebase to the 1.2.12 release.

2022-04-08  Simon Marchi  <simon.marchi@@efficios.com>

	* configure.ac: Add AC_SUBST(PKG_CONFIG_PATH).
	* configure: Re-generate.
	* Makefile.tpl (HOST_EXPORTS): Pass PKG_CONFIG_PATH.
	(PKG_CONFIG_PATH): New.
	* Makefile.in: Re-generate.

2022-03-15  Jose E. Marchesi  <jose.marchesi@@oracle.com>

	* gprofng/src/gp-collect-app.cc (collect::check_args): Use
	fallthrough comment instead of attribute.

2022-03-11  Vladimir Mezentsev  <vladimir.mezentsev@@oracle.com>

	* Makefile.def: Add gprofng module.
	* configure.ac: Add --enable-gprofng option.
	* src-release.sh: Add gprofng.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* gprofng: New directory.

2022-01-22  Nick Clifton  <nickc@@redhat.com>

	* 2.38 release branch created.

2022-01-17  Nick Clifton  <nickc@@redhat.com>

	Update config.[guess|sub] from upstream:

	2022-01-09  Idan Horowitz  <idan.horowitz@@gmail.com>

	config.guess: recognize SerenityOS
	* config.guess (*:SerenityOS:*:*): Recognize.
	(timestamp): Update.

	2022-01-03  Bernhard Voelker  <mail@@bernhard-voelker.de>

	Fix GPLv3 license headers to use a comma instead of semicolon
	See: https://www.gnu.org/licenses/gpl-3.0.html#howto

	Update license headers automatically using the following script:

	  $ git grep -l 'Foundation; either version 3' \
	    | xargs sed -i '/Foundation; either version 3/ s/n; e/n, e/'

	* config.guess: Adjust via the above command.
	(timestamp): Update.
	* config.sub: Likewise.
	* doc/config.guess.1: Regenerate.
	* doc/config.sub.1: Likewise.

	2022-01-01  Dmitry V. Levin  <ldv@@altlinux.org>

	Update copyright years
	* config.guess: Update copyright years.
	* config.sub: Likewise.

	2021-12-25  Dmitry V. Levin  <ldv@@altlinux.org>

	config.sub: alias armh to armv7l
	ALT uses armh as an alias for armv7l-alt-linux-gnueabihf since 2012.

	* config.sub (armh-unknown|armh-alt): Set cpu, vendor, and basic_os.
	(timestamp): Update.

	2021-12-24  Dmitry V. Levin  <ldv@@altlinux.org>

	config.sub: alias aarch64le to aarch64
	Apparently, QNX reports aarch64 as aarch64le on little-endian machines.

	* config.sub (aarch64le-*): Set cpu to aarch64.
	(timestamp): Update.

	2021-12-13  Dmitry V. Levin  <ldv@@altlinux.org>

	config.sub: fix typo in timestamp
	* config.sub: Fix timestamp.

	2021-11-30  Andreas F. Borchert  <github@@andreas-borchert.de>

	config.guess: x86_64-pc-solaris2.11 is not properly recognized
	config.guess guesses Solaris 11 to run on a 32-bit platform
	despite Solaris 11 no longer supporting any 32-bit platform.

	See the following code at lines 434 to 445:

	| SUN_ARCH=i386
	| # If there is a compiler, see if it is configured for 64-bit objects.
	| # Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
	| # This test works for both compilers.
	| if test "$CC_FOR_BUILD" != no_compiler_found; then
	|     if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
	|         (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \
	|         grep IS_64BIT_ARCH >/dev/null
	|     then
	|         SUN_ARCH=x86_64
	|     fi
	| fi

	If "cc" is installed, i.e. the Oracle Studio compiler, this one is
	chosen for $CC_FOR_BUILD.  This compiler, the gcc provided by Oracle
	and also gcc bootstrapped from sources on that platform with a default
	configuration will by default generate 32-bit binaries -- even on
	a 64-bit platform.  And __amd64 will not be defined for compilations
	targeting a 32-bit platform.  This is different from the corresponding
	behaviour on GNU/Linux systems where the local platform is targeted by
	default.

	Thus, as long as you do not add "-m64" or if you have a custom-built
	gcc which defaults to 64 bit, you will get 32-bit binaries on Solaris
	despite living on a 64-bit platform.

	* config.guess (i86pc:SunOS:5.*:* || i86xen:SunOS:5.*:*): Adapt the
	test by adding the "-m64" flag.  This will work properly for Solaris
	10 as well (the last Solaris release that supported x86 32-bit
	platforms).

	2021-10-27  Jordi Sanfeliu  <jordi@@fibranet.cat>

	Recognize Fiwix
	$ make check
	cd testsuite && bash config-guess.sh && rm uname
	PASS: config.guess checks (137 tests)
	cd testsuite && bash config-sub.sh
	PASS: config.sub checks (882 tests)
	PASS: config.sub idempotency checks (819 tests)
	PASS: config.sub canonicalise each config.guess testcase (137 tests)

	* config.guess (i*86:Fiwix:*:*): Recognize.
	* config.sub (fiwix*): Likewise.

	2021-10-18  Kinshuk Dua  <kinshukdua@@gmail.com>

	config.sub: Fix typo in comment
	Fixes: 5e531d391852a54e7fab2d8ff55625fca514b305

	2021-08-14  Nick Bowler  <nbowler@@draconx.ca>

	config.sub: work around command assignment bug in some shells
	When combining variable assignments with a shell command, some older
	shells (notably heirloom-sh and presumably also Solaris 10 /bin/sh)
	have a bug which causes the assignment to alter the current execution
	environment whenever the command is a shell built-in.  For example:

	  % dash -c 'x=good; x=bad echo >/dev/null; echo $x'
	  good

	  % jsh -c 'x=good; x=bad echo >/dev/null; echo $x'
	  bad

	The config.sub script contains a few commands of the form:

	  IFS=- read ...

	which triggers this bug, causing the IFS assignment to persist for the
	remainder of the script.  This can cause misbehaviour in certain cases,
	for example:

	  % jsh config.sub i386-linux-gnu
	  config.sub: test: unknown operator gnu

	  % jsh config.sub i386-gnu/linux
	  sed: can't read s|gnu/linux|gnu|: No such file or directory
	  Invalid configuration `i386-gnu/linux': OS `' not recognized

	* config.sub: Save and restore IFS explicitly to avoid shell bugs.
	* doc/config.sub.1: Regenerate.

	2021-08-04  Jeremy Soller  <jackpot51@@gmail.com>

	config.sub: add Linux Relibc Target
	$ make check
	cd testsuite && bash config-guess.sh && rm uname
	PASS: config.guess checks (136 tests)
	cd testsuite && bash config-sub.sh
	PASS: config.sub checks (881 tests)
	PASS: config.sub idempotency checks (818 tests)
	PASS: config.sub canonicalise each config.guess testcase (136 tests)

	* config.sub (relibc*): Recognize.
	* doc/config.sub.1: Regenerate.
	* testsuite/config-sub.data (x86_64-linux-relibc): New test.

	2021-07-06  Stephanos Ioannidis  <root@@stephanos.io>

	config.sub: add Zephyr RTOS support
	This adds the Zephyr RTOS targets in preparation for implementing the
	Zephyr RTOS-specific toolchain support.

	$ make check
	cd testsuite && bash config-guess.sh && rm uname
	PASS: config.guess checks (136 tests)
	cd testsuite && bash config-sub.sh
	PASS: config.sub checks (880 tests)
	PASS: config.sub idempotency checks (817 tests)
	PASS: config.sub canonicalise each config.guess testcase (136 tests)

	* config.sub (zephyr*): Recognize.
	* doc/config.sub.1: Regenerate.
	* testsuite/config-sub.data: Add testcases for *-zephyr.

	2021-07-03  Ozkan Sezer  <sezero@@users.sourceforge.net>

	config.sub: disable shellcheck SC2006 / SC2268 warnings
	This is in line with the recent config.guess change in commit
	12fcf67c9108f4c4b581eaa302088782f0ee40ea

	* config.sub (shellcheck disable): Add SC2006,SC2268.

	Suggested-by: Jacob Bachmeyer <jcb@@gnu.org>

	2021-07-03  Ozkan Sezer  <sezero@@users.sourceforge.net>

	config.sub: normalize the quoting in the `echo FOO | sed ...`
	Some cases quote the argument to echo and some do not.  At runtime
	it probably does not matter because the substituted values will never
	contain whitespace, but quoting them all would make shellcheck more
	useful.

	* config.sub: Consistently quote the argument of echo.
	* doc/config.sub.1: Regenerate.

	Suggested-by: Jacob Bachmeyer <jcb@@gnu.org>

	2021-07-02  Ozkan Sezer  <sezero@@users.sourceforge.net>

	config.sub: replace POSIX $( ) with classic ` ` throughout
	This is in line with the recent config.guess change in commit
	d70c4fa934de164178054c3a60aaa0024ed07c91.

	The patch was generated using patch-6.gawk script introduced in that
	commit.

	* config.sub: Revert POSIX command substitutions to classic form.

	2021-06-04  Vineet Gupta  <Vineet.Gupta1@@synopsys.com>

	Recognize arc32
	This is the 32-bit variant of ARCv3 ISA (which is not compatible with the
	32-bit ARCv2 ISA)

	| make check
	| cd testsuite && bash config-guess.sh && rm uname
	| PASS: config.guess checks (136 tests)
	| cd testsuite && bash config-sub.sh
	| PASS: config.sub checks (864 tests)
	| PASS: config.sub idempotency checks (801 tests)
	| PASS: config.sub canonicalise each config.guess testcase (136 tests)

	* config.guess (arc32:Linux:*:*): Recognize.
	* config.sub (arc32): Likewise.

	2021-05-27  Jacob Bachmeyer  <jcb@@gnu.org>

	Remove automatic patch generators
	These tools have served their purposes and need not be kept outside of
	the repository history any longer.  This patch as a diff also collects
	the contents of the various tools in one convenient place.

	* patch-1.gawk: Remove.
	* patch-3.gawk: Likewise.
	* patch-6.gawk: Likewise.

	2021-05-26  Jacob Bachmeyer  <jcb@@gnu.org>

	config.guess: manual fixups after previous automatic patch
	The tool could not handle command substitutions that span lines, but
	fortunately there were only two such substitutions in the script.

	The test for which universe is active on Pyramid is rewritten into a
	case block because it was the only use of a command substitution as an
	argument to the test command, which would require quoting.

	* config.guess: Rewrite "if" for Pyramid systems to "case".

	2021-05-26  Jacob Bachmeyer  <jcb@@gnu.org>

	config.guess: replace POSIX $( ) with classic ` ` throughout
	The previous replacement of backticks with POSIX command substitutions
	was ill-considered and illogical: this script recognizes many archaic
	machine types that probably never had POSIX shells, therefore it needs
	to be able to run successfully under pre-POSIX shells.

	This patch was generated using the included GNU Awk program.

	* config.guess: Revert POSIX command substitutions to classic form.
	* patch-6.gawk: Store the tool that produced the automated patch.

	2021-05-26  Jacob Bachmeyer  <jcb@@gnu.org>

	config.guess: manual fixup after previous automated patches
	This patch provides the special handling for the GNU system.  As these
	were two small and unique edits, they were not included in the scripts.

	This patch also cleans up other minor issues that must be addressed
	before reverting to classic command substitutions and updates
	"shellcheck" directives to account for changes in this script and the
	change in "shellcheck" towards reporting individual portability issues.

	2021-05-26  Jacob Bachmeyer  <jcb@@gnu.org>

	config.guess: automatic fixups after previous automated patch
	This patch was generated using the following command:

	  sed -i config.guess \
	      -e '/="[^"]\+"\(-\|$\)/s/="\([^"([:space:])]\+\)"/=\1/' \
	      -e '/="[^"]\+"[[:alnum:]]/s/="\$\([^([:space:])]\+\)"/=${\1}/' \
	      -e \
	'/\$(echo[^|]\+|/s/\([^[:space:]]\)[[:space:]]*|[[:space:]]*sed/\1 | sed/g'

	* config.guess: Remove unneeded quotes in other variable assignments,
	standardize spacing for "echo ... | sed" substitutions.

	2021-05-26  Jacob Bachmeyer  <jcb@@gnu.org>

	config.guess: remove unneeded quotes and factor command substitutions
	This is further cleanup and simplifies some constructs that can confuse
	Emacs' syntax highlighting while generally reducing required quoting.

	This patch was generated using the included GNU Awk program.

	* config.guess: Remove unneeded variable quotes and factor out command
	substitutions when setting GUESS.
	* patch-3.gawk: Store the tool that produced the automated patch.

	2021-05-25  Jacob Bachmeyer  <jcb@@gnu.org>

	config.guess: manual fixups after previous automatic patch
	* config.guess: Adjust a few "leftover" cases that the tool could not
	easily recognize and fixes comment indentation in a few other special
	cases.

	2021-05-25  Jacob Bachmeyer  <jcb@@gnu.org>

	config.guess: use intermediate variable with uname results
	This will allow quoting to be significantly simplified in another
	pass through the file.

	This patch was generated using the included GNU Awk program.

	* config.guess: Use GUESS variable to hold results of uname analysis.
	* patch-1.gawk: Store the tool that produced the automated patch.

	2021-05-25  Jacob Bachmeyer  <jcb@@gnu.org>

	config.guess: introduce intermediate variable with uname results
	This will allow quoting to be significantly simplified in another
	pass through the file.

	* config.guess: Introduce GUESS variable to hold results of uname analysis.

	2021-05-24  Dmitry V. Levin  <ldv@@altlinux.org>

	config.guess: fix shellcheck warning SC2154
	While, according to Plan 9 documentation, the environment variable
	$cputype is set to the name of the kernel's CPU's architecture,
	shellcheck warns that cputype is referenced but not assigned.
	Be on the safe side and do not use cputype if it is not defined
	or empty.

	* config.guess (*:Plan9:*:*): Fix shellcheck warning SC2154.

	2021-05-24  Dmitry V. Levin  <ldv@@altlinux.org>

	config.guess: remove redundant quotes in case commands
	According to the GNU Autoconf Portable Shell Programming manual,
	the Bourne shell does not systematically split variables and back-quoted
	expressions, in particular on the right-hand side of assignments and in
	the argument of 'case'.

	The change is made automatically using the following command:
	$ sed -E -i 's/(\<case )"(\$[^"]+)"( in\>)/\1\2\3/' config.guess

	* config.guess: Simplify case commands by removing quotes around the
	argument.

	Suggested-by: Jacob Bachmeyer <jcb@@gnu.org>

	2021-05-24  Dmitry V. Levin  <ldv@@altlinux.org>

	config.guess: simplify exit status workaround on alphaev67-dec-osf5.1
	Commit 29865ea8a5622cdd80b7a69a0afa78004b4cd311 introduced an exit trap
	reset before exiting to avoid a spurious non-zero exit status on
	alphaev67-dec-osf5.1.  Simplify that code a bit by moving the exit trap
	reset around.

	* config.guess (alpha:OSF1:*:*): Reset exit trap earlier.
	* doc/config.guess.1: Regenerate.

2021-10-29  Eli Zaretskii  <eliz@@gnu.org>

	* gdb/doc/gdb.texinfo (Command Options): (Data): Document
	'-memory-tag-violations'.  Update the example.

2021-09-28  Andrew Burgess  <andrew.burgess@@embecosm.com>

	* src-release.sh (GDB_SUPPPORT_DIRS): Add libbacktrace.

2021-09-27  Nick Alcock  <nick.alcock@@oracle.com>

	PR libctf/27967
	* libtool.m4 (LT_PATH_NM): Try BSDization flags with a user-provided
	NM, if there is one.  Run nm on itself, not on /dev/null, to avoid
	errors from nms that refuse to work on non-regular files.  Remove
	other workarounds for this problem.  Strip out blank lines from the
	nm output.

2021-09-27  Nick Alcock  <nick.alcock@@oracle.com>

	PR libctf/27967
	* libtool.m4 (lt_cv_sys_global_symbol_pipe): Augment symcode for
	Solaris 11.

2021-07-03  Nick Clifton  <nickc@@redhat.com>

	* 2.37 release branch created.

2021-07-03  Nick Clifton  <nickc@@redhat.com>

	* libiberty: Sync with gcc.  Bring in:
	2021-06-30  Gerald Pfeifer  <gerald@@pfeifer.com>

	* make-temp-file.c (usrtmp): Remove.
	(choose_tmpdir): Remove use of usrtmp.

	2021-06-28  Indu Bhagat  <indu.bhagat@@oracle.com>

	* simple-object.c (handle_lto_debug_sections): Copy over .BTF section.

	2021-06-28  Indu Bhagat  <indu.bhagat@@oracle.com>
	    David Faust  <david.faust@@oracle.com>
	    Jose E. Marchesi  <jose.marchesi@@oracle.com>
	    Weimin Pan  <weimin.pan@@oracle.com>

	* simple-object.c (handle_lto_debug_sections): Copy over .ctf
	sections.

	2021-06-05  John David Anglin  <danglin@@gcc.gnu.org>

	PR target/100734
	* configure.ac: Use libiberty snprintf and vsnprintf on
	hppa*-*-hpux*.
	* configure: Regenerate.

	2021-05-06  Tom Tromey  <tom@@tromey.com>

	* hashtab.c (htab_eq_string): New function.

	2021-05-04  Eric Botcazou  <ebotcazou@@adacore.com>

	* configure.ac: Make test for variables more robust.
	* configure: Regenerate.

	2021-05-03  H.J. Lu  <hjl.tools@@gmail.com>

	PR bootstrap/99703
	* configure: Regenerated.

	2021-04-21  Andreas Schwab  <schwab@@linux-m68k.org>

	PR demangler/100177
	* rust-demangle.c (demangle_const_char): Properly print the
	character value.

	2021-03-31  Patrick Palka  <ppalka@@redhat.com>

	PR c++/88115
	* cp-demangle.c (d_dump, d_make_comp, d_expression_1)
	(d_count_templates_scopes): Handle DEMANGLE_COMPONENT_VENDOR_EXPR.
	(d_print_comp_inner): Likewise.
	<case DEMANGLE_COMPONENT_EXTENDED_OPERATOR>: Revert r11-4926
	change.
	<case DEMANGLE_COMPONENT_UNARY>: Likewise.
	* testsuite/demangle-expected: Adjust __alignof__ tests.

	2021-03-16  Nick Clifton  <nickc@@redhat.com>

	* sha1.c (sha1_process_bytes): Use memmove in place of memcpy.

	2021-02-20  Mike Frysinger  <vapier@@gentoo.org>

	* Makefile.in (ACLOCAL, ACLOCAL_AMFLAGS, $(srcdir)/aclocal.m4): Define.
	(configure_deps): Rename to ...
	(aclocal_deps): ... this.  Replace aclocal.m4 with acinclude.m4.
	($(srcdir)/configure): Replace $(configure_deps) with
	$(srcdir)/aclocal.m4.
	* aclocal.m4: Move libiberty macros to acinclude.m4, then regenerate.
	* acinclude.m4: New file.
	* configure: Regenerate.

	2021-02-19  Ayush Mittal  <ayush.m@@samsung.com>

	* argv.c (expandargv): free allocated buffer if read fails.

	2021-02-01  Martin Sebor  <msebor@@redhat.com>

	* dyn-string.c (dyn_string_insert_cstr): Use memcpy instead of strncpy
	to avoid -Wstringop-truncation.

2021-05-29  Mike Frysinger  <vapier@@gentoo.org>

	* configure.ac: Add gnulib to configdirs for sim.
	* configure: Regenerate.

2021-05-24  Maciej W. Rozycki  <macro@@orcam.me.uk>

	* MAINTAINERS: Update path to readline config.{sub,guess} files.

2021-05-24  Maciej W. Rozycki  <macro@@orcam.me.uk>

	* config.guess: Import from upstream.
	* config.sub: Likewise.

2021-05-18  Mike Frysinger  <vapier@@gentoo.org>

	* Makefile.def: Add configure-sim dependency on all-gnulib.
	* Makefile.in: Regenerated.

2021-05-04  Nick Clifton  <nickc@@redhat.com>

	* configure.ac (AC_PROG_CC): Replace with AC_PROG_CC_C99.
	* configure: Regenerate.

2021-03-18  Nick Alcock  <nick.alcock@@oracle.com>

	PR libctf/27482
	* Makefile.def: Add install-bfd dependencies for install-libctf and
	install-ld, and install-strip-bfd dependencies for
	install-strip-libctf and install-strip-ld; move the install-ld
	dependency on install-libctf to join it.
	* Makefile.in: Regenerated.

2021-03-12  Mike Frysinger  <vapier@@gentoo.org>

	* Makefile.def: Remove all-sim dependency on configure-gdb.
	* Makefile.in: Regenerated.

2021-02-28  H.J. Lu  <hongjiu.lu@@intel.com>

	PR binutils/26766
	* Makefile.tpl (PGO_BUILD_TRAINING_FLAGS_TO_PASS): Add
	PGO_BUILD_TRAINING=yes.
	(PGO_BUILD_TRAINING_MFLAGS): New.
	(all): Pass $(PGO_BUILD_TRAINING_MFLAGS) to the PGO build.

2021-02-09  Alan Modra  <amodra@@gmail.com>

	* configure.ac: Delete arm*-*-symbianelf* entry.
	* configure: Regenerate.

2021-01-26  Nick Alcock  <nick.alcock@@oracle.com>

	* Makefile.def: Add install-libctf dependency to install-ld.
	* Makefile.in: Regenerated.

2021-01-12  Mike Frysinger  <vapier@@gentoo.org>

	* src-release.sh (do_proto_toplev): Rewrite indentation.

2021-01-11  H.J. Lu  <hongjiu.lu@@intel.com>

	PR binutils/26766
	* configure.ac:
	* configure: Regenerated.

2021-01-11  H.J. Lu  <hongjiu.lu@@intel.com>

	PR ld/27173
	* configure: Regenerated.
	* libtool.m4 (_LT_CMD_OLD_ARCHIVE): Check if AR works with
	--plugin and rc before enabling --plugin.

2021-01-09  H.J. Lu  <hongjiu.lu@@intel.com>

	PR binutils/26766
	* Makefile.tpl (BUILD_CFLAGS): New.
	(CFLAGS): Append $(BUILD_CFLAGS).
	(CXXFLAGS): Likewise.
	(PGO_BUILD_GEN_FLAGS_TO_PASS): New.
	(PGO_BUILD_TRAINING_CFLAGS): Likewise.
	(PGO_BUILD_TRAINING_CXXFLAGS): Likewise.
	(PGO_BUILD_TRAINING_FLAGS_TO_PASS): Likewise.
	(PGO_BUILD_TRAINING_MFLAGS): Likewise.
	(PGO_BUILD_USE_FLAGS_TO_PASS): Likewise.
	(PGO-TRAINING-TARGETS): Likewise.
	(PGO_BUILD_TRAINING): Likewise.
	(all): Add '+' to the command line for recursive make.  Support
	the PGO build.
	* configure.ac: Add --enable-pgo-build[=lto].
	AC_SUBST PGO_BUILD_GEN_CFLAGS, PGO_BUILD_USE_CFLAGS and
	PGO_BUILD_LTO_CFLAGS.  Enable the PGO build in Makefile.
	* Makefile.in: Regenerated.
	* configure: Likewise.

2021-01-09  H.J. Lu  <hongjiu.lu@@intel.com>

	* Makefile.tpl (AR): Add @@AR_PLUGIN_OPTION@@
	(RANLIB): Add @@RANLIB_PLUGIN_OPTION@@.
	* configure.ac: Include config/gcc-plugin.m4.
	AC_SUBST AR_PLUGIN_OPTION and RANLIB_PLUGIN_OPTION.
	* libtool.m4 (_LT_CMD_OLD_ARCHIVE): Pass --plugin to AR and
	RANLIB if possible.
	* Makefile.in: Regenerated.
	* configure: Likewise.

2021-01-09  Nick Clifton  <nickc@@redhat.com>

	* 2.36 release branch crated.

2021-01-07  Samuel Thibault  <samuel.thibault@@gnu.org>

	* libtool.m4: Match gnu* along with other GNU systems.

2021-01-07  Alan Modra  <amodra@@gmail.com>

	* config.sub: Accept OS of eabi* and gnueabi*.

2021-01-05  Nick Alcock  <nick.alcock@@oracle.com>

	* Makefile.def (libctf): No longer no_check.  Checking depends on
	all-ld.
	* Makefile.in: Regenerated.

2021-01-05  Nick Clifton  <nickc@@redhat.com>

	* libiberty: Sync with gcc.  Bring in:
	2021-01-04  Martin Liska  <mliska@@suse.cz>

	* strverscmp.c: Convert to utf8 from iso8859.

	2020-12-22  Jason Merrill  <jason@@redhat.com>

	PR c++/67343
	* cp-demangle.h (struct d_info): Add unresolved_name_state.
	* cp-demangle.c (d_prefix): Add subst parm.
	(d_nested_name): Pass it.
	(d_unresolved_name): Split out from...
	(d_expression_1): ...here.
	(d_demangle_callback): Maybe retry with old sr mangling.
	* testsuite/demangle-expected: Add test.

	2020-12-21  Jason Merrill  <jason@@redhat.com>

	* cp-demangle.c (d_expression_1): Recognize qualified-id
	on RHS of dt/pt.
	* testsuite/demangle-expected: Add test.

	2020-12-21  Jason Merrill  <jason@@redhat.com>

	* cp-demangle.c (d_unqualified_name): Clear is_expression.
	* testsuite/demangle-expected: Add tests.

	2020-11-25  Matthew Malcomson  <matthew.malcomson@@arm.com>

	* configure: Regenerate.
	* configure.ac: Avoid using sanitizer.

	2020-11-13  Eduard-Mihai Burtescu  <eddyb@@lyken.rs>

	* rust-demangle.c (struct rust_demangler): Add
	skipping_printing and bound_lifetime_depth fields.
	(eat): Add (v0-only).
	(parse_integer_62): Add (v0-only).
	(parse_opt_integer_62): Add (v0-only).
	(parse_disambiguator): Add (v0-only).
	(struct rust_mangled_ident): Add punycode{,_len} fields.
	(parse_ident): Support v0 identifiers.
	(print_str): Respect skipping_printing.
	(print_uint64): Add (v0-only).
	(print_uint64_hex): Add (v0-only).
	(print_ident): Respect skipping_printing,
	Support v0 identifiers.
	(print_lifetime_from_index): Add (v0-only).
	(demangle_binder): Add (v0-only).
	(demangle_path): Add (v0-only).
	(demangle_generic_arg): Add (v0-only).
	(demangle_type): Add (v0-only).
	(demangle_path_maybe_open_generics): Add (v0-only).
	(demangle_dyn_trait): Add (v0-only).
	(demangle_const): Add (v0-only).
	(demangle_const_uint): Add (v0-only).
	(basic_type): Add (v0-only).
	(rust_demangle_callback): Support v0 symbols.
	* testsuite/rust-demangle-expected: Add v0 testcases.

	2020-11-13  Seija Kijin  <doremylover456@@gmail.com>

	* strstr.c (strstr): Make implementation ANSI/POSIX compliant.

	2020-11-11  Patrick Palka  <ppalka@@redhat.com>

	PR c++/88115
	* cp-demangle.c (d_print_comp_inner)
	<case DEMANGLE_COMPONENT_EXTENDED_OPERATOR>: Don't print the
	"operator " prefix for __alignof__.
	<case DEMANGLE_COMPONENT_UNARY>: Always print parens around the
	operand of __alignof__.
	* testsuite/demangle-expected: Test demangling for __alignof__.

	2020-11-09  Christophe Lyon  <christophe.lyon@@linaro.org>

	* pex-win32.c (pex_win32_exec_child): Initialize orig_err.

	2020-10-06  Martin Liska  <mliska@@suse.cz>

	PR lto/97290
	* simple-object-elf.c (simple_object_elf_copy_lto_debug_sections):
	Use sh_link of a .symtab_shndx section.

2021-01-05  Alan Modra  <amodra@@gmail.com>

	* config.guess: Import from upstream.
	* config.sub: Likewise.

2020-12-16  Martin Liska  <mliska@@suse.cz>
	    Tom de Vries  <tdevries@@suse.de>

	* gdb/debuginfod-support.c (struct user_data): Remove has_printed
	field.  Add meter field.
	(progressfn): Print progress using meter.

2020-12-02  Enze Li  <lienze2010@@hotmail.com>

	* .gitignore: Add gnu global outputs.

2020-12-02  Simon Marchi  <simon.marchi@@polymtl.ca>

	* .gitignore: Sync with gcc.

2020-10-26  Andreas Rammhold <andreas@@rammhold.de>

	* src-release.sh: Use sha256sum instead of md5sum.

2020-10-14  Andrew Burgess  <andrew.burgess@@embecosm.com>

	* Makefile.in: Rebuild.
	* Makefile.def: Make distclean-gnulib depend on distclean-gdb and
	distclean-gdbserver.

2020-07-24  Aaron Merey  <amerey@@redhat.com>

	* configure: Rebuild.
	* configure.ac: Remove AC_DEBUGINFOD.

2020-07-04  Nick Clifton  <nickc@@redhat.com>

	Binutils 2.35 branch created.

2020-04-21  Stephen Casner  <casner@@acm.org>

	PR 25830
	* configure.ac (noconfigdirs): Exclude gdb & gprof for pdp11.
	* configure: Rebuild.

2020-03-12  Tom Tromey  <tom@@tromey.com>

	* Makefile.in: Rebuild.
	* Makefile.def (gdbserver): Depend on gdbsupport.

2020-03-12  Tom Tromey  <tom@@tromey.com>

	* Makefile.in: Rebuild.
	* Makefile.def (gdbsupport): Don't depend on bfd.

2020-03-12  Tom Tromey  <tom@@tromey.com>

	* Makefile.in: Rebuild.
	* Makefile.def (gdbsupport): Depend on intl.

2020-02-17  Tom Tromey  <tom@@tromey.com>

	* configure: Rebuild.
	* configure.ac (configdirs): Add gnulib and gdbsupport when building
	gdbserver.

2020-02-14  Tom Tromey  <tom@@tromey.com>

	* Makefile.in: Rebuild.
	* Makefile.def: Make gdbserver require gnulib and libiberty.

2020-02-07  Tom Tromey  <tom@@tromey.com>
	    Pedro Alves  <palves@@redhat.com>

	* src-release.sh (GDB_SUPPORT_DIRS): Add gdbserver.
	* gdbserver: New directory, moved from gdb/gdbserver.
	* configure.ac (host_tools): Add gdbserver.
	Only build gdbserver on certain systems.
	* Makefile.in, configure: Rebuild.
	* Makefile.def (host_modules, dependencies): Add gdbserver.
	* MAINTAINERS: Add gdbserver.

2020-01-28  Sergio Durigan Junior  <sergiodj@@redhat.com>

	* src-release.sh (getver): Look for gdbsupport's
	create-version.sh script at the current directory if tool is
	"gdb".

2020-01-19  Simon Marchi  <simon.marchi@@polymtl.ca>

	* remote-sim.c (gdbsim_target::wait): Return
	sim_data->remote_sim_ptid instead of inferior_ptid.
@
text
@d3 1
a3 1
@@c Copyright (C) 1992-2022 Free Software Foundation, Inc.
d15 1
a15 1
Copyright @@copyright{} 1992-2022 Free Software Foundation, Inc.
d58 1
a58 1
Copyright @@copyright{} 1992-2022 Free Software Foundation, Inc.
@


1.1.1.3.2.1
log
@Sync with HEAD.
@
text
@d3 1
a3 1
@@c Copyright (C) 1992-2024 Free Software Foundation, Inc.
d15 1
a15 1
Copyright @@copyright{} 1992-2024 Free Software Foundation, Inc.
d58 1
a58 1
Copyright @@copyright{} 1992-2024 Free Software Foundation, Inc.
@


1.1.1.4
log
@Import binutils-2.42 (last was 2.39)

2024-01-15  Nick Clifton  <nickc@@redhat.com>

	* 2.42 branch point.

2023-11-15  Arsen Arsenović  <arsen@@aarsen.me>

	* intl: Remove directory.  Replaced with out-of-tree GNU
	gettext.
	* .gitignore: Add '/gettext*'.
	* configure.ac (host_libs): Replace intl with gettext.
	(hbaseargs, bbaseargs, baseargs): Split baseargs into
	{h,b}baseargs.
	(skip_barg): New flag.  Skips appending current flag to
	bbaseargs.
	<library exemptions>: Exempt --with-libintl-{type,prefix} from
	target and build machine argument passing.
	* configure: Regenerate.
	* Makefile.def (host_modules): Replace intl module with gettext
	module.
	(configure-ld): Depend on configure-gettext.
	* Makefile.in: Regenerate.
	* src-release.sh: Remove references to the intl/ directory.

2023-07-03  Nick Clifton  <nickc@@redhat.com>

	2.41 Branch Point.

2023-06-26  Nick Clifton  <nickc@@redhat.com>

	* Import these updates to the config scripts

	commit 4ad4bb7c30aca1e705448ba8d51a210bbd47bb52
	Author: Paul Eggert <eggert@@cs.ucla.edu>
	Date:   Fri Jun 23 09:55:10 2023 -0700

		Quote 'like this', not `like this'.

	commit 63acb96f92473ceb5e21d873d7c0aee266b3d6d3
	Author: Paul Eggert <eggert@@cs.ucla.edu>
	Date:   Sat Jan 21 00:15:01 2023 -0600

		Fix config.sub spelling typo for "athlon"

	commit 4ce12a5c9125cedc0d0ba584444a6865396923ec
	Author: Dmitry V. Levin <ldv@@altlinux.org>
	Date:   Sun Jan 1 08:00:00 2023 +0000

		Update copyright years

	commit c397e2c040bce50bcdccb131f90115ba7e8bfc19
	Author: Arsen Arsenovi <arsen@@aarsen.me>
	Date:   Sat Sep 17 23:34:48 2022 +0200

		config.sub: add linux-mlibc targets

	commit 9f9f9b0b13197269848c76e3e057a3ed0680b4bf
	Author: Arsen Arsenovi <arsen@@aarsen.me>
	Date:   Sat Sep 17 23:34:47 2022 +0200

		config.guess: support running on Managarm systems

	commit 87e6687749da7bb2ab158a79fa83721c19ed9246
	Author: Arsen Arsenovi <arsen@@aarsen.me>
	Date:   Sat Sep 17 23:34:46 2022 +0200

		config.sub: add managarm-{mlibc,kernel} targets

	commit 20403c5701973a4cbd7e0b4bbeb627fcd424a0f1
	Author: Xiaotian Wu <wuxiaotian@@loongson.cn>
	Date:   Mon Aug 1 16:05:29 2022 +0800

		Remove loongarchx32

	commit 02ba26b218d3d3db6c56e014655faf463cefa983
	Author: Alexander von Gluck IV <kallisti5@@unixzen.com>
	Date:   Wed May 25 15:43:13 2022 -0500

		config.guess: Update Haiku guesses

	commit f56a7140386d08a531bcfd444d632b28c61a6329
	Author: Bruno Haible <bruno@@clisp.org>
	Date:   Sun May 8 19:08:08 2022 +0200

		config.guess (x86_64:Linux:*:*): Detect 32-bit ABI.

2023-04-20  Nick Clifton  <nickc@@redhat.com>

	* SECURITY.txt: New file.
	* src-release.sh (DEVO_SUPPORT): Add SECURITY.txt.

2022-12-31  Nick Clifton  <nickc@@redhat.com>

	* 2.40 binutils branch created.

2022-10-10  Nick Clifton  <nickc@@redhat.com>

	* src-release.sh: Add "-r <date>" option to create reproducible
	tarballs based upon a fixed timestamp of <date>.
	* binutils/README-how-to-make-a-release: Add a line showing how to
	use -r <date> when creating a binutils release.

2022-10-04  Nick Clifton  <nickc@@redhat.com>

	* README-maintainer-mode: Add a minimum version of dejagnu
	requirement.

2022-09-08  Nick Clifton  <nickc@@redhat.com>

	* README-maintainer-mode: Update minimum version  of gettext
	required.
@
text
@d3 1
a3 1
@@c Copyright (C) 1992-2024 Free Software Foundation, Inc.
d15 1
a15 1
Copyright @@copyright{} 1992-2024 Free Software Foundation, Inc.
d58 1
a58 1
Copyright @@copyright{} 1992-2024 Free Software Foundation, Inc.
@


1.1.1.5
log
@Import binutils 2.45 (previous was 2.42)

2.45 Release Notes
------------------

Assembler:

  All sframe information generated by the assembler is now in compliance
  with the SFrame V2 specification.

  The assembler now supports .errif and .warnif directives, permitting
  user-controlled diagnostics with conditionals that are evaluated only
  at the end of assembly.

  The assembler predefines the symbol "GAS(version)".

  The assembler now supports the generation of SFrame stack trace
  information (.sframe) from CFI directives on s390 64-bit (s390x).

  For RISC-V, the ".option arch, -ext" format is deprecated due to its
  controversial use.

  For RISC-V, stop generating mapping symbols $x and replace with $x<isa>.  The
  $x was defined to have the same ISA as previous $x<isa>, but now is defined
  to have the same ISA as elf architecture attribute.  Once both used .option
  arch/rvc/norvc/push/pop directives (some code have different architectures
  with file attribute) and data directives in text, then the file need to be
  rebuilt since 2.45.

  The assembler supports the latest architecture extensions for the
  RISC-V, LoongArch and AArch64 architectures.

Linker:

  The linker's --stats option can take an optional argument which if used is
  interpreted as a filename into which resource usage information should be
  stored.  As an alternative mechanism the LD_STATS environment variable can
  also be used to achieve the same results.  Resource usage information for
  various phases of the linking operation is now included in the report.
  If a map file is being produced then the information is also included there.
  The --no-stats option can be used to disable stat reporting, should it have
  been enabled.

  On s390 64-bit (s390x), generate SFrame stack trace information (.sframe)
  for the linker generated .plt section.  On s390 32-bit, generate
  ".eh_frame" unwind information for the linker generated .plt section.
  Both features are enabled by default and can be disabled using linker
  option --no-ld-generated-unwind-info.

  On RISC-V, add new PLT formats, and GNU property merge rules for zicfiss and
  zicfilp extensions.

  On AVR, the default linker scripts now assert that the .progmem sections
  don't extend past 0xffff since they are accessed by means of LPM.
  For data in program memory that may be located past 0xffff, a .progmemx
  section should be used.

  On LoongArch, linker relaxation time complexity is no longer quadratic with
  respect to relocation counts.  Linking time of large software should be
  improved.  In addition  R_LARCH_32_PCREL records are now checked for
  overflow.

Other binary utilities:

  New versioned release of libsframe: libsframe.so.2.  This release introduces
  versioned symbols with version node name LIBSFRAME_2.0.  Some new symbols
  have been added to support the new flag SFRAME_F_FDE_FUNC_START_PCREL and
  retrieving flags from SFrame decoder and encoder objects:
    - Addition of sframe_decoder_get_flags,
      sframe_decoder_get_offsetof_fde_start_addr, sframe_encoder_get_flags,
      sframe_encoder_get_offsetof_fde_start_addr.
  This release also includes backward-incompatible ABI changes:
    - Removal of sframe_get_funcdesc_with_addr.
    - Change in the behavior of sframe_decoder_get_funcdesc_v2,
      sframe_encoder_add_funcdesc_v2 and sframe_encoder_write.

  For SFrame stack trace format, the function start address in each SFrame
  FDE has a changed encoding:  The 32-bit signed integer now holds the offset
  of the start PC of the associated function from the sfde_func_start_address
  field itself (instead of the earlier where it was the offset from the start
  of the SFrame section itself).  All SFrame sections generated by gas and ld
  now default to this new encoding, setting the (new)
  SFRAME_F_FDE_FUNC_START_PCREL flag.

  Relocatable SFrame links are now fixed.

 Readelf now recognizes RISC-V GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS and
  GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED for zicfiss and zicfilp
  extensions.

  The LoongArch disassembler now properly accepts multiple disassembly
  options given by -M, such as "-M no-aliases,numeric".  (Previously only the
  first option took effect.)


2.44 Release Notes
------------------

   Assembler:
      Support for new architecture extensions for AArch64, Risc-V and
      x86.

    Linker:
      The default maximum page size was changed from 16KiB to 64KiB for
      LoongArch.

      This now supports mixed LTO and non-LTO object files in
      relocatable output.

      The ELF forms of the linker support a --image-base=<ADDR> option
      for compatibility with LLD.

      The --build-id= option now accepts an argument of "xx" which
      enables the use of the xxhash library.  This produces a 128-bit
      hash and is 2-4x faster than md5 or sha1.

      The ELF linker option --package-metadata supports percent-encoded
      and %[string] encoded JSON payloads.

    Disassembler:
      The RISC-V disassembler now supports -M,max option like QEMU to
      dump instruction without checking architecture support as usual.

    GprofNG:
      Support added for hardware event counters for Neoverse-N1,
      Ampere-1, and Appliedmicro processors.

    Support for the Nios II target has been removed.

2.43 Release Notes
------------------

    Assembler:

* Add a .base64 directive to the assembler which allows base64 encoded
  binary data to be provided as strings.

* Assembler macros as well as the bodies of .irp / .irpc / .rept can now use
  the syntax \+ to access the number of times a given macro has been executed.
  This is similar to the already existing \@@ syntax, except that the count is
  maintained on a per-macro basis.

* References to FB and dollar labels, when supported, are no longer permitted
  in a radix other than 10.  (Note that definitions of such labels were
  already thus restricted, except that leading zeroes were permitted).

    Linker:

* Add support for DT_RELR type compressed runtime relocations for the
  AArch64 and LoongArch architectures.

* Add --rosegment option which changes the -z separate-code option so that
  only one read-only segment is created (instead of two).

* Add --section-ordering-file <FILE> option to add extra mapping of input
  sections to output sections.

* Add -plugin-save-temps to store plugin intermediate files permanently.

    Utilities:

* Readelf will now display DT_RELR relocations in full detail.

* Readelf now has a -j/--display-section option which takes the name
  or index of a section and displays its contents according to its
  type.  The option can be used multiple times on the command line to
  display multiple sections.

* When objdump or readelf are used to display the contents of a
  .eh_frame section they will now also display the contents of the
  .eh_frame_hdr section, if present.

    Gprofng:

* Improved the support for hardware event counters:
    - Re-designed and streamlined the implementation.
    - Defined a common set of events for ARM processors.
    - Added specific events for AMD ZEN3 / ZEN4, and Intel
      Ice Lake processors.
* Added a minimal support for RISC-V.

    General:

* Target specific improvements for many architectures.
@
text
@d3 1
a3 1
@@c Copyright (C) 1992-2025 Free Software Foundation, Inc.
d15 1
a15 1
Copyright @@copyright{} 1992-2025 Free Software Foundation, Inc.
d58 1
a58 1
Copyright @@copyright{} 1992-2025 Free Software Foundation, Inc.
a254 1

a257 1

a260 1

a263 1

a266 1

a273 1

d280 2
a281 2
option.  The output has an extension of @@file{.xc}.

a289 55

@@item wshared
Like @@emph{cshared} but in addition to needing the @@option{-shared}
and @@option{-z combreloc} options, it also needs the @@option{-z relro}
option.  If the @@option{-z now} option is also used then the output has
an extension of @@file{.xsw}, otherwise it is @@file{.xsco}.

@@item pie
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_PIE_SCRIPT} is defined in the
@@file{emulparams} file.  The @@file{emultempl} script must arrange to use
this script at the appropriate time, normally when the linker is invoked
with the @@code{-pie} option.  The output has an extension of
@@file{.xd}.

In addition if the @@file{scripttempl} script is also invoked with
@@code{GENERATE_RELRO_SCRIPT} defined then a second script is created
with an extension of @@file{.xdo} to match the @@option{-pie} and
@@option{-z relro} options.

@@item cpie
Like @@code{pie} but this version is used when the @@file{scripttempl}
script is invoked with both @@code{GENERATE_PIE_SCRIPT} and
@@code{GENERATE_COMBRELOC_SCRIPT} defined.  The @@file{emultempl} script
must arrange to use this script at the appropriate time, normally when
the linker is invoked with the @@code{-pie} and @@option{-z combreloc}
options.  The output has an extension of @@file{.xdc}.

@@item wpie
Like @@code{cpie}, but in addition the @@option{-z relro} and
@@option{-z now} options need to be defined.  The output has an
extension of @@file{.xdw}.

@@item textonly
@@item pietextonly
@@item cpietextonly
@@item wpietextonly

@@item ctextonly
@@item wtextonly
@@item sharedtextonly
@@item csharedtextonly
@@item wsharedtextonly

@@item rotextonly
@@item roctextonly
@@item rowtextonly
@@item rosharedtextonly
@@item rocsharedtextonly
@@item rowsharedtextonly
@@item ropietextonly
@@item rocpietextonly
@@item rowpietextonly


a296 1

a298 1

@


1.1.1.6
log
@Import binutils-2.46.0 (previous was 2.45)

Changes in 2.45:

* New versioned release of libsframe: libsframe.so.2.  This release introduces
  versioned symbols with version node name LIBSFRAME_2.0.  Some new symbols
  have been added to support the new flag SFRAME_F_FDE_FUNC_START_PCREL and
  retrieving flags from SFrame decoder and encoder objects:
    - Addition of sframe_decoder_get_flags,
      sframe_decoder_get_offsetof_fde_start_addr, sframe_encoder_get_flags,
      sframe_encoder_get_offsetof_fde_start_addr.
  This release also includes backward-incompatible ABI changes:
    - Removal of sframe_get_funcdesc_with_addr.
    - Change in the behavior of sframe_decoder_get_funcdesc_v2,
      sframe_encoder_add_funcdesc_v2 and sframe_encoder_write.

* On s390 64-bit (s390x), gas, ld, objdump, and readelf now support generating
  and processing SFrame V2 stack trace information (.sframe).  The assembler
  generates SFrame info from CFI directives with option "--gsframe".  The
  linker generates SFrame info for the linker-generated .plt section and merges
  all .sframe sections.  Both objdump and readelf dump SFrame info with option
  "--sframe[=<section-name>]".

* For SFrame stack trace format, the function start address in each SFrame
  FDE has a changed encoding:  The 32-bit signed integer now holds the offset
  of the start PC of the associated function from the sfde_func_start_address
  field itself (instead of the earlier where it was the offset from the start
  of the SFrame section itself).  All SFrame sections generated by gas and ld
  now default to this new encoding, setting the (new)
  SFRAME_F_FDE_FUNC_START_PCREL flag.

  Relocatable SFrame links are now fixed.

* Readelf now recognizes RISC-V GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS and
  GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED for zicfiss and zicfilp
  extensions.

* For RISC-V dis-assembler, the definition of mapping symbol $x is changed,
  so the file needs to be rebuilt since 2.45 once used .option arch directives.

* The LoongArch disassembler now properly accepts multiple disassembly
  options given by -M, such as "-M no-aliases,numeric".  (Previously only the
  first option took effect.)
@
text
@d3 1
a3 1
@@c Copyright (C) 1992-2026 Free Software Foundation, Inc.
d15 1
a15 1
Copyright @@copyright{} 1992-2026 Free Software Foundation, Inc.
d58 1
a58 1
Copyright @@copyright{} 1992-2026 Free Software Foundation, Inc.
@


1.1.1.1.4.1
log
@file ldint.texi was added on branch phil-wifi on 2019-06-10 21:52:23 +0000
@
text
@d1 700
@


1.1.1.1.4.2
log
@Sync with HEAD
@
text
@a0 700
\input texinfo
@@setfilename ldint.info
@@c Copyright (C) 1992-2018 Free Software Foundation, Inc.

@@ifnottex
@@dircategory Software development
@@direntry
* Ld-Internals: (ldint).	The GNU linker internals.
@@end direntry
@@end ifnottex

@@copying
This file documents the internals of the GNU linker ld.

Copyright @@copyright{} 1992-2018 Free Software Foundation, Inc.
Contributed by Cygnus Support.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``GNU General Public License'' and ``Funding
Free Software'', the Front-Cover texts being (a) (see below), and with
the Back-Cover Texts being (b) (see below).  A copy of the license is
included in the section entitled ``GNU Free Documentation License''.

(a) The FSF's Front-Cover Text is:

     A GNU Manual

(b) The FSF's Back-Cover Text is:

     You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development.
@@end copying

@@iftex
@@finalout
@@setchapternewpage off
@@settitle GNU Linker Internals
@@titlepage
@@title{A guide to the internals of the GNU linker}
@@author Per Bothner, Steve Chamberlain, Ian Lance Taylor, DJ Delorie
@@author Cygnus Support
@@page

@@tex
\def\$#1${{#1}}  % Kluge: collect RCS revision info without $...$
\xdef\manvers{2.10.91}  % For use in headers, footers too
{\parskip=0pt
\hfill Cygnus Support\par
\hfill \manvers\par
\hfill \TeX{}info \texinfoversion\par
}
@@end tex

@@vskip 0pt plus 1filll
Copyright @@copyright{} 1992-2018 Free Software Foundation, Inc.

      Permission is granted to copy, distribute and/or modify this document
      under the terms of the GNU Free Documentation License, Version 1.3
      or any later version published by the Free Software Foundation;
      with no Invariant Sections, with no Front-Cover Texts, and with no
      Back-Cover Texts.  A copy of the license is included in the
      section entitled "GNU Free Documentation License".

@@end titlepage
@@end iftex

@@node Top
@@top

This file documents the internals of the GNU linker @@code{ld}.  It is a
collection of miscellaneous information with little form at this point.
Mostly, it is a repository into which you can put information about
GNU @@code{ld} as you discover it (or as you design changes to @@code{ld}).

This document is distributed under the terms of the GNU Free
Documentation License.  A copy of the license is included in the
section entitled "GNU Free Documentation License".

@@menu
* README::			The README File
* Emulations::			How linker emulations are generated
* Emulation Walkthrough::	A Walkthrough of a Typical Emulation
* Architecture Specific::	Some Architecture Specific Notes
* GNU Free Documentation License::  GNU Free Documentation License
@@end menu

@@node README
@@chapter The @@file{README} File

Check the @@file{README} file; it often has useful information that does not
appear anywhere else in the directory.

@@node Emulations
@@chapter How linker emulations are generated

Each linker target has an @@dfn{emulation}.  The emulation includes the
default linker script, and certain emulations also modify certain types
of linker behaviour.

Emulations are created during the build process by the shell script
@@file{genscripts.sh}.

The @@file{genscripts.sh} script starts by reading a file in the
@@file{emulparams} directory.  This is a shell script which sets various
shell variables used by @@file{genscripts.sh} and the other shell scripts
it invokes.

The @@file{genscripts.sh} script will invoke a shell script in the
@@file{scripttempl} directory in order to create default linker scripts
written in the linker command language.  The @@file{scripttempl} script
will be invoked 5 (or, in some cases, 6) times, with different
assignments to shell variables, to create different default scripts.
The choice of script is made based on the command line options.

After creating the scripts, @@file{genscripts.sh} will invoke yet another
shell script, this time in the @@file{emultempl} directory.  That shell
script will create the emulation source file, which contains C code.
This C code permits the linker emulation to override various linker
behaviours.  Most targets use the generic emulation code, which is in
@@file{emultempl/generic.em}.

To summarize, @@file{genscripts.sh} reads three shell scripts: an
emulation parameters script in the @@file{emulparams} directory, a linker
script generation script in the @@file{scripttempl} directory, and an
emulation source file generation script in the @@file{emultempl}
directory.

For example, the Sun 4 linker sets up variables in
@@file{emulparams/sun4.sh}, creates linker scripts using
@@file{scripttempl/aout.sc}, and creates the emulation code using
@@file{emultempl/sunos.em}.

Note that the linker can support several emulations simultaneously,
depending upon how it is configured.  An emulation can be selected with
the @@code{-m} option.  The @@code{-V} option will list all supported
emulations.

@@menu
* emulation parameters::        @@file{emulparams} scripts
* linker scripts::              @@file{scripttempl} scripts
* linker emulations::           @@file{emultempl} scripts
@@end menu

@@node emulation parameters
@@section @@file{emulparams} scripts

Each target selects a particular file in the @@file{emulparams} directory
by setting the shell variable @@code{targ_emul} in @@file{configure.tgt}.
This shell variable is used by the @@file{configure} script to control
building an emulation source file.

Certain conventions are enforced.  Suppose the @@code{targ_emul} variable
is set to @@var{emul} in @@file{configure.tgt}.  The name of the emulation
shell script will be @@file{emulparams/@@var{emul}.sh}.  The
@@file{Makefile} must have a target named @@file{e@@var{emul}.c}; this
target must depend upon @@file{emulparams/@@var{emul}.sh}, as well as the
appropriate scripts in the @@file{scripttempl} and @@file{emultempl}
directories.  The @@file{Makefile} target must invoke @@code{GENSCRIPTS}
with two arguments: @@var{emul}, and the value of the make variable
@@code{tdir_@@var{emul}}.  The value of the latter variable will be set by
the @@file{configure} script, and is used to set the default target
directory to search.

By convention, the @@file{emulparams/@@var{emul}.sh} shell script should
only set shell variables.  It may set shell variables which are to be
interpreted by the @@file{scripttempl} and the @@file{emultempl} scripts.
Certain shell variables are interpreted directly by the
@@file{genscripts.sh} script.

Here is a list of shell variables interpreted by @@file{genscripts.sh},
as well as some conventional shell variables interpreted by the
@@file{scripttempl} and @@file{emultempl} scripts.

@@table @@code
@@item SCRIPT_NAME
This is the name of the @@file{scripttempl} script to use.  If
@@code{SCRIPT_NAME} is set to @@var{script}, @@file{genscripts.sh} will use
the script @@file{scripttempl/@@var{script}.sc}.

@@item TEMPLATE_NAME
This is the name of the @@file{emultempl} script to use.  If
@@code{TEMPLATE_NAME} is set to @@var{template}, @@file{genscripts.sh} will
use the script @@file{emultempl/@@var{template}.em}.  If this variable is
not set, the default value is @@samp{generic}.

@@item GENERATE_SHLIB_SCRIPT
If this is set to a nonempty string, @@file{genscripts.sh} will invoke
the @@file{scripttempl} script an extra time to create a shared library
script.  @@ref{linker scripts}.

@@item OUTPUT_FORMAT
This is normally set to indicate the BFD output format use (e.g.,
@@samp{"a.out-sunos-big"}.  The @@file{scripttempl} script will normally
use it in an @@code{OUTPUT_FORMAT} expression in the linker script.

@@item ARCH
This is normally set to indicate the architecture to use (e.g.,
@@samp{sparc}).  The @@file{scripttempl} script will normally use it in an
@@code{OUTPUT_ARCH} expression in the linker script.

@@item ENTRY
Some @@file{scripttempl} scripts use this to set the entry address, in an
@@code{ENTRY} expression in the linker script.

@@item TEXT_START_ADDR
Some @@file{scripttempl} scripts use this to set the start address of the
@@samp{.text} section.

@@item SEGMENT_SIZE
The @@file{genscripts.sh} script uses this to set the default value of
@@code{DATA_ALIGNMENT} when running the @@file{scripttempl} script.

@@item TARGET_PAGE_SIZE
If @@code{SEGMENT_SIZE} is not defined, the @@file{genscripts.sh} script
uses this to define it.

@@item ALIGNMENT
Some @@file{scripttempl} scripts set this to a number to pass to
@@code{ALIGN} to set the required alignment for the @@code{end} symbol.
@@end table

@@node linker scripts
@@section @@file{scripttempl} scripts

Each linker target uses a @@file{scripttempl} script to generate the
default linker scripts.  The name of the @@file{scripttempl} script is
set by the @@code{SCRIPT_NAME} variable in the @@file{emulparams} script.
If @@code{SCRIPT_NAME} is set to @@var{script}, @@code{genscripts.sh} will
invoke @@file{scripttempl/@@var{script}.sc}.

The @@file{genscripts.sh} script will invoke the @@file{scripttempl}
script 5 to 9 times.  Each time it will set the shell variable
@@code{LD_FLAG} to a different value.  When the linker is run, the
options used will direct it to select a particular script.  (Script
selection is controlled by the @@code{get_script} emulation entry point;
this describes the conventional behaviour).

The @@file{scripttempl} script should just write a linker script, written
in the linker command language, to standard output.  If the emulation
name--the name of the @@file{emulparams} file without the @@file{.sc}
extension--is @@var{emul}, then the output will be directed to
@@file{ldscripts/@@var{emul}.@@var{extension}} in the build directory,
where @@var{extension} changes each time the @@file{scripttempl} script is
invoked.

Here is the list of values assigned to @@code{LD_FLAG}.

@@table @@code
@@item (empty)
The script generated is used by default (when none of the following
cases apply).  The output has an extension of @@file{.x}.
@@item n
The script generated is used when the linker is invoked with the
@@code{-n} option.  The output has an extension of @@file{.xn}.
@@item N
The script generated is used when the linker is invoked with the
@@code{-N} option.  The output has an extension of @@file{.xbn}.
@@item r
The script generated is used when the linker is invoked with the
@@code{-r} option.  The output has an extension of @@file{.xr}.
@@item u
The script generated is used when the linker is invoked with the
@@code{-Ur} option.  The output has an extension of @@file{.xu}.
@@item shared
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_SHLIB_SCRIPT} is defined in the
@@file{emulparams} file.  The @@file{emultempl} script must arrange to use
this script at the appropriate time, normally when the linker is invoked
with the @@code{-shared} option.  The output has an extension of
@@file{.xs}.
@@item c
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_COMBRELOC_SCRIPT} is defined in the
@@file{emulparams} file or if @@code{SCRIPT_NAME} is @@code{elf}. The
@@file{emultempl} script must arrange to use this script at the appropriate
time, normally when the linker is invoked with the @@code{-z combreloc}
option.  The output has an extension of
@@file{.xc}.
@@item cshared
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_COMBRELOC_SCRIPT} is defined in the
@@file{emulparams} file or if @@code{SCRIPT_NAME} is @@code{elf} and
@@code{GENERATE_SHLIB_SCRIPT} is defined in the @@file{emulparams} file.
The @@file{emultempl} script must arrange to use this script at the
appropriate time, normally when the linker is invoked with the @@code{-shared
-z combreloc} option.  The output has an extension of @@file{.xsc}.
@@item auto_import
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_AUTO_IMPORT_SCRIPT} is defined in the
@@file{emulparams} file.  The @@file{emultempl} script must arrange to
use this script at the appropriate time, normally when the linker is
invoked with the @@code{--enable-auto-import} option.  The output has
an extension of @@file{.xa}.
@@end table

Besides the shell variables set by the @@file{emulparams} script, and the
@@code{LD_FLAG} variable, the @@file{genscripts.sh} script will set
certain variables for each run of the @@file{scripttempl} script.

@@table @@code
@@item RELOCATING
This will be set to a non-empty string when the linker is doing a final
relocation (e.g., all scripts other than @@code{-r} and @@code{-Ur}).

@@item CONSTRUCTING
This will be set to a non-empty string when the linker is building
global constructor and destructor tables (e.g., all scripts other than
@@code{-r}).

@@item DATA_ALIGNMENT
This will be set to an @@code{ALIGN} expression when the output should be
page aligned, or to @@samp{.} when generating the @@code{-N} script.

@@item CREATE_SHLIB
This will be set to a non-empty string when generating a @@code{-shared}
script.

@@item COMBRELOC
This will be set to a non-empty string when generating @@code{-z combreloc}
scripts to a temporary file name which can be used during script generation.
@@end table

The conventional way to write a @@file{scripttempl} script is to first
set a few shell variables, and then write out a linker script using
@@code{cat} with a here document.  The linker script will use variable
substitutions, based on the above variables and those set in the
@@file{emulparams} script, to control its behaviour.

When there are parts of the @@file{scripttempl} script which should only
be run when doing a final relocation, they should be enclosed within a
variable substitution based on @@code{RELOCATING}.  For example, on many
targets special symbols such as @@code{_end} should be defined when doing
a final link.  Naturally, those symbols should not be defined when doing
a relocatable link using @@code{-r}.  The @@file{scripttempl} script
could use a construct like this to define those symbols:
@@smallexample
  $@@{RELOCATING+ _end = .;@@}
@@end smallexample
This will do the symbol assignment only if the @@code{RELOCATING}
variable is defined.

The basic job of the linker script is to put the sections in the correct
order, and at the correct memory addresses.  For some targets, the
linker script may have to do some other operations.

For example, on most MIPS platforms, the linker is responsible for
defining the special symbol @@code{_gp}, used to initialize the
@@code{$gp} register.  It must be set to the start of the small data
section plus @@code{0x8000}.  Naturally, it should only be defined when
doing a final relocation.  This will typically be done like this:
@@smallexample
  $@@{RELOCATING+ _gp = ALIGN(16) + 0x8000;@@}
@@end smallexample
This line would appear just before the sections which compose the small
data section (@@samp{.sdata}, @@samp{.sbss}).  All those sections would be
contiguous in memory.

Many COFF systems build constructor tables in the linker script.  The
compiler will arrange to output the address of each global constructor
in a @@samp{.ctor} section, and the address of each global destructor in
a @@samp{.dtor} section (this is done by defining
@@code{ASM_OUTPUT_CONSTRUCTOR} and @@code{ASM_OUTPUT_DESTRUCTOR} in the
@@code{gcc} configuration files).  The @@code{gcc} runtime support
routines expect the constructor table to be named @@code{__CTOR_LIST__}.
They expect it to be a list of words, with the first word being the
count of the number of entries.  There should be a trailing zero word.
(Actually, the count may be -1 if the trailing word is present, and the
trailing word may be omitted if the count is correct, but, as the
@@code{gcc} behaviour has changed slightly over the years, it is safest
to provide both).  Here is a typical way that might be handled in a
@@file{scripttempl} file.
@@smallexample
    $@@{CONSTRUCTING+ __CTOR_LIST__ = .;@@}
    $@@{CONSTRUCTING+ LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)@@}
    $@@{CONSTRUCTING+ *(.ctors)@@}
    $@@{CONSTRUCTING+ LONG(0)@@}
    $@@{CONSTRUCTING+ __CTOR_END__ = .;@@}
    $@@{CONSTRUCTING+ __DTOR_LIST__ = .;@@}
    $@@{CONSTRUCTING+ LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)@@}
    $@@{CONSTRUCTING+ *(.dtors)@@}
    $@@{CONSTRUCTING+ LONG(0)@@}
    $@@{CONSTRUCTING+ __DTOR_END__ = .;@@}
@@end smallexample
The use of @@code{CONSTRUCTING} ensures that these linker script commands
will only appear when the linker is supposed to be building the
constructor and destructor tables.  This example is written for a target
which uses 4 byte pointers.

Embedded systems often need to set a stack address.  This is normally
best done by using the @@code{PROVIDE} construct with a default stack
address.  This permits the user to easily override the stack address
using the @@code{--defsym} option.  Here is an example:
@@smallexample
  $@@{RELOCATING+ PROVIDE (__stack = 0x80000000);@@}
@@end smallexample
The value of the symbol @@code{__stack} would then be used in the startup
code to initialize the stack pointer.

@@node linker emulations
@@section @@file{emultempl} scripts

Each linker target uses an @@file{emultempl} script to generate the
emulation code.  The name of the @@file{emultempl} script is set by the
@@code{TEMPLATE_NAME} variable in the @@file{emulparams} script.  If the
@@code{TEMPLATE_NAME} variable is not set, the default is
@@samp{generic}.  If the value of @@code{TEMPLATE_NAME} is @@var{template},
@@file{genscripts.sh} will use @@file{emultempl/@@var{template}.em}.

Most targets use the generic @@file{emultempl} script,
@@file{emultempl/generic.em}.  A different @@file{emultempl} script is
only needed if the linker must support unusual actions, such as linking
against shared libraries.

The @@file{emultempl} script is normally written as a simple invocation
of @@code{cat} with a here document.  The document will use a few
variable substitutions.  Typically each function names uses a
substitution involving @@code{EMULATION_NAME}, for ease of debugging when
the linker supports multiple emulations.

Every function and variable in the emitted file should be static.  The
only globally visible object must be named
@@code{ld_@@var{EMULATION_NAME}_emulation}, where @@var{EMULATION_NAME} is
the name of the emulation set in @@file{configure.tgt} (this is also the
name of the @@file{emulparams} file without the @@file{.sh} extension).
The @@file{genscripts.sh} script will set the shell variable
@@code{EMULATION_NAME} before invoking the @@file{emultempl} script.

The @@code{ld_@@var{EMULATION_NAME}_emulation} variable must be a
@@code{struct ld_emulation_xfer_struct}, as defined in @@file{ldemul.h}.
It defines a set of function pointers which are invoked by the linker,
as well as strings for the emulation name (normally set from the shell
variable @@code{EMULATION_NAME} and the default BFD target name (normally
set from the shell variable @@code{OUTPUT_FORMAT} which is normally set
by the @@file{emulparams} file).

The @@file{genscripts.sh} script will set the shell variable
@@code{COMPILE_IN} when it invokes the @@file{emultempl} script for the
default emulation.  In this case, the @@file{emultempl} script should
include the linker scripts directly, and return them from the
@@code{get_scripts} entry point.  When the emulation is not the default,
the @@code{get_scripts} entry point should just return a file name.  See
@@file{emultempl/generic.em} for an example of how this is done.

At some point, the linker emulation entry points should be documented.

@@node Emulation Walkthrough
@@chapter A Walkthrough of a Typical Emulation

This chapter is to help people who are new to the way emulations
interact with the linker, or who are suddenly thrust into the position
of having to work with existing emulations.  It will discuss the files
you need to be aware of.  It will tell you when the given "hooks" in
the emulation will be called.  It will, hopefully, give you enough
information about when and how things happen that you'll be able to
get by.  As always, the source is the definitive reference to this.

The starting point for the linker is in @@file{ldmain.c} where
@@code{main} is defined.  The bulk of the code that's emulation
specific will initially be in @@code{emultempl/@@var{emulation}.em} but
will end up in @@code{e@@var{emulation}.c} when the build is done.
Most of the work to select and interface with emulations is in
@@code{ldemul.h} and @@code{ldemul.c}.  Specifically, @@code{ldemul.h}
defines the @@code{ld_emulation_xfer_struct} structure your emulation
exports.

Your emulation file exports a symbol
@@code{ld_@@var{EMULATION_NAME}_emulation}.  If your emulation is
selected (it usually is, since usually there's only one),
@@code{ldemul.c} sets the variable @@var{ld_emulation} to point to it.
@@code{ldemul.c} also defines a number of API functions that interface
to your emulation, like @@code{ldemul_after_parse} which simply calls
your @@code{ld_@@var{EMULATION}_emulation.after_parse} function.  For
the rest of this section, the functions will be mentioned, but you
should assume the indirect reference to your emulation also.

We will also skip or gloss over parts of the link process that don't
relate to emulations, like setting up internationalization.

After initialization, @@code{main} selects an emulation by pre-scanning
the command line arguments.  It calls @@code{ldemul_choose_target} to
choose a target.  If you set @@code{choose_target} to
@@code{ldemul_default_target}, it picks your @@code{target_name} by
default.

@@code{main} calls @@code{ldemul_before_parse}, then @@code{parse_args}.
@@code{parse_args} calls @@code{ldemul_parse_args} for each arg, which
must update the @@code{getopt} globals if it recognizes the argument.
If the emulation doesn't recognize it, then parse_args checks to see
if it recognizes it.

Now that the emulation has had access to all its command-line options,
@@code{main} calls @@code{ldemul_set_symbols}.  This can be used for any
initialization that may be affected by options.  It is also supposed
to set up any variables needed by the emulation script.

@@code{main} now calls @@code{ldemul_get_script} to get the emulation
script to use (based on arguments, no doubt, @@pxref{Emulations}) and
runs it.  While parsing, @@code{ldgram.y} may call @@code{ldemul_hll} or
@@code{ldemul_syslib} to handle the @@code{HLL} or @@code{SYSLIB}
commands.  It may call @@code{ldemul_unrecognized_file} if you asked
the linker to link a file it doesn't recognize.  It will call
@@code{ldemul_recognized_file} for each file it does recognize, in case
the emulation wants to handle some files specially.  All the while,
it's loading the files (possibly calling
@@code{ldemul_open_dynamic_archive}) and symbols and stuff.  After it's
done reading the script, @@code{main} calls @@code{ldemul_after_parse}.
Use the after-parse hook to set up anything that depends on stuff the
script might have set up, like the entry point.

@@code{main} next calls @@code{lang_process} in @@code{ldlang.c}.  This
appears to be the main core of the linking itself, as far as emulation
hooks are concerned(*).  It first opens the output file's BFD, calling
@@code{ldemul_set_output_arch}, and calls
@@code{ldemul_create_output_section_statements} in case you need to use
other means to find or create object files (i.e. shared libraries
found on a path, or fake stub objects).  Despite the name, nobody
creates output sections here.

(*) In most cases, the BFD library does the bulk of the actual
linking, handling symbol tables, symbol resolution, relocations, and
building the final output file.  See the BFD reference for all the
details.  Your emulation is usually concerned more with managing
things at the file and section level, like "put this here, add this
section", etc.

Next, the objects to be linked are opened and BFDs created for them,
and @@code{ldemul_after_open} is called.  At this point, you have all
the objects and symbols loaded, but none of the data has been placed
yet.

Next comes the Big Linking Thingy (except for the parts BFD does).
All input sections are mapped to output sections according to the
script.  If a section doesn't get mapped by default,
@@code{ldemul_place_orphan} will get called to figure out where it goes.
Next it figures out the offsets for each section, calling
@@code{ldemul_before_allocation} before and
@@code{ldemul_after_allocation} after deciding where each input section
ends up in the output sections.

The last part of @@code{lang_process} is to figure out all the symbols'
values.  After assigning final values to the symbols,
@@code{ldemul_finish} is called, and after that, any undefined symbols
are turned into fatal errors.

OK, back to @@code{main}, which calls @@code{ldwrite} in
@@file{ldwrite.c}.  @@code{ldwrite} calls BFD's final_link, which does
all the relocation fixups and writes the output bfd to disk, and we're
done.

In summary,

@@itemize @@bullet

@@item @@code{main()} in @@file{ldmain.c}
@@item @@file{emultempl/@@var{EMULATION}.em} has your code
@@item @@code{ldemul_choose_target} (defaults to your @@code{target_name})
@@item @@code{ldemul_before_parse}
@@item Parse argv, calls @@code{ldemul_parse_args} for each
@@item @@code{ldemul_set_symbols}
@@item @@code{ldemul_get_script}
@@item parse script

@@itemize @@bullet
@@item may call @@code{ldemul_hll} or @@code{ldemul_syslib}
@@item may call @@code{ldemul_open_dynamic_archive}
@@end itemize

@@item @@code{ldemul_after_parse}
@@item @@code{lang_process()} in @@file{ldlang.c}

@@itemize @@bullet
@@item create @@code{output_bfd}
@@item @@code{ldemul_set_output_arch}
@@item @@code{ldemul_create_output_section_statements}
@@item read objects, create input bfds - all symbols exist, but have no values
@@item may call @@code{ldemul_unrecognized_file}
@@item will call @@code{ldemul_recognized_file}
@@item @@code{ldemul_after_open}
@@item map input sections to output sections
@@item may call @@code{ldemul_place_orphan} for remaining sections
@@item @@code{ldemul_before_allocation}
@@item gives input sections offsets into output sections, places output sections
@@item @@code{ldemul_after_allocation} - section addresses valid
@@item assigns values to symbols
@@item @@code{ldemul_finish} - symbol values valid
@@end itemize

@@item output bfd is written to disk

@@end itemize

@@node Architecture Specific
@@chapter Some Architecture Specific Notes

This is the place for notes on the behavior of @@code{ld} on
specific platforms.  Currently, only Intel x86 is documented (and
of that, only the auto-import behavior for DLLs).

@@menu
* ix86::                        Intel x86
@@end menu

@@node ix86
@@section Intel x86

@@table @@emph
@@code{ld} can create DLLs that operate with various runtimes available
on a common x86 operating system.  These runtimes include native (using
the mingw "platform"), cygwin, and pw.

@@item auto-import from DLLs
@@enumerate
@@item
With this feature on, DLL clients can import variables from DLL
without any concern from their side (for example, without any source
code modifications).  Auto-import can be enabled using the
@@code{--enable-auto-import} flag, or disabled via the
@@code{--disable-auto-import} flag.  Auto-import is disabled by default.

@@item
This is done completely in bounds of the PE specification (to be fair,
there's a minor violation of the spec at one point, but in practice
auto-import works on all known variants of that common x86 operating
system)  So, the resulting DLL can be used with any other PE
compiler/linker.

@@item
Auto-import is fully compatible with standard import method, in which
variables are decorated using attribute modifiers. Libraries of either
type may be mixed together.

@@item
Overhead (space): 8 bytes per imported symbol, plus 20 for each
reference to it; Overhead (load time): negligible; Overhead
(virtual/physical memory): should be less than effect of DLL
relocation.
@@end enumerate

Motivation

The obvious and only way to get rid of dllimport insanity is
to make client access variable directly in the DLL, bypassing
the extra dereference imposed by ordinary DLL runtime linking.
I.e., whenever client contains something like

@@code{mov dll_var,%eax,}

address of dll_var in the command should be relocated to point
into loaded DLL. The aim is to make OS loader do so, and than
make ld help with that.  Import section of PE made following
way: there's a vector of structures each describing imports
from particular DLL. Each such structure points to two other
parallel vectors: one holding imported names, and one which
will hold address of corresponding imported name. So, the
solution is de-vectorize these structures, making import
locations be sparse and pointing directly into code.

Implementation

For each reference of data symbol to be imported from DLL (to
set of which belong symbols with name <sym>, if __imp_<sym> is
found in implib), the import fixup entry is generated. That
entry is of type IMAGE_IMPORT_DESCRIPTOR and stored in .idata$3
subsection. Each fixup entry contains pointer to symbol's address
within .text section (marked with __fuN_<sym> symbol, where N is
integer), pointer to DLL name (so, DLL name is referenced by
multiple entries), and pointer to symbol name thunk. Symbol name
thunk is singleton vector (__nm_th_<symbol>) pointing to
IMAGE_IMPORT_BY_NAME structure (__nm_<symbol>) directly containing
imported name. Here comes that "om the edge" problem mentioned above:
PE specification rambles that name vector (OriginalFirstThunk) should
run in parallel with addresses vector (FirstThunk), i.e. that they
should have same number of elements and terminated with zero. We violate
this, since FirstThunk points directly into machine code. But in
practice, OS loader implemented the sane way: it goes thru
OriginalFirstThunk and puts addresses to FirstThunk, not something
else. It once again should be noted that dll and symbol name
structures are reused across fixup entries and should be there
anyway to support standard import stuff, so sustained overhead is
20 bytes per reference. Other question is whether having several
IMAGE_IMPORT_DESCRIPTORS for the same DLL is possible. Answer is yes,
it is done even by native compiler/linker (libth32's functions are in
fact resident in windows9x kernel32.dll, so if you use it, you have
two IMAGE_IMPORT_DESCRIPTORS for kernel32.dll). Yet other question is
whether referencing the same PE structures several times is valid.
The answer is why not, prohibiting that (detecting violation) would
require more work on behalf of loader than not doing it.

@@end table

@@node GNU Free Documentation License
@@chapter GNU Free Documentation License

@@include fdl.texi

@@contents
@@bye
@


1.1.1.1.4.3
log
@Merge changes from current as of 20200406
@
text
@d3 1
a3 1
@@c Copyright (C) 1992-2020 Free Software Foundation, Inc.
d15 1
a15 1
Copyright @@copyright{} 1992-2020 Free Software Foundation, Inc.
d58 1
a58 1
Copyright @@copyright{} 1992-2020 Free Software Foundation, Inc.
d116 1
a116 1
The choice of script is made based on the command-line options.
d483 1
a483 1
the command-line arguments.  It calls @@code{ldemul_choose_target} to
@


1.1.1.1.2.1
log
@file ldint.texi was added on branch pgoyette-compat on 2018-11-26 01:50:19 +0000
@
text
@d1 700
@


1.1.1.1.2.2
log
@Sync with HEAD, resolve a couple of conflicts
@
text
@a0 700
\input texinfo
@@setfilename ldint.info
@@c Copyright (C) 1992-2018 Free Software Foundation, Inc.

@@ifnottex
@@dircategory Software development
@@direntry
* Ld-Internals: (ldint).	The GNU linker internals.
@@end direntry
@@end ifnottex

@@copying
This file documents the internals of the GNU linker ld.

Copyright @@copyright{} 1992-2018 Free Software Foundation, Inc.
Contributed by Cygnus Support.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``GNU General Public License'' and ``Funding
Free Software'', the Front-Cover texts being (a) (see below), and with
the Back-Cover Texts being (b) (see below).  A copy of the license is
included in the section entitled ``GNU Free Documentation License''.

(a) The FSF's Front-Cover Text is:

     A GNU Manual

(b) The FSF's Back-Cover Text is:

     You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development.
@@end copying

@@iftex
@@finalout
@@setchapternewpage off
@@settitle GNU Linker Internals
@@titlepage
@@title{A guide to the internals of the GNU linker}
@@author Per Bothner, Steve Chamberlain, Ian Lance Taylor, DJ Delorie
@@author Cygnus Support
@@page

@@tex
\def\$#1${{#1}}  % Kluge: collect RCS revision info without $...$
\xdef\manvers{2.10.91}  % For use in headers, footers too
{\parskip=0pt
\hfill Cygnus Support\par
\hfill \manvers\par
\hfill \TeX{}info \texinfoversion\par
}
@@end tex

@@vskip 0pt plus 1filll
Copyright @@copyright{} 1992-2018 Free Software Foundation, Inc.

      Permission is granted to copy, distribute and/or modify this document
      under the terms of the GNU Free Documentation License, Version 1.3
      or any later version published by the Free Software Foundation;
      with no Invariant Sections, with no Front-Cover Texts, and with no
      Back-Cover Texts.  A copy of the license is included in the
      section entitled "GNU Free Documentation License".

@@end titlepage
@@end iftex

@@node Top
@@top

This file documents the internals of the GNU linker @@code{ld}.  It is a
collection of miscellaneous information with little form at this point.
Mostly, it is a repository into which you can put information about
GNU @@code{ld} as you discover it (or as you design changes to @@code{ld}).

This document is distributed under the terms of the GNU Free
Documentation License.  A copy of the license is included in the
section entitled "GNU Free Documentation License".

@@menu
* README::			The README File
* Emulations::			How linker emulations are generated
* Emulation Walkthrough::	A Walkthrough of a Typical Emulation
* Architecture Specific::	Some Architecture Specific Notes
* GNU Free Documentation License::  GNU Free Documentation License
@@end menu

@@node README
@@chapter The @@file{README} File

Check the @@file{README} file; it often has useful information that does not
appear anywhere else in the directory.

@@node Emulations
@@chapter How linker emulations are generated

Each linker target has an @@dfn{emulation}.  The emulation includes the
default linker script, and certain emulations also modify certain types
of linker behaviour.

Emulations are created during the build process by the shell script
@@file{genscripts.sh}.

The @@file{genscripts.sh} script starts by reading a file in the
@@file{emulparams} directory.  This is a shell script which sets various
shell variables used by @@file{genscripts.sh} and the other shell scripts
it invokes.

The @@file{genscripts.sh} script will invoke a shell script in the
@@file{scripttempl} directory in order to create default linker scripts
written in the linker command language.  The @@file{scripttempl} script
will be invoked 5 (or, in some cases, 6) times, with different
assignments to shell variables, to create different default scripts.
The choice of script is made based on the command line options.

After creating the scripts, @@file{genscripts.sh} will invoke yet another
shell script, this time in the @@file{emultempl} directory.  That shell
script will create the emulation source file, which contains C code.
This C code permits the linker emulation to override various linker
behaviours.  Most targets use the generic emulation code, which is in
@@file{emultempl/generic.em}.

To summarize, @@file{genscripts.sh} reads three shell scripts: an
emulation parameters script in the @@file{emulparams} directory, a linker
script generation script in the @@file{scripttempl} directory, and an
emulation source file generation script in the @@file{emultempl}
directory.

For example, the Sun 4 linker sets up variables in
@@file{emulparams/sun4.sh}, creates linker scripts using
@@file{scripttempl/aout.sc}, and creates the emulation code using
@@file{emultempl/sunos.em}.

Note that the linker can support several emulations simultaneously,
depending upon how it is configured.  An emulation can be selected with
the @@code{-m} option.  The @@code{-V} option will list all supported
emulations.

@@menu
* emulation parameters::        @@file{emulparams} scripts
* linker scripts::              @@file{scripttempl} scripts
* linker emulations::           @@file{emultempl} scripts
@@end menu

@@node emulation parameters
@@section @@file{emulparams} scripts

Each target selects a particular file in the @@file{emulparams} directory
by setting the shell variable @@code{targ_emul} in @@file{configure.tgt}.
This shell variable is used by the @@file{configure} script to control
building an emulation source file.

Certain conventions are enforced.  Suppose the @@code{targ_emul} variable
is set to @@var{emul} in @@file{configure.tgt}.  The name of the emulation
shell script will be @@file{emulparams/@@var{emul}.sh}.  The
@@file{Makefile} must have a target named @@file{e@@var{emul}.c}; this
target must depend upon @@file{emulparams/@@var{emul}.sh}, as well as the
appropriate scripts in the @@file{scripttempl} and @@file{emultempl}
directories.  The @@file{Makefile} target must invoke @@code{GENSCRIPTS}
with two arguments: @@var{emul}, and the value of the make variable
@@code{tdir_@@var{emul}}.  The value of the latter variable will be set by
the @@file{configure} script, and is used to set the default target
directory to search.

By convention, the @@file{emulparams/@@var{emul}.sh} shell script should
only set shell variables.  It may set shell variables which are to be
interpreted by the @@file{scripttempl} and the @@file{emultempl} scripts.
Certain shell variables are interpreted directly by the
@@file{genscripts.sh} script.

Here is a list of shell variables interpreted by @@file{genscripts.sh},
as well as some conventional shell variables interpreted by the
@@file{scripttempl} and @@file{emultempl} scripts.

@@table @@code
@@item SCRIPT_NAME
This is the name of the @@file{scripttempl} script to use.  If
@@code{SCRIPT_NAME} is set to @@var{script}, @@file{genscripts.sh} will use
the script @@file{scripttempl/@@var{script}.sc}.

@@item TEMPLATE_NAME
This is the name of the @@file{emultempl} script to use.  If
@@code{TEMPLATE_NAME} is set to @@var{template}, @@file{genscripts.sh} will
use the script @@file{emultempl/@@var{template}.em}.  If this variable is
not set, the default value is @@samp{generic}.

@@item GENERATE_SHLIB_SCRIPT
If this is set to a nonempty string, @@file{genscripts.sh} will invoke
the @@file{scripttempl} script an extra time to create a shared library
script.  @@ref{linker scripts}.

@@item OUTPUT_FORMAT
This is normally set to indicate the BFD output format use (e.g.,
@@samp{"a.out-sunos-big"}.  The @@file{scripttempl} script will normally
use it in an @@code{OUTPUT_FORMAT} expression in the linker script.

@@item ARCH
This is normally set to indicate the architecture to use (e.g.,
@@samp{sparc}).  The @@file{scripttempl} script will normally use it in an
@@code{OUTPUT_ARCH} expression in the linker script.

@@item ENTRY
Some @@file{scripttempl} scripts use this to set the entry address, in an
@@code{ENTRY} expression in the linker script.

@@item TEXT_START_ADDR
Some @@file{scripttempl} scripts use this to set the start address of the
@@samp{.text} section.

@@item SEGMENT_SIZE
The @@file{genscripts.sh} script uses this to set the default value of
@@code{DATA_ALIGNMENT} when running the @@file{scripttempl} script.

@@item TARGET_PAGE_SIZE
If @@code{SEGMENT_SIZE} is not defined, the @@file{genscripts.sh} script
uses this to define it.

@@item ALIGNMENT
Some @@file{scripttempl} scripts set this to a number to pass to
@@code{ALIGN} to set the required alignment for the @@code{end} symbol.
@@end table

@@node linker scripts
@@section @@file{scripttempl} scripts

Each linker target uses a @@file{scripttempl} script to generate the
default linker scripts.  The name of the @@file{scripttempl} script is
set by the @@code{SCRIPT_NAME} variable in the @@file{emulparams} script.
If @@code{SCRIPT_NAME} is set to @@var{script}, @@code{genscripts.sh} will
invoke @@file{scripttempl/@@var{script}.sc}.

The @@file{genscripts.sh} script will invoke the @@file{scripttempl}
script 5 to 9 times.  Each time it will set the shell variable
@@code{LD_FLAG} to a different value.  When the linker is run, the
options used will direct it to select a particular script.  (Script
selection is controlled by the @@code{get_script} emulation entry point;
this describes the conventional behaviour).

The @@file{scripttempl} script should just write a linker script, written
in the linker command language, to standard output.  If the emulation
name--the name of the @@file{emulparams} file without the @@file{.sc}
extension--is @@var{emul}, then the output will be directed to
@@file{ldscripts/@@var{emul}.@@var{extension}} in the build directory,
where @@var{extension} changes each time the @@file{scripttempl} script is
invoked.

Here is the list of values assigned to @@code{LD_FLAG}.

@@table @@code
@@item (empty)
The script generated is used by default (when none of the following
cases apply).  The output has an extension of @@file{.x}.
@@item n
The script generated is used when the linker is invoked with the
@@code{-n} option.  The output has an extension of @@file{.xn}.
@@item N
The script generated is used when the linker is invoked with the
@@code{-N} option.  The output has an extension of @@file{.xbn}.
@@item r
The script generated is used when the linker is invoked with the
@@code{-r} option.  The output has an extension of @@file{.xr}.
@@item u
The script generated is used when the linker is invoked with the
@@code{-Ur} option.  The output has an extension of @@file{.xu}.
@@item shared
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_SHLIB_SCRIPT} is defined in the
@@file{emulparams} file.  The @@file{emultempl} script must arrange to use
this script at the appropriate time, normally when the linker is invoked
with the @@code{-shared} option.  The output has an extension of
@@file{.xs}.
@@item c
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_COMBRELOC_SCRIPT} is defined in the
@@file{emulparams} file or if @@code{SCRIPT_NAME} is @@code{elf}. The
@@file{emultempl} script must arrange to use this script at the appropriate
time, normally when the linker is invoked with the @@code{-z combreloc}
option.  The output has an extension of
@@file{.xc}.
@@item cshared
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_COMBRELOC_SCRIPT} is defined in the
@@file{emulparams} file or if @@code{SCRIPT_NAME} is @@code{elf} and
@@code{GENERATE_SHLIB_SCRIPT} is defined in the @@file{emulparams} file.
The @@file{emultempl} script must arrange to use this script at the
appropriate time, normally when the linker is invoked with the @@code{-shared
-z combreloc} option.  The output has an extension of @@file{.xsc}.
@@item auto_import
The @@file{scripttempl} script is only invoked with @@code{LD_FLAG} set to
this value if @@code{GENERATE_AUTO_IMPORT_SCRIPT} is defined in the
@@file{emulparams} file.  The @@file{emultempl} script must arrange to
use this script at the appropriate time, normally when the linker is
invoked with the @@code{--enable-auto-import} option.  The output has
an extension of @@file{.xa}.
@@end table

Besides the shell variables set by the @@file{emulparams} script, and the
@@code{LD_FLAG} variable, the @@file{genscripts.sh} script will set
certain variables for each run of the @@file{scripttempl} script.

@@table @@code
@@item RELOCATING
This will be set to a non-empty string when the linker is doing a final
relocation (e.g., all scripts other than @@code{-r} and @@code{-Ur}).

@@item CONSTRUCTING
This will be set to a non-empty string when the linker is building
global constructor and destructor tables (e.g., all scripts other than
@@code{-r}).

@@item DATA_ALIGNMENT
This will be set to an @@code{ALIGN} expression when the output should be
page aligned, or to @@samp{.} when generating the @@code{-N} script.

@@item CREATE_SHLIB
This will be set to a non-empty string when generating a @@code{-shared}
script.

@@item COMBRELOC
This will be set to a non-empty string when generating @@code{-z combreloc}
scripts to a temporary file name which can be used during script generation.
@@end table

The conventional way to write a @@file{scripttempl} script is to first
set a few shell variables, and then write out a linker script using
@@code{cat} with a here document.  The linker script will use variable
substitutions, based on the above variables and those set in the
@@file{emulparams} script, to control its behaviour.

When there are parts of the @@file{scripttempl} script which should only
be run when doing a final relocation, they should be enclosed within a
variable substitution based on @@code{RELOCATING}.  For example, on many
targets special symbols such as @@code{_end} should be defined when doing
a final link.  Naturally, those symbols should not be defined when doing
a relocatable link using @@code{-r}.  The @@file{scripttempl} script
could use a construct like this to define those symbols:
@@smallexample
  $@@{RELOCATING+ _end = .;@@}
@@end smallexample
This will do the symbol assignment only if the @@code{RELOCATING}
variable is defined.

The basic job of the linker script is to put the sections in the correct
order, and at the correct memory addresses.  For some targets, the
linker script may have to do some other operations.

For example, on most MIPS platforms, the linker is responsible for
defining the special symbol @@code{_gp}, used to initialize the
@@code{$gp} register.  It must be set to the start of the small data
section plus @@code{0x8000}.  Naturally, it should only be defined when
doing a final relocation.  This will typically be done like this:
@@smallexample
  $@@{RELOCATING+ _gp = ALIGN(16) + 0x8000;@@}
@@end smallexample
This line would appear just before the sections which compose the small
data section (@@samp{.sdata}, @@samp{.sbss}).  All those sections would be
contiguous in memory.

Many COFF systems build constructor tables in the linker script.  The
compiler will arrange to output the address of each global constructor
in a @@samp{.ctor} section, and the address of each global destructor in
a @@samp{.dtor} section (this is done by defining
@@code{ASM_OUTPUT_CONSTRUCTOR} and @@code{ASM_OUTPUT_DESTRUCTOR} in the
@@code{gcc} configuration files).  The @@code{gcc} runtime support
routines expect the constructor table to be named @@code{__CTOR_LIST__}.
They expect it to be a list of words, with the first word being the
count of the number of entries.  There should be a trailing zero word.
(Actually, the count may be -1 if the trailing word is present, and the
trailing word may be omitted if the count is correct, but, as the
@@code{gcc} behaviour has changed slightly over the years, it is safest
to provide both).  Here is a typical way that might be handled in a
@@file{scripttempl} file.
@@smallexample
    $@@{CONSTRUCTING+ __CTOR_LIST__ = .;@@}
    $@@{CONSTRUCTING+ LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)@@}
    $@@{CONSTRUCTING+ *(.ctors)@@}
    $@@{CONSTRUCTING+ LONG(0)@@}
    $@@{CONSTRUCTING+ __CTOR_END__ = .;@@}
    $@@{CONSTRUCTING+ __DTOR_LIST__ = .;@@}
    $@@{CONSTRUCTING+ LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)@@}
    $@@{CONSTRUCTING+ *(.dtors)@@}
    $@@{CONSTRUCTING+ LONG(0)@@}
    $@@{CONSTRUCTING+ __DTOR_END__ = .;@@}
@@end smallexample
The use of @@code{CONSTRUCTING} ensures that these linker script commands
will only appear when the linker is supposed to be building the
constructor and destructor tables.  This example is written for a target
which uses 4 byte pointers.

Embedded systems often need to set a stack address.  This is normally
best done by using the @@code{PROVIDE} construct with a default stack
address.  This permits the user to easily override the stack address
using the @@code{--defsym} option.  Here is an example:
@@smallexample
  $@@{RELOCATING+ PROVIDE (__stack = 0x80000000);@@}
@@end smallexample
The value of the symbol @@code{__stack} would then be used in the startup
code to initialize the stack pointer.

@@node linker emulations
@@section @@file{emultempl} scripts

Each linker target uses an @@file{emultempl} script to generate the
emulation code.  The name of the @@file{emultempl} script is set by the
@@code{TEMPLATE_NAME} variable in the @@file{emulparams} script.  If the
@@code{TEMPLATE_NAME} variable is not set, the default is
@@samp{generic}.  If the value of @@code{TEMPLATE_NAME} is @@var{template},
@@file{genscripts.sh} will use @@file{emultempl/@@var{template}.em}.

Most targets use the generic @@file{emultempl} script,
@@file{emultempl/generic.em}.  A different @@file{emultempl} script is
only needed if the linker must support unusual actions, such as linking
against shared libraries.

The @@file{emultempl} script is normally written as a simple invocation
of @@code{cat} with a here document.  The document will use a few
variable substitutions.  Typically each function names uses a
substitution involving @@code{EMULATION_NAME}, for ease of debugging when
the linker supports multiple emulations.

Every function and variable in the emitted file should be static.  The
only globally visible object must be named
@@code{ld_@@var{EMULATION_NAME}_emulation}, where @@var{EMULATION_NAME} is
the name of the emulation set in @@file{configure.tgt} (this is also the
name of the @@file{emulparams} file without the @@file{.sh} extension).
The @@file{genscripts.sh} script will set the shell variable
@@code{EMULATION_NAME} before invoking the @@file{emultempl} script.

The @@code{ld_@@var{EMULATION_NAME}_emulation} variable must be a
@@code{struct ld_emulation_xfer_struct}, as defined in @@file{ldemul.h}.
It defines a set of function pointers which are invoked by the linker,
as well as strings for the emulation name (normally set from the shell
variable @@code{EMULATION_NAME} and the default BFD target name (normally
set from the shell variable @@code{OUTPUT_FORMAT} which is normally set
by the @@file{emulparams} file).

The @@file{genscripts.sh} script will set the shell variable
@@code{COMPILE_IN} when it invokes the @@file{emultempl} script for the
default emulation.  In this case, the @@file{emultempl} script should
include the linker scripts directly, and return them from the
@@code{get_scripts} entry point.  When the emulation is not the default,
the @@code{get_scripts} entry point should just return a file name.  See
@@file{emultempl/generic.em} for an example of how this is done.

At some point, the linker emulation entry points should be documented.

@@node Emulation Walkthrough
@@chapter A Walkthrough of a Typical Emulation

This chapter is to help people who are new to the way emulations
interact with the linker, or who are suddenly thrust into the position
of having to work with existing emulations.  It will discuss the files
you need to be aware of.  It will tell you when the given "hooks" in
the emulation will be called.  It will, hopefully, give you enough
information about when and how things happen that you'll be able to
get by.  As always, the source is the definitive reference to this.

The starting point for the linker is in @@file{ldmain.c} where
@@code{main} is defined.  The bulk of the code that's emulation
specific will initially be in @@code{emultempl/@@var{emulation}.em} but
will end up in @@code{e@@var{emulation}.c} when the build is done.
Most of the work to select and interface with emulations is in
@@code{ldemul.h} and @@code{ldemul.c}.  Specifically, @@code{ldemul.h}
defines the @@code{ld_emulation_xfer_struct} structure your emulation
exports.

Your emulation file exports a symbol
@@code{ld_@@var{EMULATION_NAME}_emulation}.  If your emulation is
selected (it usually is, since usually there's only one),
@@code{ldemul.c} sets the variable @@var{ld_emulation} to point to it.
@@code{ldemul.c} also defines a number of API functions that interface
to your emulation, like @@code{ldemul_after_parse} which simply calls
your @@code{ld_@@var{EMULATION}_emulation.after_parse} function.  For
the rest of this section, the functions will be mentioned, but you
should assume the indirect reference to your emulation also.

We will also skip or gloss over parts of the link process that don't
relate to emulations, like setting up internationalization.

After initialization, @@code{main} selects an emulation by pre-scanning
the command line arguments.  It calls @@code{ldemul_choose_target} to
choose a target.  If you set @@code{choose_target} to
@@code{ldemul_default_target}, it picks your @@code{target_name} by
default.

@@code{main} calls @@code{ldemul_before_parse}, then @@code{parse_args}.
@@code{parse_args} calls @@code{ldemul_parse_args} for each arg, which
must update the @@code{getopt} globals if it recognizes the argument.
If the emulation doesn't recognize it, then parse_args checks to see
if it recognizes it.

Now that the emulation has had access to all its command-line options,
@@code{main} calls @@code{ldemul_set_symbols}.  This can be used for any
initialization that may be affected by options.  It is also supposed
to set up any variables needed by the emulation script.

@@code{main} now calls @@code{ldemul_get_script} to get the emulation
script to use (based on arguments, no doubt, @@pxref{Emulations}) and
runs it.  While parsing, @@code{ldgram.y} may call @@code{ldemul_hll} or
@@code{ldemul_syslib} to handle the @@code{HLL} or @@code{SYSLIB}
commands.  It may call @@code{ldemul_unrecognized_file} if you asked
the linker to link a file it doesn't recognize.  It will call
@@code{ldemul_recognized_file} for each file it does recognize, in case
the emulation wants to handle some files specially.  All the while,
it's loading the files (possibly calling
@@code{ldemul_open_dynamic_archive}) and symbols and stuff.  After it's
done reading the script, @@code{main} calls @@code{ldemul_after_parse}.
Use the after-parse hook to set up anything that depends on stuff the
script might have set up, like the entry point.

@@code{main} next calls @@code{lang_process} in @@code{ldlang.c}.  This
appears to be the main core of the linking itself, as far as emulation
hooks are concerned(*).  It first opens the output file's BFD, calling
@@code{ldemul_set_output_arch}, and calls
@@code{ldemul_create_output_section_statements} in case you need to use
other means to find or create object files (i.e. shared libraries
found on a path, or fake stub objects).  Despite the name, nobody
creates output sections here.

(*) In most cases, the BFD library does the bulk of the actual
linking, handling symbol tables, symbol resolution, relocations, and
building the final output file.  See the BFD reference for all the
details.  Your emulation is usually concerned more with managing
things at the file and section level, like "put this here, add this
section", etc.

Next, the objects to be linked are opened and BFDs created for them,
and @@code{ldemul_after_open} is called.  At this point, you have all
the objects and symbols loaded, but none of the data has been placed
yet.

Next comes the Big Linking Thingy (except for the parts BFD does).
All input sections are mapped to output sections according to the
script.  If a section doesn't get mapped by default,
@@code{ldemul_place_orphan} will get called to figure out where it goes.
Next it figures out the offsets for each section, calling
@@code{ldemul_before_allocation} before and
@@code{ldemul_after_allocation} after deciding where each input section
ends up in the output sections.

The last part of @@code{lang_process} is to figure out all the symbols'
values.  After assigning final values to the symbols,
@@code{ldemul_finish} is called, and after that, any undefined symbols
are turned into fatal errors.

OK, back to @@code{main}, which calls @@code{ldwrite} in
@@file{ldwrite.c}.  @@code{ldwrite} calls BFD's final_link, which does
all the relocation fixups and writes the output bfd to disk, and we're
done.

In summary,

@@itemize @@bullet

@@item @@code{main()} in @@file{ldmain.c}
@@item @@file{emultempl/@@var{EMULATION}.em} has your code
@@item @@code{ldemul_choose_target} (defaults to your @@code{target_name})
@@item @@code{ldemul_before_parse}
@@item Parse argv, calls @@code{ldemul_parse_args} for each
@@item @@code{ldemul_set_symbols}
@@item @@code{ldemul_get_script}
@@item parse script

@@itemize @@bullet
@@item may call @@code{ldemul_hll} or @@code{ldemul_syslib}
@@item may call @@code{ldemul_open_dynamic_archive}
@@end itemize

@@item @@code{ldemul_after_parse}
@@item @@code{lang_process()} in @@file{ldlang.c}

@@itemize @@bullet
@@item create @@code{output_bfd}
@@item @@code{ldemul_set_output_arch}
@@item @@code{ldemul_create_output_section_statements}
@@item read objects, create input bfds - all symbols exist, but have no values
@@item may call @@code{ldemul_unrecognized_file}
@@item will call @@code{ldemul_recognized_file}
@@item @@code{ldemul_after_open}
@@item map input sections to output sections
@@item may call @@code{ldemul_place_orphan} for remaining sections
@@item @@code{ldemul_before_allocation}
@@item gives input sections offsets into output sections, places output sections
@@item @@code{ldemul_after_allocation} - section addresses valid
@@item assigns values to symbols
@@item @@code{ldemul_finish} - symbol values valid
@@end itemize

@@item output bfd is written to disk

@@end itemize

@@node Architecture Specific
@@chapter Some Architecture Specific Notes

This is the place for notes on the behavior of @@code{ld} on
specific platforms.  Currently, only Intel x86 is documented (and
of that, only the auto-import behavior for DLLs).

@@menu
* ix86::                        Intel x86
@@end menu

@@node ix86
@@section Intel x86

@@table @@emph
@@code{ld} can create DLLs that operate with various runtimes available
on a common x86 operating system.  These runtimes include native (using
the mingw "platform"), cygwin, and pw.

@@item auto-import from DLLs
@@enumerate
@@item
With this feature on, DLL clients can import variables from DLL
without any concern from their side (for example, without any source
code modifications).  Auto-import can be enabled using the
@@code{--enable-auto-import} flag, or disabled via the
@@code{--disable-auto-import} flag.  Auto-import is disabled by default.

@@item
This is done completely in bounds of the PE specification (to be fair,
there's a minor violation of the spec at one point, but in practice
auto-import works on all known variants of that common x86 operating
system)  So, the resulting DLL can be used with any other PE
compiler/linker.

@@item
Auto-import is fully compatible with standard import method, in which
variables are decorated using attribute modifiers. Libraries of either
type may be mixed together.

@@item
Overhead (space): 8 bytes per imported symbol, plus 20 for each
reference to it; Overhead (load time): negligible; Overhead
(virtual/physical memory): should be less than effect of DLL
relocation.
@@end enumerate

Motivation

The obvious and only way to get rid of dllimport insanity is
to make client access variable directly in the DLL, bypassing
the extra dereference imposed by ordinary DLL runtime linking.
I.e., whenever client contains something like

@@code{mov dll_var,%eax,}

address of dll_var in the command should be relocated to point
into loaded DLL. The aim is to make OS loader do so, and than
make ld help with that.  Import section of PE made following
way: there's a vector of structures each describing imports
from particular DLL. Each such structure points to two other
parallel vectors: one holding imported names, and one which
will hold address of corresponding imported name. So, the
solution is de-vectorize these structures, making import
locations be sparse and pointing directly into code.

Implementation

For each reference of data symbol to be imported from DLL (to
set of which belong symbols with name <sym>, if __imp_<sym> is
found in implib), the import fixup entry is generated. That
entry is of type IMAGE_IMPORT_DESCRIPTOR and stored in .idata$3
subsection. Each fixup entry contains pointer to symbol's address
within .text section (marked with __fuN_<sym> symbol, where N is
integer), pointer to DLL name (so, DLL name is referenced by
multiple entries), and pointer to symbol name thunk. Symbol name
thunk is singleton vector (__nm_th_<symbol>) pointing to
IMAGE_IMPORT_BY_NAME structure (__nm_<symbol>) directly containing
imported name. Here comes that "om the edge" problem mentioned above:
PE specification rambles that name vector (OriginalFirstThunk) should
run in parallel with addresses vector (FirstThunk), i.e. that they
should have same number of elements and terminated with zero. We violate
this, since FirstThunk points directly into machine code. But in
practice, OS loader implemented the sane way: it goes thru
OriginalFirstThunk and puts addresses to FirstThunk, not something
else. It once again should be noted that dll and symbol name
structures are reused across fixup entries and should be there
anyway to support standard import stuff, so sustained overhead is
20 bytes per reference. Other question is whether having several
IMAGE_IMPORT_DESCRIPTORS for the same DLL is possible. Answer is yes,
it is done even by native compiler/linker (libth32's functions are in
fact resident in windows9x kernel32.dll, so if you use it, you have
two IMAGE_IMPORT_DESCRIPTORS for kernel32.dll). Yet other question is
whether referencing the same PE structures several times is valid.
The answer is why not, prohibiting that (detecting violation) would
require more work on behalf of loader than not doing it.

@@end table

@@node GNU Free Documentation License
@@chapter GNU Free Documentation License

@@include fdl.texi

@@contents
@@bye
@


