Commit | Line | Data |
---|---|---|
a6cc6b3b RO |
1 | # This shell script emits a C file. -*- C -*- |
2 | # It does some substitutions. | |
3 | if [ -z "$MACHINE" ]; then | |
4 | OUTPUT_ARCH=${ARCH} | |
5 | else | |
6 | OUTPUT_ARCH=${ARCH}:${MACHINE} | |
7 | fi | |
8 | fragment <<EOF | |
9 | /* This file is generated by a shell script. DO NOT EDIT! */ | |
10 | ||
11 | /* Solaris 2 emulation code for ${EMULATION_NAME} | |
12 | Copyright 2010 Free Software Foundation, Inc. | |
13 | Written by Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> | |
14 | ||
15 | This file is part of the GNU Binutils. | |
16 | ||
17 | This program is free software; you can redistribute it and/or modify | |
18 | it under the terms of the GNU General Public License as published by | |
19 | the Free Software Foundation; either version 3 of the License, or | |
20 | (at your option) any later version. | |
21 | ||
22 | This program is distributed in the hope that it will be useful, | |
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | GNU General Public License for more details. | |
26 | ||
27 | You should have received a copy of the GNU General Public License | |
28 | along with this program; if not, write to the Free Software | |
29 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
30 | MA 02110-1301, USA. */ | |
31 | ||
32 | #define TARGET_IS_${EMULATION_NAME} | |
33 | ||
18a1a992 RO |
34 | /* The Solaris 2 ABI requires some global symbols to be present in the |
35 | .dynsym table of executables and shared objects. If generating a | |
36 | versioned shared object, they must always be bound to the base version. | |
a6cc6b3b RO |
37 | |
38 | Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output | |
39 | File, p.63. */ | |
40 | static void | |
41 | elf_solaris2_before_allocation (void) | |
42 | { | |
18a1a992 RO |
43 | /* Global symbols required by the Solaris 2 ABI. */ |
44 | static const char *global_syms[] = { | |
a6cc6b3b RO |
45 | "_DYNAMIC", |
46 | "_GLOBAL_OFFSET_TABLE_", | |
47 | "_PROCEDURE_LINKAGE_TABLE_", | |
48 | "_edata", | |
49 | "_end", | |
50 | "_etext", | |
51 | NULL | |
52 | }; | |
53 | const char **sym; | |
54 | ||
18a1a992 RO |
55 | /* Do this for both executables and shared objects. */ |
56 | if (!link_info.relocatable) | |
57 | { | |
58 | for (sym = global_syms; *sym != NULL; sym++) | |
59 | { | |
60 | struct elf_link_hash_entry *h; | |
61 | ||
62 | /* Lookup symbol. */ | |
63 | h = elf_link_hash_lookup (elf_hash_table (&link_info), *sym, | |
64 | FALSE, FALSE, FALSE); | |
65 | if (h == NULL) | |
66 | continue; | |
67 | ||
68 | /* Undo the hiding done by _bfd_elf_define_linkage_sym. */ | |
69 | h->forced_local = 0; | |
70 | h->other &= ~STV_HIDDEN; | |
71 | ||
72 | /* Emit it into the .dynamic section, too. */ | |
73 | bfd_elf_link_record_dynamic_symbol (&link_info, h); | |
74 | } | |
75 | } | |
76 | ||
a6cc6b3b RO |
77 | /* Only do this if emitting a shared object and versioning is in place. */ |
78 | if (link_info.shared | |
79 | && (lang_elf_version_info != NULL || link_info.create_default_symver)) | |
80 | { | |
81 | struct bfd_elf_version_expr *globals = NULL, *locals = NULL; | |
82 | struct bfd_elf_version_tree *basever; | |
83 | const char *soname; | |
84 | ||
18a1a992 | 85 | for (sym = global_syms; *sym != NULL; sym++) |
a6cc6b3b RO |
86 | { |
87 | /* Create a version pattern for this symbol. Some of them start | |
88 | off as local, others as global, so try both. */ | |
89 | globals = lang_new_vers_pattern (globals, *sym, NULL, TRUE); | |
90 | locals = lang_new_vers_pattern (locals, *sym, NULL, TRUE); | |
91 | } | |
92 | ||
93 | /* New version node for those symbols. */ | |
94 | basever = lang_new_vers_node (globals, locals); | |
95 | ||
96 | /* The version name matches what bfd_elf_size_dynamic_sections uses | |
97 | for the base version. */ | |
98 | soname = bfd_elf_get_dt_soname (link_info.output_bfd); | |
99 | if (soname == NULL) | |
100 | soname = lbasename (bfd_get_filename (link_info.output_bfd)); | |
101 | ||
102 | /* Register the node. */ | |
103 | lang_register_vers_node (soname, basever, NULL); | |
104 | /* Enforce base version. The encoded vd_ndx is vernum + 1. */ | |
105 | basever->vernum = 0; | |
18a1a992 | 106 | } |
a6cc6b3b | 107 | |
18a1a992 RO |
108 | gld${EMULATION_NAME}_before_allocation (); |
109 | } | |
110 | ||
111 | /* The Solaris 2 ABI requires two local symbols to be emitted for every | |
112 | executable and shared object. | |
113 | ||
114 | Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output | |
115 | File, p.63. */ | |
116 | static void | |
117 | elf_solaris2_after_allocation (void) | |
118 | { | |
119 | /* Local symbols required by the Solaris 2 ABI. Already emitted by | |
120 | emulparams/solaris2.sh. */ | |
121 | static const char *local_syms[] = { | |
122 | "_START_", | |
123 | "_END_", | |
124 | NULL | |
125 | }; | |
126 | const char **sym; | |
127 | ||
128 | /* Do this for both executables and shared objects. */ | |
129 | if (!link_info.relocatable) | |
130 | { | |
131 | for (sym = local_syms; *sym != NULL; sym++) | |
a6cc6b3b RO |
132 | { |
133 | struct elf_link_hash_entry *h; | |
134 | ||
135 | /* Lookup symbol. */ | |
136 | h = elf_link_hash_lookup (elf_hash_table (&link_info), *sym, | |
137 | FALSE, FALSE, FALSE); | |
138 | if (h == NULL) | |
139 | continue; | |
140 | ||
18a1a992 RO |
141 | /* Turn it local. */ |
142 | h->forced_local = 1; | |
143 | /* Type should be STT_OBJECT, not STT_NOTYPE. */ | |
144 | h->type = STT_OBJECT; | |
a6cc6b3b RO |
145 | } |
146 | } | |
147 | ||
18a1a992 | 148 | gld${EMULATION_NAME}_after_allocation (); |
a6cc6b3b RO |
149 | } |
150 | ||
151 | EOF | |
152 | ||
153 | LDEMUL_BEFORE_ALLOCATION=elf_solaris2_before_allocation | |
18a1a992 | 154 | LDEMUL_AFTER_ALLOCATION=elf_solaris2_after_allocation |