OSDN Git Service

Update FSF addresses
[pf3gnuchains/pf3gnuchains4x.git] / ld / emultempl / ppc32elf.em
1 # This shell script emits a C file. -*- C -*-
2 #   Copyright 2003, 2005 Free Software Foundation, Inc.
3 #
4 # This file is part of GLD, the Gnu Linker.
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 2 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, MA 02110-1301, USA.
19 #
20
21 # This file is sourced from elf32.em, and defines extra powerpc32-elf
22 # specific routines.
23 #
24 cat >>e${EMULATION_NAME}.c <<EOF
25
26 #include "libbfd.h"
27 #include "elf32-ppc.h"
28
29 extern const bfd_target bfd_elf32_powerpc_vec;
30 extern const bfd_target bfd_elf32_powerpcle_vec;
31
32 /* Whether to run tls optimization.  */
33 static int notlsopt = 0;
34
35 /* Chooses the correct place for .plt and .got.  */
36 static int old_plt = 0;
37 static int old_got = 0;
38
39 static void
40 ppc_after_open (void)
41 {
42   if (link_info.hash->creator == &bfd_elf32_powerpc_vec
43       || link_info.hash->creator == &bfd_elf32_powerpcle_vec)
44     {
45       int new_plt;
46       int keep_new;
47       unsigned int num_plt;
48       unsigned int num_got;
49       lang_output_section_statement_type *os;
50       lang_output_section_statement_type *plt_os[2];
51       lang_output_section_statement_type *got_os[2];
52
53       new_plt = ppc_elf_select_plt_layout (output_bfd, &link_info, old_plt);
54       if (new_plt < 0)
55         einfo ("%X%P: select_plt_layout problem %E\n");
56
57       num_got = 0;
58       num_plt = 0;
59       for (os = &lang_output_section_statement.head->output_section_statement;
60            os != NULL;
61            os = os->next)
62         {
63           if (os->constraint == SPECIAL && strcmp (os->name, ".plt") == 0)
64             {
65               if (num_plt < 2)
66                 plt_os[num_plt] = os;
67               ++num_plt;
68             }
69           if (os->constraint == SPECIAL && strcmp (os->name, ".got") == 0)
70             {
71               if (num_got < 2)
72                 got_os[num_got] = os;
73               ++num_got;
74             }
75         }
76
77       keep_new = new_plt == 1 ? 0 : -1;
78       if (num_plt == 2)
79         {
80           plt_os[0]->constraint = keep_new;
81           plt_os[1]->constraint = ~keep_new;
82         }
83       if (num_got == 2)
84         {
85           if (old_got)
86             keep_new = -1;
87           got_os[0]->constraint = keep_new;
88           got_os[1]->constraint = ~keep_new;
89         }
90     }
91
92   gld${EMULATION_NAME}_after_open ();
93 }
94
95 static void
96 ppc_before_allocation (void)
97 {
98   if (link_info.hash->creator == &bfd_elf32_powerpc_vec
99       || link_info.hash->creator == &bfd_elf32_powerpcle_vec)
100     {
101       if (ppc_elf_tls_setup (output_bfd, &link_info) && !notlsopt)
102         {
103           if (!ppc_elf_tls_optimize (output_bfd, &link_info))
104             {
105               einfo ("%X%P: TLS problem %E\n");
106               return;
107             }
108         }
109     }
110   gld${EMULATION_NAME}_before_allocation ();
111 }
112
113 static void
114 gld${EMULATION_NAME}_after_allocation (void)
115 {
116   if (link_info.hash->creator == &bfd_elf32_powerpc_vec
117       || link_info.hash->creator == &bfd_elf32_powerpcle_vec)
118     {
119       if (!ppc_elf_set_sdata_syms (output_bfd, &link_info))
120         einfo ("%X%P: cannot set sdata syms %E\n");
121     }
122 }
123
124 EOF
125
126 # Define some shell vars to insert bits of code into the standard elf
127 # parse_args and list_options functions.
128 #
129 PARSE_AND_LIST_PROLOGUE='
130 #define OPTION_NO_TLS_OPT               301
131 #define OPTION_OLD_PLT                  302
132 #define OPTION_OLD_GOT                  303
133 '
134
135 PARSE_AND_LIST_LONGOPTS='
136   { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
137   { "bss-plt", no_argument, NULL, OPTION_OLD_PLT },
138   { "sdata-got", no_argument, NULL, OPTION_OLD_GOT },
139 '
140
141 PARSE_AND_LIST_OPTIONS='
142   fprintf (file, _("\
143   --no-tls-optimize     Don'\''t try to optimize TLS accesses.\n\
144   --bss-plt             Force old-style BSS PLT.\n\
145   --sdata-got           Force GOT location just before .sdata.\n"
146                    ));
147 '
148
149 PARSE_AND_LIST_ARGS_CASES='
150     case OPTION_NO_TLS_OPT:
151       notlsopt = 1;
152       break;
153
154     case OPTION_OLD_PLT:
155       old_plt = 1;
156       break;
157
158     case OPTION_OLD_GOT:
159       old_got = 1;
160       break;
161 '
162
163 # Put these extra ppc32elf routines in ld_${EMULATION_NAME}_emulation
164 #
165 LDEMUL_AFTER_OPEN=ppc_after_open
166 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
167 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation