1130561Sobrien# This shell script emits a C file. -*- C -*-
2218822Sdim#   Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
3130561Sobrien#
4130561Sobrien# This file is part of GLD, the Gnu Linker.
5130561Sobrien#
6130561Sobrien# This program is free software; you can redistribute it and/or modify
7130561Sobrien# it under the terms of the GNU General Public License as published by
8130561Sobrien# the Free Software Foundation; either version 2 of the License, or
9130561Sobrien# (at your option) any later version.
10130561Sobrien#
11130561Sobrien# This program is distributed in the hope that it will be useful,
12130561Sobrien# but WITHOUT ANY WARRANTY; without even the implied warranty of
13130561Sobrien# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14130561Sobrien# GNU General Public License for more details.
15130561Sobrien#
16130561Sobrien# You should have received a copy of the GNU General Public License
17130561Sobrien# along with this program; if not, write to the Free Software
18218822Sdim# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
19130561Sobrien#
20130561Sobrien
21130561Sobrien# This file is sourced from elf32.em, and defines extra alpha
22130561Sobrien# specific routines.
23130561Sobrien#
24130561Sobriencat >>e${EMULATION_NAME}.c <<EOF
25130561Sobrien
26130561Sobrien#include "elf/internal.h"
27130561Sobrien#include "elf/alpha.h"
28130561Sobrien#include "elf-bfd.h"
29130561Sobrien
30218822Sdimstatic bfd_boolean limit_32bit;
31218822Sdimstatic bfd_boolean disable_relaxation;
32130561Sobrien
33218822Sdimextern bfd_boolean elf64_alpha_use_secureplt;
34218822Sdimextern const bfd_target bfd_elf64_alpha_vec;
35218822Sdimextern const bfd_target bfd_elf64_alpha_freebsd_vec;
36218822Sdim
37218822Sdim
38130561Sobrien/* Set the start address as in the Tru64 ld.  */
39130561Sobrien#define ALPHA_TEXT_START_32BIT 0x12000000
40130561Sobrien
41130561Sobrienstatic void
42218822Sdimalpha_after_open (void)
43218822Sdim{
44218822Sdim  if (link_info.hash->creator == &bfd_elf64_alpha_vec
45218822Sdim      || link_info.hash->creator == &bfd_elf64_alpha_freebsd_vec)
46218822Sdim    {
47218822Sdim      unsigned int num_plt;
48218822Sdim      lang_output_section_statement_type *os;
49218822Sdim      lang_output_section_statement_type *plt_os[2];
50218822Sdim
51218822Sdim      num_plt = 0;
52218822Sdim      for (os = &lang_output_section_statement.head->output_section_statement;
53218822Sdim	   os != NULL;
54218822Sdim	   os = os->next)
55218822Sdim	{
56218822Sdim	  if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
57218822Sdim	    {
58218822Sdim	      if (num_plt < 2)
59218822Sdim		plt_os[num_plt] = os;
60218822Sdim	      ++num_plt;
61218822Sdim	    }
62218822Sdim	}
63218822Sdim
64218822Sdim      if (num_plt == 2)
65218822Sdim	{
66218822Sdim	  plt_os[0]->constraint = elf64_alpha_use_secureplt ? 0 : -1;
67218822Sdim	  plt_os[1]->constraint = elf64_alpha_use_secureplt ? -1 : 0;
68218822Sdim	}
69218822Sdim    }
70218822Sdim
71218822Sdim  gld${EMULATION_NAME}_after_open ();
72218822Sdim}
73218822Sdim
74218822Sdimstatic void
75130561Sobrienalpha_after_parse (void)
76130561Sobrien{
77218822Sdim  if (limit_32bit && !link_info.shared && !link_info.relocatable)
78130561Sobrien    lang_section_start (".interp",
79130561Sobrien			exp_binop ('+',
80130561Sobrien				   exp_intop (ALPHA_TEXT_START_32BIT),
81218822Sdim				   exp_nameop (SIZEOF_HEADERS, NULL)),
82218822Sdim			NULL);
83130561Sobrien}
84130561Sobrien
85130561Sobrienstatic void
86218822Sdimalpha_before_allocation (void)
87218822Sdim{
88218822Sdim  /* Call main function; we're just extending it.  */
89218822Sdim  gld${EMULATION_NAME}_before_allocation ();
90218822Sdim
91218822Sdim  /* Add -relax if -O, not -r, and not explicitly disabled.  */
92218822Sdim  if (link_info.optimize && !link_info.relocatable && !disable_relaxation)
93218822Sdim    command_line.relax = TRUE;
94218822Sdim}
95218822Sdim
96218822Sdimstatic void
97130561Sobrienalpha_finish (void)
98130561Sobrien{
99218822Sdim  if (limit_32bit)
100130561Sobrien    elf_elfheader (output_bfd)->e_flags |= EF_ALPHA_32BIT;
101130561Sobrien
102130561Sobrien  gld${EMULATION_NAME}_finish ();
103130561Sobrien}
104130561SobrienEOF
105130561Sobrien
106130561Sobrien# Define some shell vars to insert bits of code into the standard elf
107130561Sobrien# parse_args and list_options functions.
108130561Sobrien#
109130561SobrienPARSE_AND_LIST_PROLOGUE='
110218822Sdim#define OPTION_TASO		300
111218822Sdim#define OPTION_NO_RELAX		(OPTION_TASO + 1)
112218822Sdim#define OPTION_SECUREPLT	(OPTION_NO_RELAX + 1)
113218822Sdim#define OPTION_NO_SECUREPLT	(OPTION_SECUREPLT + 1)
114130561Sobrien'
115130561Sobrien
116130561SobrienPARSE_AND_LIST_LONGOPTS='
117218822Sdim  { "taso", no_argument, NULL, OPTION_TASO },
118218822Sdim  { "no-relax", no_argument, NULL, OPTION_NO_RELAX },
119218822Sdim  { "secureplt", no_argument, NULL, OPTION_SECUREPLT },
120218822Sdim  { "no-secureplt", no_argument, NULL, OPTION_NO_SECUREPLT },
121130561Sobrien'
122130561Sobrien
123130561SobrienPARSE_AND_LIST_OPTIONS='
124218822Sdim  fprintf (file, _("\
125218822Sdim  --taso		Load executable in the lower 31-bit addressable\n\
126218822Sdim			virtual address range.\n\
127218822Sdim  --no-relax		Do not relax call and gp sequences.\n\
128218822Sdim  --secureplt		Force PLT in text segment.\n\
129218822Sdim  --no-secureplt	Force PLT in data segment.\n\
130218822Sdim"));
131130561Sobrien'
132130561Sobrien
133130561SobrienPARSE_AND_LIST_ARGS_CASES='
134130561Sobrien    case OPTION_TASO:
135218822Sdim      limit_32bit = 1;
136130561Sobrien      break;
137218822Sdim    case OPTION_NO_RELAX:
138218822Sdim      disable_relaxation = TRUE;
139218822Sdim      break;
140218822Sdim    case OPTION_SECUREPLT:
141218822Sdim      elf64_alpha_use_secureplt = TRUE;
142218822Sdim      break;
143218822Sdim    case OPTION_NO_SECUREPLT:
144218822Sdim      elf64_alpha_use_secureplt = FALSE;
145218822Sdim      break;
146130561Sobrien'
147130561Sobrien
148130561Sobrien# Put these extra alpha routines in ld_${EMULATION_NAME}_emulation
149130561Sobrien#
150218822SdimLDEMUL_AFTER_OPEN=alpha_after_open
151130561SobrienLDEMUL_AFTER_PARSE=alpha_after_parse
152218822SdimLDEMUL_BEFORE_ALLOCATION=alpha_before_allocation
153130561SobrienLDEMUL_FINISH=alpha_finish
154