Fix fallout from splitting ldbuildid.[ch] off elf32.em.
[platform/upstream/binutils.git] / ld / emultempl / alphaelf.em
1 # This shell script emits a C file. -*- C -*-
2 #   Copyright (C) 2003-2014 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21
22 # This file is sourced from elf32.em, and defines extra alpha
23 # specific routines.
24 #
25 fragment <<EOF
26
27 #include "elf/internal.h"
28 #include "elf/alpha.h"
29 #include "elf-bfd.h"
30
31 static bfd_boolean limit_32bit;
32
33 extern bfd_boolean elf64_alpha_use_secureplt;
34
35
36 /* Set the start address as in the Tru64 ld.  */
37 #define ALPHA_TEXT_START_32BIT 0x12000000
38
39 static void
40 alpha_after_open (void)
41 {
42   if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
43       && elf_object_id (link_info.output_bfd) == ALPHA_ELF_DATA)
44     {
45       unsigned int num_plt;
46       lang_output_section_statement_type *os;
47       lang_output_section_statement_type *plt_os[2];
48
49       num_plt = 0;
50       for (os = &lang_output_section_statement.head->output_section_statement;
51            os != NULL;
52            os = os->next)
53         {
54           if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
55             {
56               if (num_plt < 2)
57                 plt_os[num_plt] = os;
58               ++num_plt;
59             }
60         }
61
62       if (num_plt == 2)
63         {
64           plt_os[0]->constraint = elf64_alpha_use_secureplt ? 0 : -1;
65           plt_os[1]->constraint = elf64_alpha_use_secureplt ? -1 : 0;
66         }
67     }
68
69   gld${EMULATION_NAME}_after_open ();
70 }
71
72 static void
73 alpha_after_parse (void)
74 {
75   if (limit_32bit && !link_info.shared && !link_info.relocatable)
76     lang_section_start (".interp",
77                         exp_binop ('+',
78                                    exp_intop (ALPHA_TEXT_START_32BIT),
79                                    exp_nameop (SIZEOF_HEADERS, NULL)),
80                         NULL);
81
82   after_parse_default ();
83 }
84
85 static void
86 alpha_before_allocation (void)
87 {
88   /* Call main function; we're just extending it.  */
89   gld${EMULATION_NAME}_before_allocation ();
90
91   /* Add -relax if -O, not -r, and not explicitly disabled.  */
92   if (link_info.optimize && !link_info.relocatable && ! RELAXATION_DISABLED_BY_USER)
93     ENABLE_RELAXATION;
94 }
95
96 static void
97 alpha_finish (void)
98 {
99   if (limit_32bit)
100     elf_elfheader (link_info.output_bfd)->e_flags |= EF_ALPHA_32BIT;
101
102   finish_default ();
103 }
104 EOF
105
106 # Define some shell vars to insert bits of code into the standard elf
107 # parse_args and list_options functions.
108 #
109 PARSE_AND_LIST_PROLOGUE='
110 #define OPTION_TASO             300
111 #define OPTION_SECUREPLT        (OPTION_TASO + 1)
112 #define OPTION_NO_SECUREPLT     (OPTION_SECUREPLT + 1)
113 '
114
115 PARSE_AND_LIST_LONGOPTS='
116   { "taso", no_argument, NULL, OPTION_TASO },
117   { "secureplt", no_argument, NULL, OPTION_SECUREPLT },
118   { "no-secureplt", no_argument, NULL, OPTION_NO_SECUREPLT },
119 '
120
121 PARSE_AND_LIST_OPTIONS='
122   fprintf (file, _("\
123   --taso                      Load executable in the lower 31-bit addressable\n\
124                                 virtual address range.\n\
125   --secureplt                 Force PLT in text segment.\n\
126   --no-secureplt              Force PLT in data segment.\n\
127 "));
128 '
129
130 PARSE_AND_LIST_ARGS_CASES='
131     case OPTION_TASO:
132       limit_32bit = 1;
133       break;
134     case OPTION_SECUREPLT:
135       elf64_alpha_use_secureplt = TRUE;
136       break;
137     case OPTION_NO_SECUREPLT:
138       elf64_alpha_use_secureplt = FALSE;
139       break;
140 '
141
142 # Put these extra alpha routines in ld_${EMULATION_NAME}_emulation
143 #
144 LDEMUL_AFTER_OPEN=alpha_after_open
145 LDEMUL_AFTER_PARSE=alpha_after_parse
146 LDEMUL_BEFORE_ALLOCATION=alpha_before_allocation
147 LDEMUL_FINISH=alpha_finish