# This shell script emits a C file. -*- C -*-
# Copyright 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
#
# This file is part of GLD, the Gnu Linker.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# This file is sourced from elf32.em and mmo.em, used to define
# linker MMIX-specifics common to ELF and MMO.
cat >>e${EMULATION_NAME}.c <<EOF
#define gldmmo_before_allocation before_allocation_default
EOF
. ${srcdir}/emultempl/mmix-elfnmmo.em
cat >>e${EMULATION_NAME}.c <<EOF
static bfd_boolean
mmo_place_orphan (lang_input_statement_type *file, asection *s)
{
static struct orphan_save hold_text =
{
MMO_TEXT_SECTION_NAME,
SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE,
0, 0, 0, 0
};
struct orphan_save *place;
const char *secname;
lang_output_section_statement_type *after;
lang_output_section_statement_type *os;
if (link_info.relocatable
|| (s->flags & (SEC_EXCLUDE | SEC_LOAD)) != SEC_LOAD)
return FALSE;
secname = s->name;
os = lang_output_section_find (secname);
if (os != NULL)
{
lang_add_section (&os->children, s, os, file);
return TRUE;
}
if ((s->flags & (SEC_CODE | SEC_READONLY)) == 0)
return FALSE;
if (hold_text.os == NULL)
hold_text.os = lang_output_section_find (hold_text.name);
place = &hold_text;
if (hold_text.os != NULL)
after = hold_text.os;
else
after = &lang_output_section_statement.head->output_section_statement;
os = lang_insert_orphan (file, s, secname, after, place, NULL, NULL);
if (hold_text.os == NULL)
hold_text.os = os;
return TRUE;
}
static void
mmo_wipe_sec_reloc_flag (bfd *abfd, asection *sec, void *ptr ATTRIBUTE_UNUSED)
{
bfd_set_section_flags (abfd, sec,
bfd_get_section_flags (abfd, sec) & ~SEC_RELOC);
}
static void
mmo_finish (void)
{
bfd_map_over_sections (output_bfd, mmo_wipe_sec_reloc_flag, NULL);
}
static void
mmo_after_open (void)
{
if (bfd_get_flavour (output_bfd) != bfd_target_elf_flavour)
{
LANG_FOR_EACH_INPUT_STATEMENT (is)
{
if (bfd_get_flavour (is->the_bfd) == bfd_target_elf_flavour
&& !_bfd_mmix_check_all_relocs (is->the_bfd, &link_info))
einfo ("%X%P: Internal problems scanning %B after opening it",
is->the_bfd);
}
}
}
EOF
LDEMUL_PLACE_ORPHAN=mmo_place_orphan
LDEMUL_FINISH=mmo_finish
LDEMUL_AFTER_OPEN=mmo_after_open