]>
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} | |
250d07de | 12 | Copyright (C) 2010-2021 Free Software Foundation, Inc. |
a6cc6b3b RO |
13 | Written by Rainer Orth <[email protected]> |
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 | 37 | |
c5bdb022 L |
38 | The Solaris 2 ABI also requires two local symbols to be emitted for |
39 | every executable and shared object. | |
40 | ||
a6cc6b3b RO |
41 | Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output |
42 | File, p.63. */ | |
c5bdb022 | 43 | |
a6cc6b3b RO |
44 | static void |
45 | elf_solaris2_before_allocation (void) | |
46 | { | |
18a1a992 RO |
47 | /* Global symbols required by the Solaris 2 ABI. */ |
48 | static const char *global_syms[] = { | |
a6cc6b3b RO |
49 | "_DYNAMIC", |
50 | "_GLOBAL_OFFSET_TABLE_", | |
51 | "_PROCEDURE_LINKAGE_TABLE_", | |
52 | "_edata", | |
53 | "_end", | |
54 | "_etext", | |
55 | NULL | |
56 | }; | |
c5bdb022 L |
57 | /* Local symbols required by the Solaris 2 ABI. Already emitted by |
58 | emulparams/solaris2.sh. */ | |
59 | static const char *local_syms[] = { | |
60 | "_START_", | |
61 | "_END_", | |
62 | NULL | |
63 | }; | |
a6cc6b3b RO |
64 | const char **sym; |
65 | ||
18a1a992 | 66 | /* Do this for both executables and shared objects. */ |
0e1862bb | 67 | if (!bfd_link_relocatable (&link_info)) |
18a1a992 RO |
68 | { |
69 | for (sym = global_syms; *sym != NULL; sym++) | |
70 | { | |
71 | struct elf_link_hash_entry *h; | |
72 | ||
73 | /* Lookup symbol. */ | |
74 | h = elf_link_hash_lookup (elf_hash_table (&link_info), *sym, | |
f38a2680 | 75 | false, false, false); |
18a1a992 RO |
76 | if (h == NULL) |
77 | continue; | |
78 | ||
79 | /* Undo the hiding done by _bfd_elf_define_linkage_sym. */ | |
80 | h->forced_local = 0; | |
81 | h->other &= ~STV_HIDDEN; | |
82 | ||
83 | /* Emit it into the .dynamic section, too. */ | |
84 | bfd_elf_link_record_dynamic_symbol (&link_info, h); | |
85 | } | |
c5bdb022 L |
86 | |
87 | for (sym = local_syms; *sym != NULL; sym++) | |
88 | { | |
89 | struct elf_link_hash_entry *h; | |
90 | ||
91 | /* Lookup symbol. */ | |
92 | h = elf_link_hash_lookup (elf_hash_table (&link_info), *sym, | |
f38a2680 | 93 | false, false, false); |
c5bdb022 L |
94 | if (h == NULL) |
95 | continue; | |
96 | ||
97 | /* Turn it local. */ | |
98 | h->forced_local = 1; | |
99 | /* Type should be STT_OBJECT, not STT_NOTYPE. */ | |
100 | h->type = STT_OBJECT; | |
101 | } | |
18a1a992 RO |
102 | } |
103 | ||
a6cc6b3b | 104 | /* Only do this if emitting a shared object and versioning is in place. */ |
0e1862bb | 105 | if (bfd_link_dll (&link_info) |
1a792e1c MR |
106 | && ((link_info.version_info != NULL |
107 | && link_info.version_info->name[0] != '\0') | |
fd91d419 | 108 | || link_info.create_default_symver)) |
a6cc6b3b RO |
109 | { |
110 | struct bfd_elf_version_expr *globals = NULL, *locals = NULL; | |
111 | struct bfd_elf_version_tree *basever; | |
112 | const char *soname; | |
113 | ||
18a1a992 | 114 | for (sym = global_syms; *sym != NULL; sym++) |
a6cc6b3b RO |
115 | { |
116 | /* Create a version pattern for this symbol. Some of them start | |
117 | off as local, others as global, so try both. */ | |
f38a2680 AM |
118 | globals = lang_new_vers_pattern (globals, *sym, NULL, true); |
119 | locals = lang_new_vers_pattern (locals, *sym, NULL, true); | |
a6cc6b3b RO |
120 | } |
121 | ||
122 | /* New version node for those symbols. */ | |
123 | basever = lang_new_vers_node (globals, locals); | |
124 | ||
125 | /* The version name matches what bfd_elf_size_dynamic_sections uses | |
126 | for the base version. */ | |
127 | soname = bfd_elf_get_dt_soname (link_info.output_bfd); | |
128 | if (soname == NULL) | |
129 | soname = lbasename (bfd_get_filename (link_info.output_bfd)); | |
130 | ||
131 | /* Register the node. */ | |
132 | lang_register_vers_node (soname, basever, NULL); | |
133 | /* Enforce base version. The encoded vd_ndx is vernum + 1. */ | |
134 | basever->vernum = 0; | |
18a1a992 | 135 | } |
a6cc6b3b | 136 | |
18a1a992 RO |
137 | gld${EMULATION_NAME}_before_allocation (); |
138 | } | |
139 | ||
a6cc6b3b RO |
140 | EOF |
141 | ||
142 | LDEMUL_BEFORE_ALLOCATION=elf_solaris2_before_allocation |