binutils-gdb/ld/emultempl/beos.em

783 lines
24 KiB
Plaintext
Raw Normal View History

1999-05-03 09:29:11 +02:00
# This shell script emits a C file. -*- C -*-
# It does some substitutions.
if [ -z "$MACHINE" ]; then
OUTPUT_ARCH=${ARCH}
else
OUTPUT_ARCH=${ARCH}:${MACHINE}
fi
2007-07-19 Roland McGrath <roland@redhat.com> * genscripts.sh (source_em, fragment): New sh functions. Truncate e${EMULATION_NAME}.c file before .em script fills it. Use source_em in place of . for the .em script. * emultempl/generic.em: Use fragment and source_em functions. * emultempl/aix.em: Likewise. * emultempl/alphaelf.em: Likewise. * emultempl/armcoff.em: Likewise. * emultempl/armelf.em: Likewise. * emultempl/avrelf.em: Likewise. * emultempl/beos.em: Likewise. * emultempl/cr16elf.em: Likewise. * emultempl/crxelf.em: Likewise. * emultempl/elf-generic.em: Likewise. * emultempl/elf32.em: Likewise. * emultempl/genelf.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/hppaelf.em: Likewise. * emultempl/ia64elf.em: Likewise. * emultempl/irix.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68hc1xelf.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/m68kelf.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/mipself.em: Likewise. * emultempl/mmix-elfnmmo.em: Likewise. * emultempl/mmixelf.em: Likewise. * emultempl/mmo.em: Likewise. * emultempl/needrelax.em: Likewise. * emultempl/netbsd.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/pep.em: Likewise. * emultempl/ppc32elf.em: Likewise. * emultempl/ppc64elf.em: Likewise. * emultempl/scoreelf.em: Likewise. * emultempl/sh64elf.em: Likewise. * emultempl/spuelf.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/vxworks.em: Likewise. * emultempl/xtensaelf.em: Likewise. * emultempl/z80.em: Likewise.
2007-07-19 21:56:10 +02:00
fragment <<EOF
1999-05-03 09:29:11 +02:00
/* This file is part of GLD, the Gnu Linker.
2005-03-03 12:52:12 +01:00
Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
1999-05-03 09:29:11 +02:00
2007-07-06 16:09:45 +02:00
This file is part of the GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
1999-05-03 09:29:11 +02:00
/* For WINDOWS_NT */
/* The original file generated returned different default scripts depending
on whether certain switches were set, but these switches pertain to the
Linux system and that particular version of coff. In the NT case, we
only determine if the subsystem is console or windows in order to select
the correct entry point by default. */
1999-05-03 09:29:11 +02:00
#include "sysdep.h"
#include "bfd.h"
1999-05-03 09:29:11 +02:00
#include "bfdlink.h"
#include "getopt.h"
#include "libiberty.h"
#include "filenames.h"
1999-05-03 09:29:11 +02:00
#include "ld.h"
#include "ldmain.h"
#include "ldexp.h"
#include "ldlang.h"
#include "ldfile.h"
1999-05-03 09:29:11 +02:00
#include "ldemul.h"
#include <ldgram.h>
1999-05-03 09:29:11 +02:00
#include "ldlex.h"
#include "ldmisc.h"
#include "ldctor.h"
#include "coff/internal.h"
#include "../bfd/libcoff.h"
#define TARGET_IS_${EMULATION_NAME}
static struct internal_extra_pe_aouthdr pe;
static int dll;
extern const char *output_filename;
static void
gld_${EMULATION_NAME}_before_parse (void)
1999-05-03 09:29:11 +02:00
{
ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
output_filename = "a.exe";
1999-05-03 09:29:11 +02:00
}
/* PE format extra command line options. */
/* Used for setting flags in the PE header. */
#define OPTION_BASE_FILE (300 + 1)
#define OPTION_DLL (OPTION_BASE_FILE + 1)
#define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1)
#define OPTION_IMAGE_BASE (OPTION_FILE_ALIGNMENT + 1)
#define OPTION_MAJOR_IMAGE_VERSION (OPTION_IMAGE_BASE + 1)
#define OPTION_MAJOR_OS_VERSION (OPTION_MAJOR_IMAGE_VERSION + 1)
#define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1)
#define OPTION_MINOR_IMAGE_VERSION (OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
#define OPTION_MINOR_OS_VERSION (OPTION_MINOR_IMAGE_VERSION + 1)
#define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
#define OPTION_SECTION_ALIGNMENT (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
#define OPTION_STACK (OPTION_SECTION_ALIGNMENT + 1)
#define OPTION_SUBSYSTEM (OPTION_STACK + 1)
#define OPTION_HEAP (OPTION_SUBSYSTEM + 1)
* ldemul.c (ldemul_add_options, ldemul_handle_option): New functions. (ldemul_parse_args): Return bfd_boolean. Formatting. * ldemul.h (ldemul_add_options, ldemul_handle_option): Declare. (ldemul_parse_args): Adjust. (struct ld_emulation_xfer_struct): Add add_options and handle_option. Return bfd_boolean from parse_args. * lexsup.c (parse_args): Malloc shortopts, longopts and really_longopts. Call ldemul_add_options and ldemul_handle_option. * emultempl/aix.em (gld${EMULATION_NAME}_add_options): Split out from gld${EMULATION_NAME}_parse_args. (gld${EMULATION_NAME}_handle_option): Likewise. (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/armcoff.em: As for aix.em, but remove parse_args. * emultempl/beos.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/elf32.em: Likewise. Don't duplicate long options either. (gld${EMULATION_NAME}_add_sysroot): Prototype. * emultempl/armelf.em (PARSE_AND_LIST_LONGOPTS): Don't duplicate options. * emultempl/hppaelf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc32elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc64elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/armelf_oabi.em (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/generic.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/netbsd.em (gldnetbsd_before_parse): Prototype.
2003-02-28 02:32:31 +01:00
static void
gld${EMULATION_NAME}_add_options
(int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
struct option **longopts, int nrl ATTRIBUTE_UNUSED,
struct option **really_longopts ATTRIBUTE_UNUSED)
* ldemul.c (ldemul_add_options, ldemul_handle_option): New functions. (ldemul_parse_args): Return bfd_boolean. Formatting. * ldemul.h (ldemul_add_options, ldemul_handle_option): Declare. (ldemul_parse_args): Adjust. (struct ld_emulation_xfer_struct): Add add_options and handle_option. Return bfd_boolean from parse_args. * lexsup.c (parse_args): Malloc shortopts, longopts and really_longopts. Call ldemul_add_options and ldemul_handle_option. * emultempl/aix.em (gld${EMULATION_NAME}_add_options): Split out from gld${EMULATION_NAME}_parse_args. (gld${EMULATION_NAME}_handle_option): Likewise. (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/armcoff.em: As for aix.em, but remove parse_args. * emultempl/beos.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/elf32.em: Likewise. Don't duplicate long options either. (gld${EMULATION_NAME}_add_sysroot): Prototype. * emultempl/armelf.em (PARSE_AND_LIST_LONGOPTS): Don't duplicate options. * emultempl/hppaelf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc32elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc64elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/armelf_oabi.em (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/generic.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/netbsd.em (gldnetbsd_before_parse): Prototype.
2003-02-28 02:32:31 +01:00
{
static const struct option xtra_long[] = {
/* PE options */
1999-05-03 09:29:11 +02:00
{"base-file", required_argument, NULL, OPTION_BASE_FILE},
{"dll", no_argument, NULL, OPTION_DLL},
{"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
{"heap", required_argument, NULL, OPTION_HEAP},
{"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
1999-05-03 09:29:11 +02:00
{"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
{"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
{"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
{"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
{"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
{"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
{"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
{"stack", required_argument, NULL, OPTION_STACK},
{"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
* ldemul.c (ldemul_add_options, ldemul_handle_option): New functions. (ldemul_parse_args): Return bfd_boolean. Formatting. * ldemul.h (ldemul_add_options, ldemul_handle_option): Declare. (ldemul_parse_args): Adjust. (struct ld_emulation_xfer_struct): Add add_options and handle_option. Return bfd_boolean from parse_args. * lexsup.c (parse_args): Malloc shortopts, longopts and really_longopts. Call ldemul_add_options and ldemul_handle_option. * emultempl/aix.em (gld${EMULATION_NAME}_add_options): Split out from gld${EMULATION_NAME}_parse_args. (gld${EMULATION_NAME}_handle_option): Likewise. (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/armcoff.em: As for aix.em, but remove parse_args. * emultempl/beos.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/elf32.em: Likewise. Don't duplicate long options either. (gld${EMULATION_NAME}_add_sysroot): Prototype. * emultempl/armelf.em (PARSE_AND_LIST_LONGOPTS): Don't duplicate options. * emultempl/hppaelf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc32elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc64elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/armelf_oabi.em (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/generic.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/netbsd.em (gldnetbsd_before_parse): Prototype.
2003-02-28 02:32:31 +01:00
{NULL, no_argument, NULL, 0}
1999-05-03 09:29:11 +02:00
};
* ldemul.c (ldemul_add_options, ldemul_handle_option): New functions. (ldemul_parse_args): Return bfd_boolean. Formatting. * ldemul.h (ldemul_add_options, ldemul_handle_option): Declare. (ldemul_parse_args): Adjust. (struct ld_emulation_xfer_struct): Add add_options and handle_option. Return bfd_boolean from parse_args. * lexsup.c (parse_args): Malloc shortopts, longopts and really_longopts. Call ldemul_add_options and ldemul_handle_option. * emultempl/aix.em (gld${EMULATION_NAME}_add_options): Split out from gld${EMULATION_NAME}_parse_args. (gld${EMULATION_NAME}_handle_option): Likewise. (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/armcoff.em: As for aix.em, but remove parse_args. * emultempl/beos.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/elf32.em: Likewise. Don't duplicate long options either. (gld${EMULATION_NAME}_add_sysroot): Prototype. * emultempl/armelf.em (PARSE_AND_LIST_LONGOPTS): Don't duplicate options. * emultempl/hppaelf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc32elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc64elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/armelf_oabi.em (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/generic.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/netbsd.em (gldnetbsd_before_parse): Prototype.
2003-02-28 02:32:31 +01:00
*longopts = (struct option *)
xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
}
1999-05-03 09:29:11 +02:00
/* PE/WIN32; added routines to get the subsystem type, heap and/or stack
parameters which may be input from the command line */
typedef struct {
void *ptr;
int size;
int value;
char *symbol;
int inited;
} definfo;
#define D(field,symbol,def) {&pe.field,sizeof(pe.field), def, symbol,0}
static definfo init[] =
{
/* imagebase must be first */
#define IMAGEBASEOFF 0
D(ImageBase,"__image_base__", BEOS_EXE_IMAGE_BASE),
#define DLLOFF 1
{&dll, sizeof(dll), 0, "__dll__", 0},
1999-05-03 09:29:11 +02:00
D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),
D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
D(MajorOperatingSystemVersion,"__major_os_version__", 4),
D(MinorOperatingSystemVersion,"__minor_os_version__", 0),
D(MajorImageVersion,"__major_image_version__", 1),
D(MinorImageVersion,"__minor_image_version__", 0),
D(MajorSubsystemVersion,"__major_subsystem_version__", 4),
D(MinorSubsystemVersion,"__minor_subsystem_version__", 0),
D(Subsystem,"__subsystem__", 3),
D(SizeOfStackReserve,"__size_of_stack_reserve__", 0x2000000),
D(SizeOfStackCommit,"__size_of_stack_commit__", 0x1000),
D(SizeOfHeapReserve,"__size_of_heap_reserve__", 0x100000),
D(SizeOfHeapCommit,"__size_of_heap_commit__", 0x1000),
D(LoaderFlags,"__loader_flags__", 0x0),
{ NULL, 0, 0, NULL, 0 }
};
static void
set_pe_name (char *name, long val)
1999-05-03 09:29:11 +02:00
{
int i;
/* Find the name and set it. */
for (i = 0; init[i].ptr; i++)
{
if (strcmp (name, init[i].symbol) == 0)
{
init[i].value = val;
init[i].inited = 1;
return;
}
}
abort();
}
static void
set_pe_subsystem (void)
1999-05-03 09:29:11 +02:00
{
const char *sver;
int len;
int i;
static const struct
1999-05-03 09:29:11 +02:00
{
const char *name;
const int value;
const char *entry;
}
v[] =
{
{ "native", 1, "_NtProcessStartup" },
{ "windows", 2, "_WinMainCRTStartup" },
{ "wwindows", 2, "_wWinMainCRTStartup" },
{ "console", 3, "_mainCRTStartup" },
{ "wconsole", 3, "_wmainCRTStartup" },
{ "posix", 7, "___PosixProcessStartup"},
{ 0, 0, 0 }
};
sver = strchr (optarg, ':');
if (sver == NULL)
len = strlen (optarg);
else
{
char *end;
len = sver - optarg;
set_pe_name ("__major_subsystem_version__",
strtoul (sver + 1, &end, 0));
if (*end == '.')
set_pe_name ("__minor_subsystem_version__",
strtoul (end + 1, &end, 0));
if (*end != '\0')
einfo ("%P: warning: bad version number in -subsystem option\n");
}
for (i = 0; v[i].name; i++)
{
if (strncmp (optarg, v[i].name, len) == 0
&& v[i].name[len] == '\0')
{
set_pe_name ("__subsystem__", v[i].value);
/* If the subsystem is windows, we use a different entry
point. */
lang_default_entry (v[i].entry);
1999-05-03 09:29:11 +02:00
return;
}
}
einfo ("%P%F: invalid subsystem type %s\n", optarg);
}
static void
set_pe_value (char *name)
1999-05-03 09:29:11 +02:00
{
char *end;
set_pe_name (name, strtoul (optarg, &end, 0));
if (end == optarg)
{
einfo ("%P%F: invalid hex number for PE parameter '%s'\n", optarg);
}
optarg = end;
}
static void
set_pe_stack_heap (char *resname, char *comname)
1999-05-03 09:29:11 +02:00
{
set_pe_value (resname);
if (*optarg == ',')
{
optarg++;
set_pe_value (comname);
}
else if (*optarg)
{
einfo ("%P%F: strange hex info for PE parameter '%s'\n", optarg);
}
}
* ldemul.c (ldemul_add_options, ldemul_handle_option): New functions. (ldemul_parse_args): Return bfd_boolean. Formatting. * ldemul.h (ldemul_add_options, ldemul_handle_option): Declare. (ldemul_parse_args): Adjust. (struct ld_emulation_xfer_struct): Add add_options and handle_option. Return bfd_boolean from parse_args. * lexsup.c (parse_args): Malloc shortopts, longopts and really_longopts. Call ldemul_add_options and ldemul_handle_option. * emultempl/aix.em (gld${EMULATION_NAME}_add_options): Split out from gld${EMULATION_NAME}_parse_args. (gld${EMULATION_NAME}_handle_option): Likewise. (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/armcoff.em: As for aix.em, but remove parse_args. * emultempl/beos.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/elf32.em: Likewise. Don't duplicate long options either. (gld${EMULATION_NAME}_add_sysroot): Prototype. * emultempl/armelf.em (PARSE_AND_LIST_LONGOPTS): Don't duplicate options. * emultempl/hppaelf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc32elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc64elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/armelf_oabi.em (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/generic.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/netbsd.em (gldnetbsd_before_parse): Prototype.
2003-02-28 02:32:31 +01:00
static bfd_boolean
gld${EMULATION_NAME}_handle_option (int optc)
1999-05-03 09:29:11 +02:00
{
switch (optc)
{
default:
* ldemul.c (ldemul_add_options, ldemul_handle_option): New functions. (ldemul_parse_args): Return bfd_boolean. Formatting. * ldemul.h (ldemul_add_options, ldemul_handle_option): Declare. (ldemul_parse_args): Adjust. (struct ld_emulation_xfer_struct): Add add_options and handle_option. Return bfd_boolean from parse_args. * lexsup.c (parse_args): Malloc shortopts, longopts and really_longopts. Call ldemul_add_options and ldemul_handle_option. * emultempl/aix.em (gld${EMULATION_NAME}_add_options): Split out from gld${EMULATION_NAME}_parse_args. (gld${EMULATION_NAME}_handle_option): Likewise. (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/armcoff.em: As for aix.em, but remove parse_args. * emultempl/beos.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/elf32.em: Likewise. Don't duplicate long options either. (gld${EMULATION_NAME}_add_sysroot): Prototype. * emultempl/armelf.em (PARSE_AND_LIST_LONGOPTS): Don't duplicate options. * emultempl/hppaelf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc32elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc64elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/armelf_oabi.em (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/generic.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/netbsd.em (gldnetbsd_before_parse): Prototype.
2003-02-28 02:32:31 +01:00
return FALSE;
1999-05-03 09:29:11 +02:00
case OPTION_BASE_FILE:
link_info.base_file = fopen (optarg, FOPEN_WB);
1999-05-03 09:29:11 +02:00
if (link_info.base_file == NULL)
einfo (_("%F%P: cannot open base file %s\n"), optarg);
1999-05-03 09:29:11 +02:00
break;
/* PE options */
case OPTION_HEAP:
1999-05-03 09:29:11 +02:00
set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
break;
case OPTION_STACK:
1999-05-03 09:29:11 +02:00
set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
break;
case OPTION_SUBSYSTEM:
set_pe_subsystem ();
break;
case OPTION_MAJOR_OS_VERSION:
set_pe_value ("__major_os_version__");
break;
case OPTION_MINOR_OS_VERSION:
set_pe_value ("__minor_os_version__");
break;
case OPTION_MAJOR_SUBSYSTEM_VERSION:
set_pe_value ("__major_subsystem_version__");
break;
case OPTION_MINOR_SUBSYSTEM_VERSION:
set_pe_value ("__minor_subsystem_version__");
break;
case OPTION_MAJOR_IMAGE_VERSION:
set_pe_value ("__major_image_version__");
break;
case OPTION_MINOR_IMAGE_VERSION:
set_pe_value ("__minor_image_version__");
break;
case OPTION_FILE_ALIGNMENT:
set_pe_value ("__file_alignment__");
break;
case OPTION_SECTION_ALIGNMENT:
set_pe_value ("__section_alignment__");
break;
case OPTION_DLL:
set_pe_name ("__dll__", 1);
break;
case OPTION_IMAGE_BASE:
set_pe_value ("__image_base__");
break;
}
* ldemul.c (ldemul_add_options, ldemul_handle_option): New functions. (ldemul_parse_args): Return bfd_boolean. Formatting. * ldemul.h (ldemul_add_options, ldemul_handle_option): Declare. (ldemul_parse_args): Adjust. (struct ld_emulation_xfer_struct): Add add_options and handle_option. Return bfd_boolean from parse_args. * lexsup.c (parse_args): Malloc shortopts, longopts and really_longopts. Call ldemul_add_options and ldemul_handle_option. * emultempl/aix.em (gld${EMULATION_NAME}_add_options): Split out from gld${EMULATION_NAME}_parse_args. (gld${EMULATION_NAME}_handle_option): Likewise. (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/armcoff.em: As for aix.em, but remove parse_args. * emultempl/beos.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/elf32.em: Likewise. Don't duplicate long options either. (gld${EMULATION_NAME}_add_sysroot): Prototype. * emultempl/armelf.em (PARSE_AND_LIST_LONGOPTS): Don't duplicate options. * emultempl/hppaelf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc32elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc64elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/armelf_oabi.em (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/generic.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/netbsd.em (gldnetbsd_before_parse): Prototype.
2003-02-28 02:32:31 +01:00
return TRUE;
1999-05-03 09:29:11 +02:00
}
/* Assign values to the special symbols before the linker script is
read. */
static void
gld_${EMULATION_NAME}_set_symbols (void)
1999-05-03 09:29:11 +02:00
{
/* Run through and invent symbols for all the
names and insert the defaults. */
int j;
if (!init[IMAGEBASEOFF].inited)
{
2003-06-25 08:40:27 +02:00
if (link_info.relocatable)
1999-05-03 09:29:11 +02:00
init[IMAGEBASEOFF].value = 0;
else if (init[DLLOFF].value)
init[IMAGEBASEOFF].value = BEOS_DLL_IMAGE_BASE;
else
init[IMAGEBASEOFF].value = BEOS_EXE_IMAGE_BASE;
}
2003-06-25 08:40:27 +02:00
/* Don't do any symbol assignments if this is a relocatable link. */
if (link_info.relocatable)
1999-05-03 09:29:11 +02:00
return;
/* Glue the assignments into the abs section */
push_stat_ptr (&abs_output_section->children);
1999-05-03 09:29:11 +02:00
for (j = 0; init[j].ptr; j++)
{
long val = init[j].value;
lang_add_assignment (exp_assign (init[j].symbol, exp_intop (val)));
1999-05-03 09:29:11 +02:00
if (init[j].size == sizeof(short))
*(short *)init[j].ptr = val;
else if (init[j].size == sizeof(int))
*(int *)init[j].ptr = val;
else if (init[j].size == sizeof(long))
*(long *)init[j].ptr = val;
/* This might be a long long or other special type. */
else if (init[j].size == sizeof(bfd_vma))
*(bfd_vma *)init[j].ptr = val;
else abort();
}
/* Restore the pointer. */
pop_stat_ptr ();
1999-05-03 09:29:11 +02:00
if (pe.FileAlignment >
pe.SectionAlignment)
{
einfo ("%P: warning, file alignment > section alignment.\n");
}
}
static void
gld_${EMULATION_NAME}_after_open (void)
1999-05-03 09:29:11 +02:00
{
after_open_default ();
1999-05-03 09:29:11 +02:00
/* Pass the wacky PE command line options into the output bfd.
FIXME: This should be done via a function, rather than by
including an internal BFD header. */
include/ * bfdlink.h (struct bfd_link_hash_table): Delete creator field. (struct bfd_link_info): Add output_bfd. bfd/ * elflink.c: Replace all accesses to hash->creator field with output_bfd->xvec. * cofflink.c: Likewise. * coff-h8300.c: Likewise. * ecoff.c: Likewise. * elf32-m68hc1x.c: Likewise. * elf32-ppc.c: Likewise. * elf64-alpha.c: Likewise. * elf64-ppc.c: Likewise. * elf64-sparc.c: Likewise. * elfxx-mips.c: Likewise. * i386linux.c: Likewise. * m68klinux.c: Likewise. * sparclinux.c: Likewise. * sunos.c: Likewise. * xcofflink.c: Likewise. * linker.c: Likewise. (_bfd_link_hash_table_init): Don't store creator. ld/ * ldmain.h (output_bfd): Delete. * ldmain.c (output_bfd): Delete. Replace all occurrences of output_bfd with link_info.output_bfd. * ldcref.c: Likewise. * ldctor.c: Likewise. * ldemul.c: Likewise. * ldexp.c: Likewise. * ldfile.c: Likewise. * ldlang.c: Likewise. * ldmisc.c: Likewise. * ldwrite.c: Likewise. * pe-dll.c: Likewise. * emultempl/aix.em: Likewise. * emultempl/alphaelf.em: Likewise. * emultempl/armcoff.em: Likewise. * emultempl/armelf.em: Likewise. * emultempl/avrelf.em: Likewise. * emultempl/beos.em: Likewise. * emultempl/elf-generic.em: Likewise. * emultempl/elf32.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/hppaelf.em: Likewise. * emultempl/irix.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68hc1xelf.em: Likewise. * emultempl/mmix-elfnmmo.em: Likewise. * emultempl/mmo.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/pep.em: Likewise. * emultempl/ppc32elf.em: Likewise. * emultempl/ppc64elf.em: Likewise. * emultempl/scoreelf.em: Likewise. * emultempl/sh64elf.em: Likewise. * emultempl/spuelf.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/vxworks.em: Likewise. * emultempl/xtensaelf.em: Likewise. * emultempl/z80.em: Likewise. * ldlang.c (open_output): Don't return output, instead write link_info_output_bfd directly. * emultempl/alphaelf.em: Replace occurrences of link_info.hash->creator with link_info.output_bfd->xvec. * emultempl/hppaelf.em: Likewise. * emultempl/ppc32elf.em: Likewise. * emultempl/ppc64elf.em: Likewise. * emultempl/spuelf.em: Likewise.
2008-02-15 04:35:53 +01:00
if (!coff_data(link_info.output_bfd)->pe)
1999-05-03 09:29:11 +02:00
{
einfo ("%F%P: PE operations on non PE file.\n");
}
include/ * bfdlink.h (struct bfd_link_hash_table): Delete creator field. (struct bfd_link_info): Add output_bfd. bfd/ * elflink.c: Replace all accesses to hash->creator field with output_bfd->xvec. * cofflink.c: Likewise. * coff-h8300.c: Likewise. * ecoff.c: Likewise. * elf32-m68hc1x.c: Likewise. * elf32-ppc.c: Likewise. * elf64-alpha.c: Likewise. * elf64-ppc.c: Likewise. * elf64-sparc.c: Likewise. * elfxx-mips.c: Likewise. * i386linux.c: Likewise. * m68klinux.c: Likewise. * sparclinux.c: Likewise. * sunos.c: Likewise. * xcofflink.c: Likewise. * linker.c: Likewise. (_bfd_link_hash_table_init): Don't store creator. ld/ * ldmain.h (output_bfd): Delete. * ldmain.c (output_bfd): Delete. Replace all occurrences of output_bfd with link_info.output_bfd. * ldcref.c: Likewise. * ldctor.c: Likewise. * ldemul.c: Likewise. * ldexp.c: Likewise. * ldfile.c: Likewise. * ldlang.c: Likewise. * ldmisc.c: Likewise. * ldwrite.c: Likewise. * pe-dll.c: Likewise. * emultempl/aix.em: Likewise. * emultempl/alphaelf.em: Likewise. * emultempl/armcoff.em: Likewise. * emultempl/armelf.em: Likewise. * emultempl/avrelf.em: Likewise. * emultempl/beos.em: Likewise. * emultempl/elf-generic.em: Likewise. * emultempl/elf32.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/hppaelf.em: Likewise. * emultempl/irix.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68hc1xelf.em: Likewise. * emultempl/mmix-elfnmmo.em: Likewise. * emultempl/mmo.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/pep.em: Likewise. * emultempl/ppc32elf.em: Likewise. * emultempl/ppc64elf.em: Likewise. * emultempl/scoreelf.em: Likewise. * emultempl/sh64elf.em: Likewise. * emultempl/spuelf.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/vxworks.em: Likewise. * emultempl/xtensaelf.em: Likewise. * emultempl/z80.em: Likewise. * ldlang.c (open_output): Don't return output, instead write link_info_output_bfd directly. * emultempl/alphaelf.em: Replace occurrences of link_info.hash->creator with link_info.output_bfd->xvec. * emultempl/hppaelf.em: Likewise. * emultempl/ppc32elf.em: Likewise. * emultempl/ppc64elf.em: Likewise. * emultempl/spuelf.em: Likewise.
2008-02-15 04:35:53 +01:00
pe_data(link_info.output_bfd)->pe_opthdr = pe;
pe_data(link_info.output_bfd)->dll = init[DLLOFF].value;
1999-05-03 09:29:11 +02:00
}
/* Callback functions for qsort in sort_sections. */
static int
sort_by_file_name (const void *a, const void *b)
1999-05-03 09:29:11 +02:00
{
const lang_statement_union_type *const *ra = a;
const lang_statement_union_type *const *rb = b;
1999-05-03 09:29:11 +02:00
int i, a_sec, b_sec;
i = filename_cmp ((*ra)->input_section.section->owner->my_archive->filename,
(*rb)->input_section.section->owner->my_archive->filename);
1999-05-03 09:29:11 +02:00
if (i != 0)
return i;
i = filename_cmp ((*ra)->input_section.section->owner->filename,
(*rb)->input_section.section->owner->filename);
1999-05-03 09:29:11 +02:00
if (i != 0)
return i;
/* the tail idata4/5 are the only ones without relocs to an
idata$6 section unless we are importing by ordinal,
1999-05-03 09:29:11 +02:00
so sort them to last to terminate the IAT
and HNT properly. if no reloc this one is import by ordinal
so we have to sort by section contents */
if ( ((*ra)->input_section.section->reloc_count + (*rb)->input_section.section->reloc_count) )
{
i = (((*ra)->input_section.section->reloc_count >
1999-05-03 09:29:11 +02:00
(*rb)->input_section.section->reloc_count) ? -1 : 0);
if ( i != 0)
return i;
return (((*ra)->input_section.section->reloc_count >
1999-05-03 09:29:11 +02:00
(*rb)->input_section.section->reloc_count) ? 0 : 1);
}
else
{
if ( (strcmp( (*ra)->input_section.section->name, ".idata$6") == 0) )
return 0; /* don't sort .idata$6 or .idata$7 FIXME dlltool eliminate .idata$7 */
* ldlang.h (lang_input_section_type): Remove "ifile" field. (lang_insert_orphan, lang_add_section): Update prototypes. * ldlang.c (lang_insert_orphan): Remove "file" param. (lang_add_section): Likewise. Update all callers. (wild_sort): Get an input section's bfd via "section->owner". (size_input_section): Access just_syms_flag via bfd usrdata. (lang_place_orphans): Update ldemul_place_orphan call. * ldemul.h (ldemul_place_orphan): Remove input_statement param. (struct ld_emulation_xfer_struct <place_orphan>): Likewise. * ldemul.c (ldemul_place_orphan): Likewise. * ldwrite.c (build_link_order): Access just_syms_flag via bfd usrdata. * emultempl/armelf.em (arm_elf_set_bfd_for_interworking): Likewise. * emultempl/beos.em (sort_by_file_name): Access bfd by section->owner. (sort_sections): Likewise. (place_orphan): Remove "file" param. Adjust lang_add_section call. * emultempl/elf32.em (place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/hppaelf.em (hppaelf_add_stub_section): Adjust lang_add_section call. (build_section_lists): Access just_syms_flag via bfd usrdata. * emultempl/m68hc1xelf.em (m68hc11elf_add_stub_section): Adjust lang_add_section call. * emultempl/mmo.em (mmo_place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/pe.em (place_orphan): Likewise. Access bfd via section owner. * emultempl/ppc64elf.em (ppc_add_stub_section): Adjust lang_add_section call. (build_toc_list): Access just_syms_flag via bfd usrdata. (build_section_lists): Likewise. * emultempl/xtensaelf.em (elf_xtensa_place_orphan): Remove "file" param. Adjust place_orphan call. (ld_build_required_section_dependence): Access bfd via section owner.
2005-11-17 01:10:05 +01:00
if (! bfd_get_section_contents ((*ra)->input_section.section->owner,
1999-05-03 09:29:11 +02:00
(*ra)->input_section.section, &a_sec, (file_ptr) 0, (bfd_size_type)sizeof(a_sec)))
einfo ("%F%B: Can't read contents of section .idata: %E\n",
* ldlang.h (lang_input_section_type): Remove "ifile" field. (lang_insert_orphan, lang_add_section): Update prototypes. * ldlang.c (lang_insert_orphan): Remove "file" param. (lang_add_section): Likewise. Update all callers. (wild_sort): Get an input section's bfd via "section->owner". (size_input_section): Access just_syms_flag via bfd usrdata. (lang_place_orphans): Update ldemul_place_orphan call. * ldemul.h (ldemul_place_orphan): Remove input_statement param. (struct ld_emulation_xfer_struct <place_orphan>): Likewise. * ldemul.c (ldemul_place_orphan): Likewise. * ldwrite.c (build_link_order): Access just_syms_flag via bfd usrdata. * emultempl/armelf.em (arm_elf_set_bfd_for_interworking): Likewise. * emultempl/beos.em (sort_by_file_name): Access bfd by section->owner. (sort_sections): Likewise. (place_orphan): Remove "file" param. Adjust lang_add_section call. * emultempl/elf32.em (place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/hppaelf.em (hppaelf_add_stub_section): Adjust lang_add_section call. (build_section_lists): Access just_syms_flag via bfd usrdata. * emultempl/m68hc1xelf.em (m68hc11elf_add_stub_section): Adjust lang_add_section call. * emultempl/mmo.em (mmo_place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/pe.em (place_orphan): Likewise. Access bfd via section owner. * emultempl/ppc64elf.em (ppc_add_stub_section): Adjust lang_add_section call. (build_toc_list): Access just_syms_flag via bfd usrdata. (build_section_lists): Likewise. * emultempl/xtensaelf.em (elf_xtensa_place_orphan): Remove "file" param. Adjust place_orphan call. (ld_build_required_section_dependence): Access bfd via section owner.
2005-11-17 01:10:05 +01:00
(*ra)->input_section.section->owner);
1999-05-03 09:29:11 +02:00
* ldlang.h (lang_input_section_type): Remove "ifile" field. (lang_insert_orphan, lang_add_section): Update prototypes. * ldlang.c (lang_insert_orphan): Remove "file" param. (lang_add_section): Likewise. Update all callers. (wild_sort): Get an input section's bfd via "section->owner". (size_input_section): Access just_syms_flag via bfd usrdata. (lang_place_orphans): Update ldemul_place_orphan call. * ldemul.h (ldemul_place_orphan): Remove input_statement param. (struct ld_emulation_xfer_struct <place_orphan>): Likewise. * ldemul.c (ldemul_place_orphan): Likewise. * ldwrite.c (build_link_order): Access just_syms_flag via bfd usrdata. * emultempl/armelf.em (arm_elf_set_bfd_for_interworking): Likewise. * emultempl/beos.em (sort_by_file_name): Access bfd by section->owner. (sort_sections): Likewise. (place_orphan): Remove "file" param. Adjust lang_add_section call. * emultempl/elf32.em (place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/hppaelf.em (hppaelf_add_stub_section): Adjust lang_add_section call. (build_section_lists): Access just_syms_flag via bfd usrdata. * emultempl/m68hc1xelf.em (m68hc11elf_add_stub_section): Adjust lang_add_section call. * emultempl/mmo.em (mmo_place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/pe.em (place_orphan): Likewise. Access bfd via section owner. * emultempl/ppc64elf.em (ppc_add_stub_section): Adjust lang_add_section call. (build_toc_list): Access just_syms_flag via bfd usrdata. (build_section_lists): Likewise. * emultempl/xtensaelf.em (elf_xtensa_place_orphan): Remove "file" param. Adjust place_orphan call. (ld_build_required_section_dependence): Access bfd via section owner.
2005-11-17 01:10:05 +01:00
if (! bfd_get_section_contents ((*rb)->input_section.section->owner,
1999-05-03 09:29:11 +02:00
(*rb)->input_section.section, &b_sec, (file_ptr) 0, (bfd_size_type)sizeof(b_sec) ))
einfo ("%F%B: Can't read contents of section .idata: %E\n",
* ldlang.h (lang_input_section_type): Remove "ifile" field. (lang_insert_orphan, lang_add_section): Update prototypes. * ldlang.c (lang_insert_orphan): Remove "file" param. (lang_add_section): Likewise. Update all callers. (wild_sort): Get an input section's bfd via "section->owner". (size_input_section): Access just_syms_flag via bfd usrdata. (lang_place_orphans): Update ldemul_place_orphan call. * ldemul.h (ldemul_place_orphan): Remove input_statement param. (struct ld_emulation_xfer_struct <place_orphan>): Likewise. * ldemul.c (ldemul_place_orphan): Likewise. * ldwrite.c (build_link_order): Access just_syms_flag via bfd usrdata. * emultempl/armelf.em (arm_elf_set_bfd_for_interworking): Likewise. * emultempl/beos.em (sort_by_file_name): Access bfd by section->owner. (sort_sections): Likewise. (place_orphan): Remove "file" param. Adjust lang_add_section call. * emultempl/elf32.em (place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/hppaelf.em (hppaelf_add_stub_section): Adjust lang_add_section call. (build_section_lists): Access just_syms_flag via bfd usrdata. * emultempl/m68hc1xelf.em (m68hc11elf_add_stub_section): Adjust lang_add_section call. * emultempl/mmo.em (mmo_place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/pe.em (place_orphan): Likewise. Access bfd via section owner. * emultempl/ppc64elf.em (ppc_add_stub_section): Adjust lang_add_section call. (build_toc_list): Access just_syms_flag via bfd usrdata. (build_section_lists): Likewise. * emultempl/xtensaelf.em (elf_xtensa_place_orphan): Remove "file" param. Adjust place_orphan call. (ld_build_required_section_dependence): Access bfd via section owner.
2005-11-17 01:10:05 +01:00
(*rb)->input_section.section->owner);
1999-05-03 09:29:11 +02:00
i = ((a_sec < b_sec) ? -1 : 0);
if ( i != 0)
return i;
return ((a_sec < b_sec) ? 0 : 1);
}
return 0;
}
static int
sort_by_section_name (const void *a, const void *b)
1999-05-03 09:29:11 +02:00
{
const lang_statement_union_type *const *ra = a;
const lang_statement_union_type *const *rb = b;
1999-05-03 09:29:11 +02:00
int i;
i = strcmp ((*ra)->input_section.section->name,
(*rb)->input_section.section->name);
/* This is a hack to make .stab and .stabstr last, so we don't have
to fix strip/objcopy for .reloc sections.
FIXME stripping images with a .rsrc section still needs to be fixed. */
if (i != 0)
1999-05-03 09:29:11 +02:00
{
if ((CONST_STRNEQ ((*ra)->input_section.section->name, ".stab"))
&& (! CONST_STRNEQ ((*rb)->input_section.section->name, ".stab")))
1999-05-03 09:29:11 +02:00
return 1;
}
return i;
}
/* Subroutine of sort_sections to a contiguous subset of a list of sections.
NEXT_AFTER is the element after the last one to sort.
The result is a pointer to the last element's "next" pointer. */
static lang_statement_union_type **
sort_sections_1 (lang_statement_union_type **startptr,
lang_statement_union_type *next_after,
int count,
int (*sort_func) (const void *, const void *))
1999-05-03 09:29:11 +02:00
{
lang_statement_union_type **vec;
lang_statement_union_type *p;
int i;
lang_statement_union_type **ret;
if (count == 0)
return startptr;
vec = ((lang_statement_union_type **)
xmalloc (count * sizeof (lang_statement_union_type *)));
for (p = *startptr, i = 0; i < count; i++, p = p->header.next)
1999-05-03 09:29:11 +02:00
vec[i] = p;
qsort (vec, count, sizeof (vec[0]), sort_func);
/* Fill in the next pointers again. */
*startptr = vec[0];
for (i = 0; i < count - 1; i++)
vec[i]->header.next = vec[i + 1];
vec[i]->header.next = next_after;
ret = &vec[i]->header.next;
free (vec);
return ret;
}
/* Sort the .idata\$foo input sections of archives into filename order.
The reason is so dlltool can arrange to have the pe dll import information
generated correctly - the head of the list goes into dh.o, the tail into
dt.o, and the guts into ds[nnnn].o. Note that this is only needed for the
.idata section.
FIXME: This may no longer be necessary with grouped sections. Instead of
sorting on dh.o, ds[nnnn].o, dt.o, one could, for example, have dh.o use
.idata\$4h, have ds[nnnn].o use .idata\$4s[nnnn], and have dt.o use .idata\$4t.
This would have to be elaborated upon to handle multiple dll's
[assuming such an eloboration is possible of course].
We also sort sections in '\$' wild statements. These are created by the
place_orphans routine to implement grouped sections. */
static void
sort_sections (lang_statement_union_type *s)
1999-05-03 09:29:11 +02:00
{
for (; s ; s = s->header.next)
1999-05-03 09:29:11 +02:00
switch (s->header.type)
{
case lang_output_section_statement_enum:
sort_sections (s->output_section_statement.children.head);
break;
case lang_wild_statement_enum:
{
lang_statement_union_type **p = &s->wild_statement.children.head;
struct wildcard_list *sec;
1999-05-03 09:29:11 +02:00
for (sec = s->wild_statement.section_list; sec; sec = sec->next)
1999-05-03 09:29:11 +02:00
{
/* Is this the .idata section? */
if (sec->spec.name != NULL
&& CONST_STRNEQ (sec->spec.name, ".idata"))
1999-05-03 09:29:11 +02:00
{
/* Sort the children. We want to sort any objects in
the same archive. In order to handle the case of
including a single archive multiple times, we sort
all the children by archive name and then by object
name. After sorting them, we re-thread the pointer
chain. */
while (*p)
1999-05-03 09:29:11 +02:00
{
lang_statement_union_type *start = *p;
if (start->header.type != lang_input_section_enum
* ldlang.h (lang_input_section_type): Remove "ifile" field. (lang_insert_orphan, lang_add_section): Update prototypes. * ldlang.c (lang_insert_orphan): Remove "file" param. (lang_add_section): Likewise. Update all callers. (wild_sort): Get an input section's bfd via "section->owner". (size_input_section): Access just_syms_flag via bfd usrdata. (lang_place_orphans): Update ldemul_place_orphan call. * ldemul.h (ldemul_place_orphan): Remove input_statement param. (struct ld_emulation_xfer_struct <place_orphan>): Likewise. * ldemul.c (ldemul_place_orphan): Likewise. * ldwrite.c (build_link_order): Access just_syms_flag via bfd usrdata. * emultempl/armelf.em (arm_elf_set_bfd_for_interworking): Likewise. * emultempl/beos.em (sort_by_file_name): Access bfd by section->owner. (sort_sections): Likewise. (place_orphan): Remove "file" param. Adjust lang_add_section call. * emultempl/elf32.em (place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/hppaelf.em (hppaelf_add_stub_section): Adjust lang_add_section call. (build_section_lists): Access just_syms_flag via bfd usrdata. * emultempl/m68hc1xelf.em (m68hc11elf_add_stub_section): Adjust lang_add_section call. * emultempl/mmo.em (mmo_place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/pe.em (place_orphan): Likewise. Access bfd via section owner. * emultempl/ppc64elf.em (ppc_add_stub_section): Adjust lang_add_section call. (build_toc_list): Access just_syms_flag via bfd usrdata. (build_section_lists): Likewise. * emultempl/xtensaelf.em (elf_xtensa_place_orphan): Remove "file" param. Adjust place_orphan call. (ld_build_required_section_dependence): Access bfd via section owner.
2005-11-17 01:10:05 +01:00
|| !start->input_section.section->owner->my_archive)
p = &(start->header.next);
else
{
lang_statement_union_type *end;
int count;
for (end = start, count = 0;
end && (end->header.type
== lang_input_section_enum);
end = end->header.next)
count++;
p = sort_sections_1 (p, end, count,
sort_by_file_name);
}
1999-05-03 09:29:11 +02:00
}
break;
1999-05-03 09:29:11 +02:00
}
/* If this is a collection of grouped sections, sort them.
The linker script must explicitly mention "*(.foo\$)" or
"*(.foo\$*)". Don't sort them if \$ is not the last
character (not sure if this is really useful, but it
allows explicitly mentioning some \$ sections and letting
the linker handle the rest). */
if (sec->spec.name != NULL)
1999-05-03 09:29:11 +02:00
{
char *q = strchr (sec->spec.name, '\$');
1999-05-03 09:29:11 +02:00
if (q != NULL
&& (q[1] == '\0'
|| (q[1] == '*' && q[2] == '\0')))
1999-05-03 09:29:11 +02:00
{
lang_statement_union_type *end;
int count;
for (end = *p, count = 0; end; end = end->header.next)
{
if (end->header.type != lang_input_section_enum)
abort ();
count++;
}
(void) sort_sections_1 (p, end, count,
sort_by_section_name);
1999-05-03 09:29:11 +02:00
}
break;
1999-05-03 09:29:11 +02:00
}
}
}
break;
default:
break;
}
}
static void
gld_${EMULATION_NAME}_before_allocation (void)
1999-05-03 09:29:11 +02:00
{
#ifdef TARGET_IS_ppcpe
/* Here we rummage through the found bfds to collect toc information */
{
LANG_FOR_EACH_INPUT_STATEMENT (is)
{
if (!ppc_process_before_allocation(is->the_bfd, &link_info))
{
einfo("Errors encountered processing file %s\n", is->filename);
}
}
}
/* We have seen it all. Allocate it, and carry on */
ppc_allocate_toc_section (&link_info);
#else
#ifdef TARGET_IS_armpe
/* FIXME: we should be able to set the size of the interworking stub
section.
Here we rummage through the found bfds to collect glue
information. FIXME: should this be based on a command line
option? krk@cygnus.com */
{
LANG_FOR_EACH_INPUT_STATEMENT (is)
{
if (!arm_process_before_allocation (is->the_bfd, & link_info))
{
einfo ("Errors encountered processing file %s", is->filename);
}
}
}
/* We have seen it all. Allocate it, and carry on */
arm_allocate_interworking_sections (& link_info);
#endif /* TARGET_IS_armpe */
#endif /* TARGET_IS_ppcpe */
sort_sections (stat_ptr->head);
bfd/ * section.c (struct bfd_section): Replace link_order_head and link_order_tail with map_head and map_tail union. (STD_SECTION): Update. (_bfd_strip_section_from_output): Delete. * aoutx.h: Update throughout for above changes. * coff-ppc.c: Likewise. * cofflink.c: Likewise. * ecoff.c: Likewise. * elf-eh-frame.c: Likewise. * elf-m10300.c: Likewise. * elf.c: Likewise. * elf32-arm.c: Likewise. * elf32-cris.c: Likewise. * elf32-hppa.c: Likewise. * elf32-i386.c: Likewise. * elf32-m32r.c: Likewise. * elf32-m68hc1x.c: Likewise. * elf32-m68k.c: Likewise. * elf32-ppc.c: Likewise. * elf32-s390.c: Likewise. * elf32-sh.c: Likewise. * elf32-vax.c: Likewise. * elf32-xtensa.c: Likewise. * elf64-alpha.c: Likewise. * elf64-hppa.c: Likewise. * elf64-ppc.c: Likewise. * elf64-s390.c: Likewise. * elf64-sh64.c: Likewise. * elf64-x86-64.c: Likewise. * elflink.c: Likewise. * elfxx-ia64.c: Likewise. * elfxx-mips.c: Likewise. * elfxx-sparc.c: Likewise. * linker.c: Likewise. * merge.c: Likewise. * pdp11.c: Likewise. * xcofflink.c: Likewise. * elflink.c (bfd_boolean bfd_elf_size_dynsym_hash_dynstr): Split out from bfd_elf_size_dynamic_sections. * bfd-in.h (bfd_boolean bfd_elf_size_dynsym_hash_dynstr): Declare. * bfd-in2.h: Regenerate. ld/ * ldemul.c: Include bfdlink.h. (ldemul_before_allocation): Assume before_allocation is non-zero. (before_allocation_default): Call strip_excluded_output_sections. * ldlang.c (stripped_excluded_sections): New variable. (lang_add_section): Build input section list for each output section, attached via map_head and map_tail pointers. (strip_excluded_output_sections): Make global. Traverse the input section lists to find which output sections can go. Clear link_order pointers and set stripped_excluded_sections. (lang_process): Call strip_excluded_output_sections. * ldlang.h (strip_excluded_output_sections): Declare. * ldwrite.c: Update throuhout for link_order_head -> map_head change. * emultempl/aix.em (before_allocation): Call strip_excluded_output_sections. * emultempl/armcoff.em (before_allocation): Likewise. * emultempl/beos.em (before_allocation): Likewise. * emultempl/linux.em (before_allocation): Likewise. * emultempl/pe.em (before_allocation): Likewise. * emultempl/sunos.em (before_allocation): Likewise. * emultempl/elf32.em (before_allocation): Likewise. Call bfd_elf_size_dynsym_hash_dynstr too. * emultempl/lnk960.em (lnk960_before_allocation): Delete. (ld_lnk960): Use before_allocation_default.
2005-05-04 13:00:28 +02:00
before_allocation_default ();
1999-05-03 09:29:11 +02:00
}
/* Place an orphan section. We use this to put sections with a '\$' in them
into the right place. Any section with a '\$' in them (e.g. .text\$foo)
gets mapped to the output section with everything from the '\$' on stripped
(e.g. .text).
See the Microsoft Portable Executable and Common Object File Format
Specification 4.1, section 4.2, Grouped Sections.
FIXME: This is now handled by the linker script using wildcards,
but I'm leaving this here in case we want to enable it for sections
which are not mentioned in the linker script. */
static lang_output_section_statement_type *
gld${EMULATION_NAME}_place_orphan (asection *s,
const char *secname,
int constraint)
1999-05-03 09:29:11 +02:00
{
char *output_secname, *ps;
lang_output_section_statement_type *os;
lang_statement_union_type *l;
if ((s->flags & SEC_ALLOC) == 0)
return NULL;
1999-05-03 09:29:11 +02:00
/* Don't process grouped sections unless doing a final link.
If they're marked as COMDAT sections, we don't want .text\$foo to
end up in .text and then have .text disappear because it's marked
link-once-discard. */
2003-06-25 08:40:27 +02:00
if (link_info.relocatable)
return NULL;
1999-05-03 09:29:11 +02:00
/* Everything from the '\$' on gets deleted so don't allow '\$' as the
first character. */
if (*secname == '\$')
einfo ("%P%F: section %s has '\$' as first character\n", secname);
if (strchr (secname + 1, '\$') == NULL)
return NULL;
1999-05-03 09:29:11 +02:00
/* Look up the output section. The Microsoft specs say sections names in
image files never contain a '\$'. Fortunately, lang_..._lookup creates
the section if it doesn't exist. */
2001-05-02 20:14:31 +02:00
output_secname = xstrdup (secname);
1999-05-03 09:29:11 +02:00
ps = strchr (output_secname + 1, '\$');
*ps = 0;
os = lang_output_section_statement_lookup (output_secname, constraint, TRUE);
1999-05-03 09:29:11 +02:00
/* Find the '\$' wild statement for this section. We currently require the
linker script to explicitly mention "*(.foo\$)".
FIXME: ppcpe.sc has .CRT\$foo in the .rdata section. According to the
Microsoft docs this isn't correct so it's not (currently) handled. */
ps[0] = '\$';
ps[1] = 0;
for (l = os->children.head; l; l = l->header.next)
if (l->header.type == lang_wild_statement_enum)
{
struct wildcard_list *sec;
for (sec = l->wild_statement.section_list; sec; sec = sec->next)
if (sec->spec.name && strcmp (sec->spec.name, output_secname) == 0)
break;
if (sec)
break;
}
1999-05-03 09:29:11 +02:00
ps[0] = 0;
if (l == NULL)
einfo ("%P%F: *(%s\$) missing from linker script\n", output_secname);
/* Link the input section in and we're done for now.
The sections still have to be sorted, but that has to wait until
all such sections have been processed by us. The sorting is done by
sort_sections. */
* ldlang.h (lang_input_section_type): Remove "ifile" field. (lang_insert_orphan, lang_add_section): Update prototypes. * ldlang.c (lang_insert_orphan): Remove "file" param. (lang_add_section): Likewise. Update all callers. (wild_sort): Get an input section's bfd via "section->owner". (size_input_section): Access just_syms_flag via bfd usrdata. (lang_place_orphans): Update ldemul_place_orphan call. * ldemul.h (ldemul_place_orphan): Remove input_statement param. (struct ld_emulation_xfer_struct <place_orphan>): Likewise. * ldemul.c (ldemul_place_orphan): Likewise. * ldwrite.c (build_link_order): Access just_syms_flag via bfd usrdata. * emultempl/armelf.em (arm_elf_set_bfd_for_interworking): Likewise. * emultempl/beos.em (sort_by_file_name): Access bfd by section->owner. (sort_sections): Likewise. (place_orphan): Remove "file" param. Adjust lang_add_section call. * emultempl/elf32.em (place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/hppaelf.em (hppaelf_add_stub_section): Adjust lang_add_section call. (build_section_lists): Access just_syms_flag via bfd usrdata. * emultempl/m68hc1xelf.em (m68hc11elf_add_stub_section): Adjust lang_add_section call. * emultempl/mmo.em (mmo_place_orphan): Remove "file" param. Adjust lang_add_section and lang_insert_orphan calls. * emultempl/pe.em (place_orphan): Likewise. Access bfd via section owner. * emultempl/ppc64elf.em (ppc_add_stub_section): Adjust lang_add_section call. (build_toc_list): Access just_syms_flag via bfd usrdata. (build_section_lists): Likewise. * emultempl/xtensaelf.em (elf_xtensa_place_orphan): Remove "file" param. Adjust place_orphan call. (ld_build_required_section_dependence): Access bfd via section owner.
2005-11-17 01:10:05 +01:00
lang_add_section (&l->wild_statement.children, s, os);
1999-05-03 09:29:11 +02:00
return os;
1999-05-03 09:29:11 +02:00
}
static char *
gld_${EMULATION_NAME}_get_script (int *isfile)
1999-05-03 09:29:11 +02:00
EOF
# Scripts compiled in.
# sed commands to quote an ld script as a C string.
sc="-f stringify.sed"
1999-05-03 09:29:11 +02:00
2007-07-19 Roland McGrath <roland@redhat.com> * genscripts.sh (source_em, fragment): New sh functions. Truncate e${EMULATION_NAME}.c file before .em script fills it. Use source_em in place of . for the .em script. * emultempl/generic.em: Use fragment and source_em functions. * emultempl/aix.em: Likewise. * emultempl/alphaelf.em: Likewise. * emultempl/armcoff.em: Likewise. * emultempl/armelf.em: Likewise. * emultempl/avrelf.em: Likewise. * emultempl/beos.em: Likewise. * emultempl/cr16elf.em: Likewise. * emultempl/crxelf.em: Likewise. * emultempl/elf-generic.em: Likewise. * emultempl/elf32.em: Likewise. * emultempl/genelf.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/hppaelf.em: Likewise. * emultempl/ia64elf.em: Likewise. * emultempl/irix.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68hc1xelf.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/m68kelf.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/mipself.em: Likewise. * emultempl/mmix-elfnmmo.em: Likewise. * emultempl/mmixelf.em: Likewise. * emultempl/mmo.em: Likewise. * emultempl/needrelax.em: Likewise. * emultempl/netbsd.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/pep.em: Likewise. * emultempl/ppc32elf.em: Likewise. * emultempl/ppc64elf.em: Likewise. * emultempl/scoreelf.em: Likewise. * emultempl/sh64elf.em: Likewise. * emultempl/spuelf.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/vxworks.em: Likewise. * emultempl/xtensaelf.em: Likewise. * emultempl/z80.em: Likewise.
2007-07-19 21:56:10 +02:00
fragment <<EOF
{
1999-05-03 09:29:11 +02:00
*isfile = 0;
2003-06-25 08:40:27 +02:00
if (link_info.relocatable && config.build_constructors)
1999-05-03 09:29:11 +02:00
return
EOF
sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c
2003-06-25 08:40:27 +02:00
echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c
echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c
echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c
echo ' ; else return' >> e${EMULATION_NAME}.c
sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c
echo '; }' >> e${EMULATION_NAME}.c
1999-05-03 09:29:11 +02:00
2007-07-19 Roland McGrath <roland@redhat.com> * genscripts.sh (source_em, fragment): New sh functions. Truncate e${EMULATION_NAME}.c file before .em script fills it. Use source_em in place of . for the .em script. * emultempl/generic.em: Use fragment and source_em functions. * emultempl/aix.em: Likewise. * emultempl/alphaelf.em: Likewise. * emultempl/armcoff.em: Likewise. * emultempl/armelf.em: Likewise. * emultempl/avrelf.em: Likewise. * emultempl/beos.em: Likewise. * emultempl/cr16elf.em: Likewise. * emultempl/crxelf.em: Likewise. * emultempl/elf-generic.em: Likewise. * emultempl/elf32.em: Likewise. * emultempl/genelf.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/hppaelf.em: Likewise. * emultempl/ia64elf.em: Likewise. * emultempl/irix.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68hc1xelf.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/m68kelf.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/mipself.em: Likewise. * emultempl/mmix-elfnmmo.em: Likewise. * emultempl/mmixelf.em: Likewise. * emultempl/mmo.em: Likewise. * emultempl/needrelax.em: Likewise. * emultempl/netbsd.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/pep.em: Likewise. * emultempl/ppc32elf.em: Likewise. * emultempl/ppc64elf.em: Likewise. * emultempl/scoreelf.em: Likewise. * emultempl/sh64elf.em: Likewise. * emultempl/spuelf.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/vxworks.em: Likewise. * emultempl/xtensaelf.em: Likewise. * emultempl/z80.em: Likewise.
2007-07-19 21:56:10 +02:00
fragment <<EOF
1999-05-03 09:29:11 +02:00
struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
1999-05-03 09:29:11 +02:00
{
gld_${EMULATION_NAME}_before_parse,
syslib_default,
hll_default,
after_parse_default,
gld_${EMULATION_NAME}_after_open,
after_allocation_default,
set_output_arch_default,
ldemul_default_target,
gld_${EMULATION_NAME}_before_allocation,
gld_${EMULATION_NAME}_get_script,
"${EMULATION_NAME}",
"${OUTPUT_FORMAT}",
finish_default,
1999-05-03 09:29:11 +02:00
NULL, /* create output section statements */
NULL, /* open dynamic archive */
gld${EMULATION_NAME}_place_orphan,
gld_${EMULATION_NAME}_set_symbols,
* ldemul.c (ldemul_add_options, ldemul_handle_option): New functions. (ldemul_parse_args): Return bfd_boolean. Formatting. * ldemul.h (ldemul_add_options, ldemul_handle_option): Declare. (ldemul_parse_args): Adjust. (struct ld_emulation_xfer_struct): Add add_options and handle_option. Return bfd_boolean from parse_args. * lexsup.c (parse_args): Malloc shortopts, longopts and really_longopts. Call ldemul_add_options and ldemul_handle_option. * emultempl/aix.em (gld${EMULATION_NAME}_add_options): Split out from gld${EMULATION_NAME}_parse_args. (gld${EMULATION_NAME}_handle_option): Likewise. (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/armcoff.em: As for aix.em, but remove parse_args. * emultempl/beos.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/ticoff.em: Likewise. * emultempl/elf32.em: Likewise. Don't duplicate long options either. (gld${EMULATION_NAME}_add_sysroot): Prototype. * emultempl/armelf.em (PARSE_AND_LIST_LONGOPTS): Don't duplicate options. * emultempl/hppaelf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc32elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/ppc64elf.em (PARSE_AND_LIST_LONGOPTS): Likewise. * emultempl/armelf_oabi.em (ld_${EMULATION_NAME}_emulation): Adjust initializer. * emultempl/generic.em: Likewise. * emultempl/gld960.em: Likewise. * emultempl/gld960c.em: Likewise. * emultempl/linux.em: Likewise. * emultempl/lnk960.em: Likewise. * emultempl/m68kcoff.em: Likewise. * emultempl/mipsecoff.em: Likewise. * emultempl/sunos.em: Likewise. * emultempl/vanilla.em: Likewise. * emultempl/netbsd.em (gldnetbsd_before_parse): Prototype.
2003-02-28 02:32:31 +01:00
NULL, /* parse_args */
gld${EMULATION_NAME}_add_options,
gld${EMULATION_NAME}_handle_option,
NULL, /* unrecognized file */
NULL, /* list options */
NULL, /* recognized file */
NULL, /* find_potential_libraries */
NULL /* new_vers_pattern */
1999-05-03 09:29:11 +02:00
};
EOF