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