obj-macho.c revision 1.1.1.5 1 1.1 christos /* Mach-O object file format
2 1.1.1.5 christos Copyright (C) 2009-2018 Free Software Foundation, Inc.
3 1.1 christos
4 1.1 christos This file is part of GAS, the GNU Assembler.
5 1.1 christos
6 1.1 christos GAS is free software; you can redistribute it and/or modify
7 1.1 christos it under the terms of the GNU General Public License as
8 1.1 christos published by the Free Software Foundation; either version 3,
9 1.1 christos or (at your option) any later version.
10 1.1 christos
11 1.1 christos GAS is distributed in the hope that it will be useful, but
12 1.1 christos WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 1.1 christos the GNU General Public License for more details.
15 1.1 christos
16 1.1 christos You should have received a copy of the GNU General Public License
17 1.1 christos along with GAS; see the file COPYING. If not, write to the Free
18 1.1 christos Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 1.1 christos 02110-1301, USA. */
20 1.1 christos
21 1.1.1.2 christos /* Here we handle the mach-o directives that are common to all architectures.
22 1.1.1.2 christos
23 1.1.1.2 christos Most significant are mach-o named sections and a variety of symbol type
24 1.1.1.2 christos decorations. */
25 1.1.1.2 christos
26 1.1.1.2 christos /* Mach-O supports multiple, named segments each of which may contain
27 1.1.1.3 christos multiple named sections. Thus the concept of subsectioning is
28 1.1.1.2 christos handled by (say) having a __TEXT segment with appropriate flags from
29 1.1.1.3 christos which subsections are generated like __text, __const etc.
30 1.1.1.3 christos
31 1.1.1.2 christos The well-known as short-hand section switch directives like .text, .data
32 1.1.1.5 christos etc. are mapped onto predefined segment/section pairs using facilities
33 1.1.1.2 christos supplied by the mach-o port of bfd.
34 1.1.1.3 christos
35 1.1.1.2 christos A number of additional mach-o short-hand section switch directives are
36 1.1.1.2 christos also defined. */
37 1.1.1.2 christos
38 1.1 christos #define OBJ_HEADER "obj-macho.h"
39 1.1 christos
40 1.1 christos #include "as.h"
41 1.1.1.2 christos #include "subsegs.h"
42 1.1.1.2 christos #include "symbols.h"
43 1.1.1.2 christos #include "write.h"
44 1.1 christos #include "mach-o.h"
45 1.1.1.2 christos #include "mach-o/loader.h"
46 1.1.1.2 christos #include "obj-macho.h"
47 1.1.1.2 christos
48 1.1.1.2 christos #include <string.h>
49 1.1.1.2 christos
50 1.1.1.2 christos /* Forward decls. */
51 1.1.1.2 christos static segT obj_mach_o_segT_from_bfd_name (const char *, int);
52 1.1.1.2 christos
53 1.1.1.2 christos /* TODO: Implement "-dynamic"/"-static" command line options. */
54 1.1.1.2 christos
55 1.1.1.2 christos static int obj_mach_o_is_static;
56 1.1.1.2 christos
57 1.1.1.2 christos /* TODO: Implement the "-n" command line option to suppress the initial
58 1.1.1.2 christos switch to the text segment. */
59 1.1.1.2 christos
60 1.1.1.2 christos static int obj_mach_o_start_with_text_section = 1;
61 1.1.1.2 christos
62 1.1.1.2 christos /* Allow for special re-ordering on output. */
63 1.1.1.2 christos
64 1.1.1.2 christos static int obj_mach_o_seen_objc_section;
65 1.1.1.2 christos
66 1.1.1.2 christos /* Start-up: At present, just create the sections we want. */
67 1.1.1.2 christos void
68 1.1.1.2 christos mach_o_begin (void)
69 1.1.1.2 christos {
70 1.1.1.2 christos /* Mach-O only defines the .text section by default, and even this can
71 1.1.1.2 christos be suppressed by a flag. In the latter event, the first code MUST
72 1.1.1.2 christos be a section definition. */
73 1.1.1.2 christos if (obj_mach_o_start_with_text_section)
74 1.1.1.2 christos {
75 1.1.1.2 christos text_section = obj_mach_o_segT_from_bfd_name (TEXT_SECTION_NAME, 1);
76 1.1.1.2 christos subseg_set (text_section, 0);
77 1.1.1.2 christos if (obj_mach_o_is_static)
78 1.1.1.2 christos {
79 1.1.1.3 christos bfd_mach_o_section *mo_sec
80 1.1.1.2 christos = bfd_mach_o_get_mach_o_section (text_section);
81 1.1.1.2 christos mo_sec->flags &= ~BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS;
82 1.1.1.2 christos }
83 1.1.1.2 christos }
84 1.1.1.2 christos }
85 1.1.1.2 christos
86 1.1.1.2 christos /* Remember the subsections_by_symbols state in case we need to reset
87 1.1.1.2 christos the file flags. */
88 1.1.1.2 christos
89 1.1.1.2 christos static int obj_mach_o_subsections_by_symbols;
90 1.1.1.2 christos
91 1.1.1.2 christos /* This will put at most 16 characters (terminated by a ',' or newline) from
92 1.1.1.2 christos the input stream into dest. If there are more than 16 chars before the
93 1.1.1.2 christos delimiter, a warning is given and the string is truncated. On completion of
94 1.1.1.3 christos this function, input_line_pointer will point to the char after the ',' or
95 1.1.1.3 christos to the newline.
96 1.1.1.3 christos
97 1.1.1.2 christos It trims leading and trailing space. */
98 1.1.1.2 christos
99 1.1.1.2 christos static int
100 1.1.1.2 christos collect_16char_name (char *dest, const char *msg, int require_comma)
101 1.1.1.2 christos {
102 1.1.1.2 christos char c, *namstart;
103 1.1.1.2 christos
104 1.1.1.2 christos SKIP_WHITESPACE ();
105 1.1.1.2 christos namstart = input_line_pointer;
106 1.1.1.2 christos
107 1.1.1.3 christos while ( (c = *input_line_pointer) != ','
108 1.1.1.2 christos && !is_end_of_line[(unsigned char) c])
109 1.1.1.2 christos input_line_pointer++;
110 1.1.1.2 christos
111 1.1.1.2 christos {
112 1.1.1.2 christos int len = input_line_pointer - namstart; /* could be zero. */
113 1.1.1.3 christos /* lose any trailing space. */
114 1.1.1.3 christos while (len > 0 && namstart[len-1] == ' ')
115 1.1.1.2 christos len--;
116 1.1.1.2 christos if (len > 16)
117 1.1.1.2 christos {
118 1.1.1.2 christos *input_line_pointer = '\0'; /* make a temp string. */
119 1.1.1.2 christos as_bad (_("the %s name '%s' is too long (maximum 16 characters)"),
120 1.1.1.2 christos msg, namstart);
121 1.1.1.2 christos *input_line_pointer = c; /* restore for printing. */
122 1.1.1.2 christos len = 16;
123 1.1.1.2 christos }
124 1.1.1.2 christos if (len > 0)
125 1.1.1.2 christos memcpy (dest, namstart, len);
126 1.1.1.2 christos }
127 1.1.1.2 christos
128 1.1.1.2 christos if (c != ',' && require_comma)
129 1.1.1.2 christos {
130 1.1.1.2 christos as_bad (_("expected a %s name followed by a `,'"), msg);
131 1.1.1.2 christos return 1;
132 1.1.1.2 christos }
133 1.1.1.2 christos
134 1.1.1.2 christos return 0;
135 1.1.1.2 christos }
136 1.1.1.2 christos
137 1.1.1.2 christos static int
138 1.1.1.2 christos obj_mach_o_get_section_names (char *seg, char *sec,
139 1.1.1.2 christos unsigned segl, unsigned secl)
140 1.1.1.2 christos {
141 1.1.1.2 christos /* Zero-length segment and section names are allowed. */
142 1.1.1.2 christos /* Parse segment name. */
143 1.1.1.2 christos memset (seg, 0, segl);
144 1.1.1.2 christos if (collect_16char_name (seg, "segment", 1))
145 1.1.1.2 christos {
146 1.1.1.2 christos ignore_rest_of_line ();
147 1.1.1.2 christos return 0;
148 1.1.1.2 christos }
149 1.1.1.2 christos input_line_pointer++; /* Skip the terminating ',' */
150 1.1.1.2 christos
151 1.1.1.2 christos /* Parse section name, which can be empty. */
152 1.1.1.2 christos memset (sec, 0, secl);
153 1.1.1.2 christos collect_16char_name (sec, "section", 0);
154 1.1.1.2 christos return 1;
155 1.1.1.2 christos }
156 1.1.1.2 christos
157 1.1.1.2 christos /* Build (or get) a section from the mach-o description - which includes
158 1.1.1.2 christos optional definitions for type, attributes, alignment and stub size.
159 1.1.1.3 christos
160 1.1.1.2 christos BFD supplies default values for sections which have a canonical name. */
161 1.1.1.2 christos
162 1.1.1.2 christos #define SECT_TYPE_SPECIFIED 0x0001
163 1.1.1.2 christos #define SECT_ATTR_SPECIFIED 0x0002
164 1.1.1.2 christos #define SECT_ALGN_SPECIFIED 0x0004
165 1.1.1.2 christos #define SECT_STUB_SPECIFIED 0x0008
166 1.1.1.2 christos
167 1.1.1.2 christos static segT
168 1.1.1.2 christos obj_mach_o_make_or_get_sect (char * segname, char * sectname,
169 1.1.1.3 christos unsigned int specified_mask,
170 1.1.1.2 christos unsigned int usectype, unsigned int usecattr,
171 1.1.1.2 christos unsigned int ualign, offsetT stub_size)
172 1.1.1.2 christos {
173 1.1.1.2 christos unsigned int sectype, secattr, secalign;
174 1.1.1.2 christos flagword oldflags, flags;
175 1.1.1.2 christos const char *name;
176 1.1.1.2 christos segT sec;
177 1.1.1.2 christos bfd_mach_o_section *msect;
178 1.1.1.2 christos const mach_o_section_name_xlat *xlat;
179 1.1.1.2 christos
180 1.1.1.2 christos /* This provides default bfd flags and default mach-o section type and
181 1.1.1.2 christos attributes along with the canonical name. */
182 1.1.1.2 christos xlat = bfd_mach_o_section_data_for_mach_sect (stdoutput, segname, sectname);
183 1.1.1.2 christos
184 1.1.1.5 christos /* TODO: more checking of whether overrides are actually allowed. */
185 1.1.1.2 christos
186 1.1.1.2 christos if (xlat != NULL)
187 1.1.1.2 christos {
188 1.1.1.2 christos name = xstrdup (xlat->bfd_name);
189 1.1.1.2 christos sectype = xlat->macho_sectype;
190 1.1.1.2 christos if (specified_mask & SECT_TYPE_SPECIFIED)
191 1.1.1.2 christos {
192 1.1.1.2 christos if ((sectype == BFD_MACH_O_S_ZEROFILL
193 1.1.1.2 christos || sectype == BFD_MACH_O_S_GB_ZEROFILL)
194 1.1.1.2 christos && sectype != usectype)
195 1.1.1.5 christos as_bad (_("cannot override zerofill section type for `%s,%s'"),
196 1.1.1.2 christos segname, sectname);
197 1.1.1.2 christos else
198 1.1.1.2 christos sectype = usectype;
199 1.1.1.2 christos }
200 1.1.1.2 christos secattr = xlat->macho_secattr;
201 1.1.1.2 christos secalign = xlat->sectalign;
202 1.1.1.2 christos flags = xlat->bfd_flags;
203 1.1.1.2 christos }
204 1.1.1.2 christos else
205 1.1.1.2 christos {
206 1.1.1.2 christos /* There is no normal BFD section name for this section. Create one.
207 1.1.1.2 christos The name created doesn't really matter as it will never be written
208 1.1.1.2 christos on disk. */
209 1.1.1.4 christos name = concat (segname, ".", sectname, (char *) NULL);
210 1.1.1.2 christos if (specified_mask & SECT_TYPE_SPECIFIED)
211 1.1.1.2 christos sectype = usectype;
212 1.1.1.2 christos else
213 1.1.1.2 christos sectype = BFD_MACH_O_S_REGULAR;
214 1.1.1.2 christos secattr = BFD_MACH_O_S_ATTR_NONE;
215 1.1.1.2 christos secalign = 0;
216 1.1.1.2 christos flags = SEC_NO_FLAGS;
217 1.1.1.2 christos }
218 1.1.1.2 christos
219 1.1.1.2 christos /* For now, just use what the user provided. */
220 1.1.1.2 christos
221 1.1.1.2 christos if (specified_mask & SECT_ATTR_SPECIFIED)
222 1.1.1.2 christos secattr = usecattr;
223 1.1.1.2 christos
224 1.1.1.2 christos if (specified_mask & SECT_ALGN_SPECIFIED)
225 1.1.1.2 christos secalign = ualign;
226 1.1.1.2 christos
227 1.1.1.2 christos /* Sub-segments don't exists as is on Mach-O. */
228 1.1.1.2 christos sec = subseg_new (name, 0);
229 1.1.1.2 christos
230 1.1.1.2 christos oldflags = bfd_get_section_flags (stdoutput, sec);
231 1.1.1.2 christos msect = bfd_mach_o_get_mach_o_section (sec);
232 1.1.1.2 christos
233 1.1.1.2 christos if (oldflags == SEC_NO_FLAGS)
234 1.1.1.2 christos {
235 1.1.1.2 christos /* In the absence of canonical information, try to determine CODE and
236 1.1.1.2 christos DEBUG section flags from the mach-o section data. */
237 1.1.1.2 christos if (flags == SEC_NO_FLAGS
238 1.1.1.2 christos && (specified_mask & SECT_ATTR_SPECIFIED)
239 1.1.1.2 christos && (secattr & BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS))
240 1.1.1.2 christos flags |= SEC_CODE;
241 1.1.1.3 christos
242 1.1.1.2 christos if (flags == SEC_NO_FLAGS
243 1.1.1.2 christos && (specified_mask & SECT_ATTR_SPECIFIED)
244 1.1.1.2 christos && (secattr & BFD_MACH_O_S_ATTR_DEBUG))
245 1.1.1.2 christos flags |= SEC_DEBUGGING;
246 1.1.1.2 christos
247 1.1.1.2 christos /* New, so just use the defaults or what's specified. */
248 1.1.1.2 christos if (! bfd_set_section_flags (stdoutput, sec, flags))
249 1.1.1.2 christos as_warn (_("failed to set flags for \"%s\": %s"),
250 1.1.1.2 christos bfd_section_name (stdoutput, sec),
251 1.1.1.2 christos bfd_errmsg (bfd_get_error ()));
252 1.1.1.3 christos
253 1.1.1.2 christos strncpy (msect->segname, segname, sizeof (msect->segname));
254 1.1.1.2 christos strncpy (msect->sectname, sectname, sizeof (msect->sectname));
255 1.1.1.2 christos
256 1.1.1.2 christos msect->align = secalign;
257 1.1.1.2 christos msect->flags = sectype | secattr;
258 1.1.1.3 christos
259 1.1.1.2 christos if (sectype == BFD_MACH_O_S_ZEROFILL
260 1.1.1.2 christos || sectype == BFD_MACH_O_S_GB_ZEROFILL)
261 1.1.1.2 christos seg_info (sec)->bss = 1;
262 1.1.1.2 christos }
263 1.1.1.2 christos else if (flags != SEC_NO_FLAGS)
264 1.1.1.2 christos {
265 1.1.1.2 christos if (flags != oldflags
266 1.1.1.2 christos || msect->flags != (secattr | sectype))
267 1.1.1.2 christos as_warn (_("Ignoring changed section attributes for %s"), name);
268 1.1.1.2 christos }
269 1.1.1.2 christos
270 1.1.1.2 christos if (specified_mask & SECT_STUB_SPECIFIED)
271 1.1.1.2 christos /* At present, the stub size is not supplied from the BFD tables. */
272 1.1.1.2 christos msect->reserved2 = stub_size;
273 1.1.1.2 christos
274 1.1.1.2 christos return sec;
275 1.1.1.2 christos }
276 1.1.1.2 christos
277 1.1.1.2 christos /* .section
278 1.1.1.2 christos
279 1.1.1.2 christos The '.section' specification syntax looks like:
280 1.1.1.2 christos .section <segment> , <section> [, type [, attribs [, size]]]
281 1.1.1.2 christos
282 1.1.1.2 christos White space is allowed everywhere between elements.
283 1.1.1.2 christos
284 1.1.1.2 christos <segment> and <section> may be from 0 to 16 chars in length - they may
285 1.1.1.3 christos contain spaces but leading and trailing space will be trimmed. It is
286 1.1.1.2 christos mandatory that they be present (or that zero-length names are indicated
287 1.1.1.2 christos by ",,").
288 1.1.1.2 christos
289 1.1.1.2 christos There is only a single section type for any entry.
290 1.1.1.2 christos
291 1.1.1.2 christos There may be multiple attributes, they are delimited by `+'.
292 1.1.1.2 christos
293 1.1.1.2 christos Not all section types and attributes are accepted by the Darwin system
294 1.1.1.2 christos assemblers as user-specifiable - although, at present, we do here. */
295 1.1 christos
296 1.1 christos static void
297 1.1.1.2 christos obj_mach_o_section (int ignore ATTRIBUTE_UNUSED)
298 1.1.1.2 christos {
299 1.1.1.2 christos unsigned int sectype = BFD_MACH_O_S_REGULAR;
300 1.1.1.2 christos unsigned int specified_mask = 0;
301 1.1.1.2 christos unsigned int secattr = 0;
302 1.1.1.2 christos offsetT sizeof_stub = 0;
303 1.1.1.2 christos segT new_seg;
304 1.1.1.2 christos char segname[17];
305 1.1.1.2 christos char sectname[17];
306 1.1.1.2 christos
307 1.1.1.2 christos #ifdef md_flush_pending_output
308 1.1.1.2 christos md_flush_pending_output ();
309 1.1.1.2 christos #endif
310 1.1.1.2 christos
311 1.1.1.5 christos /* Get the User's segment and section names. */
312 1.1.1.2 christos if (! obj_mach_o_get_section_names (segname, sectname, 17, 17))
313 1.1.1.2 christos return;
314 1.1.1.2 christos
315 1.1.1.2 christos /* Parse section type, if present. */
316 1.1.1.2 christos if (*input_line_pointer == ',')
317 1.1.1.2 christos {
318 1.1.1.2 christos char *p;
319 1.1.1.2 christos char c;
320 1.1.1.2 christos char tmpc;
321 1.1.1.2 christos int len;
322 1.1.1.2 christos input_line_pointer++;
323 1.1.1.2 christos SKIP_WHITESPACE ();
324 1.1.1.2 christos p = input_line_pointer;
325 1.1.1.2 christos while ((c = *input_line_pointer) != ','
326 1.1.1.2 christos && !is_end_of_line[(unsigned char) c])
327 1.1.1.2 christos input_line_pointer++;
328 1.1.1.2 christos
329 1.1.1.2 christos len = input_line_pointer - p;
330 1.1.1.2 christos /* strip trailing spaces. */
331 1.1.1.2 christos while (len > 0 && p[len-1] == ' ')
332 1.1.1.2 christos len--;
333 1.1.1.2 christos tmpc = p[len];
334 1.1.1.2 christos
335 1.1.1.2 christos /* Temporarily make a string from the token. */
336 1.1.1.2 christos p[len] = 0;
337 1.1.1.2 christos sectype = bfd_mach_o_get_section_type_from_name (stdoutput, p);
338 1.1.1.2 christos if (sectype > 255) /* Max Section ID == 255. */
339 1.1.1.2 christos {
340 1.1.1.2 christos as_bad (_("unknown or invalid section type '%s'"), p);
341 1.1.1.2 christos p[len] = tmpc;
342 1.1.1.2 christos ignore_rest_of_line ();
343 1.1.1.2 christos return;
344 1.1.1.2 christos }
345 1.1.1.2 christos else
346 1.1.1.2 christos specified_mask |= SECT_TYPE_SPECIFIED;
347 1.1.1.2 christos /* Restore. */
348 1.1.1.2 christos p[len] = tmpc;
349 1.1.1.2 christos
350 1.1.1.2 christos /* Parse attributes.
351 1.1.1.2 christos TODO: check validity of attributes for section type. */
352 1.1.1.2 christos if ((specified_mask & SECT_TYPE_SPECIFIED)
353 1.1.1.2 christos && c == ',')
354 1.1.1.2 christos {
355 1.1.1.2 christos do
356 1.1.1.2 christos {
357 1.1.1.2 christos int attr;
358 1.1.1.2 christos
359 1.1.1.2 christos /* Skip initial `,' and subsequent `+'. */
360 1.1.1.2 christos input_line_pointer++;
361 1.1.1.2 christos SKIP_WHITESPACE ();
362 1.1.1.2 christos p = input_line_pointer;
363 1.1.1.2 christos while ((c = *input_line_pointer) != '+'
364 1.1.1.2 christos && c != ','
365 1.1.1.2 christos && !is_end_of_line[(unsigned char) c])
366 1.1.1.2 christos input_line_pointer++;
367 1.1.1.2 christos
368 1.1.1.2 christos len = input_line_pointer - p;
369 1.1.1.2 christos /* strip trailing spaces. */
370 1.1.1.2 christos while (len > 0 && p[len-1] == ' ')
371 1.1.1.2 christos len--;
372 1.1.1.2 christos tmpc = p[len];
373 1.1.1.2 christos
374 1.1.1.2 christos /* Temporarily make a string from the token. */
375 1.1.1.2 christos p[len] ='\0';
376 1.1.1.2 christos attr = bfd_mach_o_get_section_attribute_from_name (p);
377 1.1.1.2 christos if (attr == -1)
378 1.1.1.2 christos {
379 1.1.1.2 christos as_bad (_("unknown or invalid section attribute '%s'"), p);
380 1.1.1.2 christos p[len] = tmpc;
381 1.1.1.2 christos ignore_rest_of_line ();
382 1.1.1.2 christos return;
383 1.1.1.2 christos }
384 1.1.1.2 christos else
385 1.1.1.2 christos {
386 1.1.1.2 christos specified_mask |= SECT_ATTR_SPECIFIED;
387 1.1.1.2 christos secattr |= attr;
388 1.1.1.2 christos }
389 1.1.1.2 christos /* Restore. */
390 1.1.1.2 christos p[len] = tmpc;
391 1.1.1.2 christos }
392 1.1.1.2 christos while (*input_line_pointer == '+');
393 1.1.1.2 christos
394 1.1.1.2 christos /* Parse sizeof_stub. */
395 1.1.1.3 christos if ((specified_mask & SECT_ATTR_SPECIFIED)
396 1.1.1.2 christos && *input_line_pointer == ',')
397 1.1.1.2 christos {
398 1.1.1.2 christos if (sectype != BFD_MACH_O_S_SYMBOL_STUBS)
399 1.1.1.2 christos {
400 1.1.1.2 christos as_bad (_("unexpected section size information"));
401 1.1.1.2 christos ignore_rest_of_line ();
402 1.1.1.2 christos return;
403 1.1.1.2 christos }
404 1.1.1.2 christos
405 1.1.1.2 christos input_line_pointer++;
406 1.1.1.2 christos sizeof_stub = get_absolute_expression ();
407 1.1.1.2 christos specified_mask |= SECT_STUB_SPECIFIED;
408 1.1.1.2 christos }
409 1.1.1.3 christos else if ((specified_mask & SECT_ATTR_SPECIFIED)
410 1.1.1.2 christos && sectype == BFD_MACH_O_S_SYMBOL_STUBS)
411 1.1.1.2 christos {
412 1.1.1.2 christos as_bad (_("missing sizeof_stub expression"));
413 1.1.1.2 christos ignore_rest_of_line ();
414 1.1.1.2 christos return;
415 1.1.1.2 christos }
416 1.1.1.2 christos }
417 1.1.1.2 christos }
418 1.1.1.2 christos
419 1.1.1.3 christos new_seg = obj_mach_o_make_or_get_sect (segname, sectname, specified_mask,
420 1.1.1.2 christos sectype, secattr, 0 /*align */,
421 1.1.1.2 christos sizeof_stub);
422 1.1.1.2 christos if (new_seg != NULL)
423 1.1.1.2 christos {
424 1.1.1.2 christos subseg_set (new_seg, 0);
425 1.1.1.2 christos demand_empty_rest_of_line ();
426 1.1.1.2 christos }
427 1.1.1.2 christos }
428 1.1.1.2 christos
429 1.1.1.2 christos /* .zerofill segname, sectname [, symbolname, size [, align]]
430 1.1.1.2 christos
431 1.1.1.2 christos Zerofill switches, temporarily, to a sect of type 'zerofill'.
432 1.1.1.2 christos
433 1.1.1.2 christos If a variable name is given, it defines that in the section.
434 1.1.1.2 christos Otherwise it just creates the section if it doesn't exist. */
435 1.1.1.2 christos
436 1.1.1.2 christos static void
437 1.1.1.2 christos obj_mach_o_zerofill (int ignore ATTRIBUTE_UNUSED)
438 1.1.1.2 christos {
439 1.1.1.2 christos char segname[17];
440 1.1.1.2 christos char sectname[17];
441 1.1.1.2 christos segT old_seg = now_seg;
442 1.1.1.2 christos segT new_seg;
443 1.1.1.2 christos symbolS *sym = NULL;
444 1.1.1.2 christos unsigned int align = 0;
445 1.1.1.2 christos unsigned int specified_mask = 0;
446 1.1.1.2 christos offsetT size = 0;
447 1.1.1.2 christos
448 1.1.1.2 christos #ifdef md_flush_pending_output
449 1.1.1.2 christos md_flush_pending_output ();
450 1.1.1.2 christos #endif
451 1.1.1.2 christos
452 1.1.1.5 christos /* Get the User's segment and section names. */
453 1.1.1.2 christos if (! obj_mach_o_get_section_names (segname, sectname, 17, 17))
454 1.1.1.2 christos return;
455 1.1.1.2 christos
456 1.1.1.2 christos /* Parse variable definition, if present. */
457 1.1.1.2 christos if (*input_line_pointer == ',')
458 1.1.1.2 christos {
459 1.1.1.3 christos /* Parse symbol, size [.align]
460 1.1.1.2 christos We follow the method of s_common_internal, with the difference
461 1.1.1.2 christos that the symbol cannot be a duplicate-common. */
462 1.1.1.2 christos char *name;
463 1.1.1.2 christos char c;
464 1.1.1.2 christos char *p;
465 1.1.1.2 christos expressionS exp;
466 1.1.1.3 christos
467 1.1.1.2 christos input_line_pointer++; /* Skip ',' */
468 1.1.1.2 christos SKIP_WHITESPACE ();
469 1.1.1.3 christos c = get_symbol_name (&name);
470 1.1.1.2 christos /* Just after name is now '\0'. */
471 1.1.1.2 christos p = input_line_pointer;
472 1.1.1.2 christos *p = c;
473 1.1.1.2 christos
474 1.1.1.2 christos if (name == p)
475 1.1.1.2 christos {
476 1.1.1.2 christos as_bad (_("expected symbol name"));
477 1.1.1.2 christos ignore_rest_of_line ();
478 1.1.1.2 christos goto done;
479 1.1.1.2 christos }
480 1.1.1.2 christos
481 1.1.1.3 christos SKIP_WHITESPACE_AFTER_NAME ();
482 1.1.1.2 christos if (*input_line_pointer == ',')
483 1.1.1.2 christos input_line_pointer++;
484 1.1.1.2 christos
485 1.1.1.2 christos expression_and_evaluate (&exp);
486 1.1.1.2 christos if (exp.X_op != O_constant
487 1.1.1.2 christos && exp.X_op != O_absent)
488 1.1.1.2 christos {
489 1.1.1.2 christos as_bad (_("bad or irreducible absolute expression"));
490 1.1.1.2 christos ignore_rest_of_line ();
491 1.1.1.2 christos goto done;
492 1.1.1.2 christos }
493 1.1.1.2 christos else if (exp.X_op == O_absent)
494 1.1.1.2 christos {
495 1.1.1.2 christos as_bad (_("missing size expression"));
496 1.1.1.2 christos ignore_rest_of_line ();
497 1.1.1.2 christos goto done;
498 1.1.1.2 christos }
499 1.1.1.2 christos
500 1.1.1.2 christos size = exp.X_add_number;
501 1.1.1.2 christos size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
502 1.1.1.2 christos if (exp.X_add_number != size || !exp.X_unsigned)
503 1.1.1.2 christos {
504 1.1.1.2 christos as_warn (_("size (%ld) out of range, ignored"),
505 1.1.1.2 christos (long) exp.X_add_number);
506 1.1.1.2 christos ignore_rest_of_line ();
507 1.1.1.2 christos goto done;
508 1.1.1.2 christos }
509 1.1.1.2 christos
510 1.1.1.2 christos *p = 0; /* Make the name into a c string for err messages. */
511 1.1.1.2 christos sym = symbol_find_or_make (name);
512 1.1.1.2 christos if (S_IS_DEFINED (sym) || symbol_equated_p (sym))
513 1.1.1.2 christos {
514 1.1.1.2 christos as_bad (_("symbol `%s' is already defined"), name);
515 1.1.1.2 christos *p = c;
516 1.1.1.2 christos ignore_rest_of_line ();
517 1.1.1.2 christos goto done;
518 1.1.1.2 christos }
519 1.1.1.2 christos
520 1.1.1.2 christos size = S_GET_VALUE (sym);
521 1.1.1.2 christos if (size == 0)
522 1.1.1.2 christos size = exp.X_add_number;
523 1.1.1.2 christos else if (size != exp.X_add_number)
524 1.1.1.2 christos as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
525 1.1.1.2 christos name, (long) size, (long) exp.X_add_number);
526 1.1.1.2 christos
527 1.1.1.2 christos *p = c; /* Restore the termination char. */
528 1.1.1.3 christos
529 1.1.1.3 christos SKIP_WHITESPACE ();
530 1.1.1.2 christos if (*input_line_pointer == ',')
531 1.1.1.2 christos {
532 1.1.1.2 christos align = (unsigned int) parse_align (0);
533 1.1.1.2 christos if (align == (unsigned int) -1)
534 1.1.1.2 christos {
535 1.1.1.2 christos as_warn (_("align value not recognized, using size"));
536 1.1.1.2 christos align = size;
537 1.1.1.2 christos }
538 1.1.1.2 christos if (align > 15)
539 1.1.1.2 christos {
540 1.1.1.2 christos as_warn (_("Alignment (%lu) too large: 15 assumed."),
541 1.1.1.2 christos (unsigned long)align);
542 1.1.1.2 christos align = 15;
543 1.1.1.2 christos }
544 1.1.1.2 christos specified_mask |= SECT_ALGN_SPECIFIED;
545 1.1.1.2 christos }
546 1.1.1.2 christos }
547 1.1.1.2 christos /* else just a section definition. */
548 1.1.1.2 christos
549 1.1.1.2 christos specified_mask |= SECT_TYPE_SPECIFIED;
550 1.1.1.3 christos new_seg = obj_mach_o_make_or_get_sect (segname, sectname, specified_mask,
551 1.1.1.2 christos BFD_MACH_O_S_ZEROFILL,
552 1.1.1.2 christos BFD_MACH_O_S_ATTR_NONE,
553 1.1.1.2 christos align, (offsetT) 0 /*stub size*/);
554 1.1.1.2 christos if (new_seg == NULL)
555 1.1.1.2 christos return;
556 1.1.1.2 christos
557 1.1.1.2 christos /* In case the user specifies the bss section by mach-o name.
558 1.1.1.2 christos Create it on demand */
559 1.1.1.2 christos if (strcmp (new_seg->name, BSS_SECTION_NAME) == 0
560 1.1.1.2 christos && bss_section == NULL)
561 1.1.1.2 christos bss_section = new_seg;
562 1.1.1.2 christos
563 1.1.1.2 christos subseg_set (new_seg, 0);
564 1.1.1.2 christos
565 1.1.1.2 christos if (sym != NULL)
566 1.1.1.2 christos {
567 1.1.1.2 christos char *pfrag;
568 1.1.1.2 christos
569 1.1.1.2 christos if (align)
570 1.1.1.2 christos {
571 1.1.1.2 christos record_alignment (new_seg, align);
572 1.1.1.2 christos frag_align (align, 0, 0);
573 1.1.1.2 christos }
574 1.1.1.2 christos
575 1.1.1.2 christos /* Detach from old frag. */
576 1.1.1.2 christos if (S_GET_SEGMENT (sym) == new_seg)
577 1.1.1.2 christos symbol_get_frag (sym)->fr_symbol = NULL;
578 1.1.1.2 christos
579 1.1.1.2 christos symbol_set_frag (sym, frag_now);
580 1.1.1.2 christos pfrag = frag_var (rs_org, 1, 1, 0, sym, size, NULL);
581 1.1.1.2 christos *pfrag = 0;
582 1.1.1.2 christos
583 1.1.1.2 christos S_SET_SEGMENT (sym, new_seg);
584 1.1.1.2 christos if (new_seg == bss_section)
585 1.1.1.2 christos S_CLEAR_EXTERNAL (sym);
586 1.1.1.2 christos }
587 1.1.1.2 christos
588 1.1.1.2 christos done:
589 1.1.1.2 christos /* switch back to the section that was current before the .zerofill. */
590 1.1.1.2 christos subseg_set (old_seg, 0);
591 1.1.1.2 christos }
592 1.1.1.2 christos
593 1.1.1.3 christos static segT
594 1.1.1.2 christos obj_mach_o_segT_from_bfd_name (const char *nam, int must_succeed)
595 1.1.1.2 christos {
596 1.1.1.2 christos const mach_o_section_name_xlat *xlat;
597 1.1.1.2 christos const char *segn;
598 1.1.1.2 christos segT sec;
599 1.1.1.2 christos
600 1.1.1.2 christos /* BFD has tables of flags and default attributes for all the sections that
601 1.1.1.2 christos have a 'canonical' name. */
602 1.1.1.2 christos xlat = bfd_mach_o_section_data_for_bfd_name (stdoutput, nam, &segn);
603 1.1.1.2 christos if (xlat == NULL)
604 1.1.1.2 christos {
605 1.1.1.2 christos if (must_succeed)
606 1.1.1.2 christos as_fatal (_("BFD is out of sync with GAS, "
607 1.1.1.2 christos "unhandled well-known section type `%s'"), nam);
608 1.1.1.2 christos return NULL;
609 1.1.1.2 christos }
610 1.1.1.2 christos
611 1.1.1.2 christos sec = bfd_get_section_by_name (stdoutput, nam);
612 1.1.1.2 christos if (sec == NULL)
613 1.1.1.2 christos {
614 1.1.1.2 christos bfd_mach_o_section *msect;
615 1.1.1.2 christos
616 1.1.1.2 christos sec = subseg_force_new (xlat->bfd_name, 0);
617 1.1.1.2 christos
618 1.1.1.2 christos /* Set default type, attributes and alignment. */
619 1.1.1.2 christos msect = bfd_mach_o_get_mach_o_section (sec);
620 1.1.1.2 christos msect->flags = xlat->macho_sectype | xlat->macho_secattr;
621 1.1.1.2 christos msect->align = xlat->sectalign;
622 1.1.1.2 christos
623 1.1.1.3 christos if ((msect->flags & BFD_MACH_O_SECTION_TYPE_MASK)
624 1.1.1.2 christos == BFD_MACH_O_S_ZEROFILL)
625 1.1.1.2 christos seg_info (sec)->bss = 1;
626 1.1.1.2 christos }
627 1.1.1.2 christos
628 1.1.1.2 christos return sec;
629 1.1.1.2 christos }
630 1.1.1.2 christos
631 1.1.1.2 christos static const char * const known_sections[] =
632 1.1.1.2 christos {
633 1.1.1.2 christos /* 0 */ NULL,
634 1.1.1.2 christos /* __TEXT */
635 1.1.1.2 christos /* 1 */ ".const",
636 1.1.1.2 christos /* 2 */ ".static_const",
637 1.1.1.2 christos /* 3 */ ".cstring",
638 1.1.1.2 christos /* 4 */ ".literal4",
639 1.1.1.2 christos /* 5 */ ".literal8",
640 1.1.1.2 christos /* 6 */ ".literal16",
641 1.1.1.2 christos /* 7 */ ".constructor",
642 1.1.1.2 christos /* 8 */ ".destructor",
643 1.1.1.2 christos /* 9 */ ".eh_frame",
644 1.1.1.2 christos /* __DATA */
645 1.1.1.2 christos /* 10 */ ".const_data",
646 1.1.1.2 christos /* 11 */ ".static_data",
647 1.1.1.2 christos /* 12 */ ".mod_init_func",
648 1.1.1.2 christos /* 13 */ ".mod_term_func",
649 1.1.1.2 christos /* 14 */ ".dyld",
650 1.1.1.2 christos /* 15 */ ".cfstring"
651 1.1.1.2 christos };
652 1.1.1.2 christos
653 1.1.1.2 christos /* Interface for a known non-optional section directive. */
654 1.1.1.2 christos
655 1.1.1.2 christos static void
656 1.1.1.2 christos obj_mach_o_known_section (int sect_index)
657 1.1.1.2 christos {
658 1.1.1.2 christos segT section;
659 1.1.1.2 christos
660 1.1.1.2 christos #ifdef md_flush_pending_output
661 1.1.1.2 christos md_flush_pending_output ();
662 1.1.1.2 christos #endif
663 1.1.1.2 christos
664 1.1.1.2 christos section = obj_mach_o_segT_from_bfd_name (known_sections[sect_index], 1);
665 1.1.1.2 christos if (section != NULL)
666 1.1.1.2 christos subseg_set (section, 0);
667 1.1.1.2 christos
668 1.1.1.2 christos /* else, we leave the section as it was; there was a fatal error anyway. */
669 1.1.1.2 christos }
670 1.1.1.2 christos
671 1.1.1.2 christos static const char * const objc_sections[] =
672 1.1.1.2 christos {
673 1.1.1.2 christos /* 0 */ NULL,
674 1.1.1.2 christos /* 1 */ ".objc_class",
675 1.1.1.2 christos /* 2 */ ".objc_meta_class",
676 1.1.1.2 christos /* 3 */ ".objc_cat_cls_meth",
677 1.1.1.2 christos /* 4 */ ".objc_cat_inst_meth",
678 1.1.1.2 christos /* 5 */ ".objc_protocol",
679 1.1.1.2 christos /* 6 */ ".objc_string_object",
680 1.1.1.2 christos /* 7 */ ".objc_cls_meth",
681 1.1.1.2 christos /* 8 */ ".objc_inst_meth",
682 1.1.1.2 christos /* 9 */ ".objc_cls_refs",
683 1.1.1.2 christos /* 10 */ ".objc_message_refs",
684 1.1.1.2 christos /* 11 */ ".objc_symbols",
685 1.1.1.2 christos /* 12 */ ".objc_category",
686 1.1.1.2 christos /* 13 */ ".objc_class_vars",
687 1.1.1.2 christos /* 14 */ ".objc_instance_vars",
688 1.1.1.2 christos /* 15 */ ".objc_module_info",
689 1.1.1.2 christos /* 16 */ ".cstring", /* objc_class_names Alias for .cstring */
690 1.1.1.2 christos /* 17 */ ".cstring", /* Alias objc_meth_var_types for .cstring */
691 1.1.1.2 christos /* 18 */ ".cstring", /* objc_meth_var_names Alias for .cstring */
692 1.1.1.2 christos /* 19 */ ".objc_selector_strs",
693 1.1.1.2 christos /* 20 */ ".objc_image_info", /* extension. */
694 1.1.1.2 christos /* 21 */ ".objc_selector_fixup", /* extension. */
695 1.1.1.2 christos /* 22 */ ".objc1_class_ext", /* ObjC-1 extension. */
696 1.1.1.2 christos /* 23 */ ".objc1_property_list", /* ObjC-1 extension. */
697 1.1.1.2 christos /* 24 */ ".objc1_protocol_ext" /* ObjC-1 extension. */
698 1.1.1.2 christos };
699 1.1.1.2 christos
700 1.1.1.2 christos /* This currently does the same as known_sections, but kept separate for
701 1.1.1.2 christos ease of maintenance. */
702 1.1.1.2 christos
703 1.1.1.2 christos static void
704 1.1.1.2 christos obj_mach_o_objc_section (int sect_index)
705 1.1.1.2 christos {
706 1.1.1.2 christos segT section;
707 1.1.1.3 christos
708 1.1.1.2 christos #ifdef md_flush_pending_output
709 1.1.1.2 christos md_flush_pending_output ();
710 1.1.1.2 christos #endif
711 1.1.1.2 christos
712 1.1.1.2 christos section = obj_mach_o_segT_from_bfd_name (objc_sections[sect_index], 1);
713 1.1.1.2 christos if (section != NULL)
714 1.1.1.2 christos {
715 1.1.1.2 christos obj_mach_o_seen_objc_section = 1; /* We need to ensure that certain
716 1.1.1.2 christos sections are present and in the
717 1.1.1.2 christos right order. */
718 1.1.1.2 christos subseg_set (section, 0);
719 1.1.1.2 christos }
720 1.1.1.2 christos
721 1.1.1.2 christos /* else, we leave the section as it was; there was a fatal error anyway. */
722 1.1.1.2 christos }
723 1.1.1.2 christos
724 1.1.1.2 christos /* Debug section directives. */
725 1.1.1.2 christos
726 1.1.1.2 christos static const char * const debug_sections[] =
727 1.1.1.2 christos {
728 1.1.1.2 christos /* 0 */ NULL,
729 1.1.1.2 christos /* __DWARF */
730 1.1.1.2 christos /* 1 */ ".debug_frame",
731 1.1.1.2 christos /* 2 */ ".debug_info",
732 1.1.1.2 christos /* 3 */ ".debug_abbrev",
733 1.1.1.2 christos /* 4 */ ".debug_aranges",
734 1.1.1.2 christos /* 5 */ ".debug_macinfo",
735 1.1.1.2 christos /* 6 */ ".debug_line",
736 1.1.1.2 christos /* 7 */ ".debug_loc",
737 1.1.1.2 christos /* 8 */ ".debug_pubnames",
738 1.1.1.2 christos /* 9 */ ".debug_pubtypes",
739 1.1.1.2 christos /* 10 */ ".debug_str",
740 1.1.1.2 christos /* 11 */ ".debug_ranges",
741 1.1.1.2 christos /* 12 */ ".debug_macro"
742 1.1.1.2 christos };
743 1.1.1.2 christos
744 1.1.1.2 christos /* ??? Maybe these should be conditional on gdwarf-*.
745 1.1.1.2 christos It`s also likely that we will need to be able to set them from the cfi
746 1.1.1.2 christos code. */
747 1.1.1.2 christos
748 1.1.1.2 christos static void
749 1.1.1.2 christos obj_mach_o_debug_section (int sect_index)
750 1.1.1.2 christos {
751 1.1.1.2 christos segT section;
752 1.1.1.2 christos
753 1.1.1.2 christos #ifdef md_flush_pending_output
754 1.1.1.2 christos md_flush_pending_output ();
755 1.1.1.2 christos #endif
756 1.1.1.2 christos
757 1.1.1.2 christos section = obj_mach_o_segT_from_bfd_name (debug_sections[sect_index], 1);
758 1.1.1.2 christos if (section != NULL)
759 1.1.1.2 christos subseg_set (section, 0);
760 1.1.1.2 christos
761 1.1.1.2 christos /* else, we leave the section as it was; there was a fatal error anyway. */
762 1.1.1.2 christos }
763 1.1.1.2 christos
764 1.1.1.2 christos /* This could be moved to the tc-xx files, but there is so little dependency
765 1.1.1.2 christos there, that the code might as well be shared. */
766 1.1.1.2 christos
767 1.1.1.3 christos struct opt_tgt_sect
768 1.1.1.2 christos {
769 1.1.1.2 christos const char *name;
770 1.1.1.2 christos unsigned x86_val;
771 1.1.1.2 christos unsigned ppc_val;
772 1.1.1.2 christos };
773 1.1.1.2 christos
774 1.1.1.2 christos /* The extensions here are for specific sections that are generated by GCC
775 1.1.1.2 christos and Darwin system tools, but don't have directives in the `system as'. */
776 1.1.1.2 christos
777 1.1.1.2 christos static const struct opt_tgt_sect tgt_sections[] =
778 1.1.1.2 christos {
779 1.1.1.2 christos /* 0 */ { NULL, 0, 0},
780 1.1.1.2 christos /* 1 */ { ".lazy_symbol_pointer", 0, 0},
781 1.1.1.2 christos /* 2 */ { ".lazy_symbol_pointer2", 0, 0}, /* X86 - extension */
782 1.1.1.2 christos /* 3 */ { ".lazy_symbol_pointer3", 0, 0}, /* X86 - extension */
783 1.1.1.2 christos /* 4 */ { ".non_lazy_symbol_pointer", 0, 0},
784 1.1.1.2 christos /* 5 */ { ".non_lazy_symbol_pointer_x86", 0, 0}, /* X86 - extension */
785 1.1.1.2 christos /* 6 */ { ".symbol_stub", 16, 20},
786 1.1.1.2 christos /* 7 */ { ".symbol_stub1", 0, 16}, /* PPC - extension */
787 1.1.1.2 christos /* 8 */ { ".picsymbol_stub", 26, 36},
788 1.1.1.2 christos /* 9 */ { ".picsymbol_stub1", 0, 32}, /* PPC - extension */
789 1.1.1.2 christos /* 10 */ { ".picsymbol_stub2", 25, 0}, /* X86 - extension */
790 1.1.1.2 christos /* 11 */ { ".picsymbol_stub3", 5, 0}, /* X86 - extension */
791 1.1.1.2 christos };
792 1.1.1.2 christos
793 1.1.1.2 christos /* Interface for an optional section directive. */
794 1.1.1.2 christos
795 1.1.1.2 christos static void
796 1.1.1.2 christos obj_mach_o_opt_tgt_section (int sect_index)
797 1.1.1.2 christos {
798 1.1.1.2 christos const struct opt_tgt_sect *tgtsct = &tgt_sections[sect_index];
799 1.1.1.2 christos segT section;
800 1.1.1.2 christos
801 1.1.1.2 christos #ifdef md_flush_pending_output
802 1.1.1.2 christos md_flush_pending_output ();
803 1.1.1.2 christos #endif
804 1.1.1.2 christos
805 1.1.1.2 christos section = obj_mach_o_segT_from_bfd_name (tgtsct->name, 0);
806 1.1.1.2 christos if (section == NULL)
807 1.1.1.2 christos {
808 1.1.1.2 christos as_bad (_("%s is not used for the selected target"), tgtsct->name);
809 1.1.1.2 christos /* Leave the section as it is. */
810 1.1.1.2 christos }
811 1.1.1.2 christos else
812 1.1.1.2 christos {
813 1.1.1.2 christos bfd_mach_o_section *mo_sec = bfd_mach_o_get_mach_o_section (section);
814 1.1.1.2 christos subseg_set (section, 0);
815 1.1.1.2 christos #if defined (TC_I386)
816 1.1.1.2 christos mo_sec->reserved2 = tgtsct->x86_val;
817 1.1.1.2 christos #elif defined (TC_PPC)
818 1.1.1.2 christos mo_sec->reserved2 = tgtsct->ppc_val;
819 1.1.1.2 christos #else
820 1.1.1.2 christos mo_sec->reserved2 = 0;
821 1.1.1.2 christos #endif
822 1.1.1.2 christos }
823 1.1.1.2 christos }
824 1.1.1.2 christos
825 1.1.1.2 christos /* We don't necessarily have the three 'base' sections on mach-o.
826 1.1.1.2 christos Normally, we would start up with only the 'text' section defined.
827 1.1.1.2 christos However, even that can be suppressed with (TODO) c/l option "-n".
828 1.1.1.2 christos Thus, we have to be able to create all three sections on-demand. */
829 1.1.1.2 christos
830 1.1.1.2 christos static void
831 1.1.1.2 christos obj_mach_o_base_section (int sect_index)
832 1.1.1.2 christos {
833 1.1.1.2 christos segT section;
834 1.1.1.2 christos
835 1.1.1.2 christos #ifdef md_flush_pending_output
836 1.1.1.2 christos md_flush_pending_output ();
837 1.1.1.2 christos #endif
838 1.1.1.2 christos
839 1.1.1.2 christos /* We don't support numeric (or any other) qualifications on the
840 1.1.1.2 christos well-known section shorthands. */
841 1.1.1.2 christos demand_empty_rest_of_line ();
842 1.1.1.2 christos
843 1.1.1.2 christos switch (sect_index)
844 1.1.1.2 christos {
845 1.1.1.2 christos /* Handle the three sections that are globally known within GAS.
846 1.1.1.2 christos For Mach-O, these are created on demand rather than at startup. */
847 1.1.1.2 christos case 1:
848 1.1.1.2 christos if (text_section == NULL)
849 1.1.1.2 christos text_section = obj_mach_o_segT_from_bfd_name (TEXT_SECTION_NAME, 1);
850 1.1.1.2 christos if (obj_mach_o_is_static)
851 1.1.1.2 christos {
852 1.1.1.2 christos bfd_mach_o_section *mo_sec
853 1.1.1.2 christos = bfd_mach_o_get_mach_o_section (text_section);
854 1.1.1.2 christos mo_sec->flags &= ~BFD_MACH_O_S_ATTR_PURE_INSTRUCTIONS;
855 1.1.1.2 christos }
856 1.1.1.2 christos section = text_section;
857 1.1.1.2 christos break;
858 1.1.1.2 christos case 2:
859 1.1.1.2 christos if (data_section == NULL)
860 1.1.1.2 christos data_section = obj_mach_o_segT_from_bfd_name (DATA_SECTION_NAME, 1);
861 1.1.1.2 christos section = data_section;
862 1.1.1.2 christos break;
863 1.1.1.2 christos case 3:
864 1.1.1.2 christos /* ??? maybe this achieves very little, as an addition. */
865 1.1.1.2 christos if (bss_section == NULL)
866 1.1.1.2 christos {
867 1.1.1.2 christos bss_section = obj_mach_o_segT_from_bfd_name (BSS_SECTION_NAME, 1);
868 1.1.1.2 christos seg_info (bss_section)->bss = 1;
869 1.1.1.2 christos }
870 1.1.1.2 christos section = bss_section;
871 1.1.1.2 christos break;
872 1.1.1.2 christos default:
873 1.1.1.2 christos as_fatal (_("internal error: base section index out of range"));
874 1.1.1.2 christos return;
875 1.1.1.2 christos break;
876 1.1.1.2 christos }
877 1.1.1.2 christos subseg_set (section, 0);
878 1.1.1.2 christos }
879 1.1.1.2 christos
880 1.1.1.2 christos /* This finishes off parsing a .comm or .lcomm statement, which both can have
881 1.1.1.2 christos an (optional) alignment field. It also allows us to create the bss section
882 1.1.1.2 christos on demand. */
883 1.1.1.2 christos
884 1.1.1.2 christos static symbolS *
885 1.1.1.2 christos obj_mach_o_common_parse (int is_local, symbolS *symbolP,
886 1.1.1.2 christos addressT size)
887 1.1.1.2 christos {
888 1.1.1.2 christos addressT align = 0;
889 1.1.1.2 christos bfd_mach_o_asymbol *s;
890 1.1.1.2 christos
891 1.1.1.3 christos SKIP_WHITESPACE ();
892 1.1.1.2 christos
893 1.1.1.2 christos /* Both comm and lcomm take an optional alignment, as a power
894 1.1.1.2 christos of two between 1 and 15. */
895 1.1.1.2 christos if (*input_line_pointer == ',')
896 1.1.1.2 christos {
897 1.1.1.2 christos /* We expect a power of 2. */
898 1.1.1.2 christos align = parse_align (0);
899 1.1.1.2 christos if (align == (addressT) -1)
900 1.1.1.2 christos return NULL;
901 1.1.1.2 christos if (align > 15)
902 1.1.1.2 christos {
903 1.1.1.2 christos as_warn (_("Alignment (%lu) too large: 15 assumed."),
904 1.1.1.2 christos (unsigned long)align);
905 1.1.1.2 christos align = 15;
906 1.1.1.2 christos }
907 1.1.1.2 christos }
908 1.1.1.2 christos
909 1.1.1.2 christos s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (symbolP);
910 1.1.1.2 christos if (is_local)
911 1.1.1.2 christos {
912 1.1.1.2 christos /* Create the BSS section on demand. */
913 1.1.1.2 christos if (bss_section == NULL)
914 1.1.1.2 christos {
915 1.1.1.2 christos bss_section = obj_mach_o_segT_from_bfd_name (BSS_SECTION_NAME, 1);
916 1.1.1.3 christos seg_info (bss_section)->bss = 1;
917 1.1.1.2 christos }
918 1.1.1.2 christos bss_alloc (symbolP, size, align);
919 1.1.1.2 christos s->n_type = BFD_MACH_O_N_SECT;
920 1.1.1.2 christos S_CLEAR_EXTERNAL (symbolP);
921 1.1.1.2 christos }
922 1.1.1.2 christos else
923 1.1.1.2 christos {
924 1.1.1.2 christos S_SET_VALUE (symbolP, size);
925 1.1.1.2 christos S_SET_ALIGN (symbolP, align);
926 1.1.1.2 christos S_SET_EXTERNAL (symbolP);
927 1.1.1.2 christos S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
928 1.1.1.2 christos s->n_type = BFD_MACH_O_N_UNDF | BFD_MACH_O_N_EXT;
929 1.1.1.2 christos }
930 1.1.1.2 christos
931 1.1.1.2 christos /* This is a data object (whatever we choose that to mean). */
932 1.1.1.2 christos s->symbol.flags |= BSF_OBJECT;
933 1.1.1.2 christos
934 1.1.1.2 christos /* We've set symbol qualifiers, so validate if you can. */
935 1.1.1.2 christos s->symbol.udata.i = SYM_MACHO_FIELDS_NOT_VALIDATED;
936 1.1.1.2 christos
937 1.1.1.2 christos return symbolP;
938 1.1.1.2 christos }
939 1.1.1.2 christos
940 1.1.1.2 christos static void
941 1.1.1.2 christos obj_mach_o_comm (int is_local)
942 1.1.1.2 christos {
943 1.1.1.2 christos s_comm_internal (is_local, obj_mach_o_common_parse);
944 1.1.1.2 christos }
945 1.1.1.2 christos
946 1.1.1.2 christos /* Set properties that apply to the whole file. At present, the only
947 1.1.1.2 christos one defined, is subsections_via_symbols. */
948 1.1.1.2 christos
949 1.1.1.2 christos typedef enum obj_mach_o_file_properties {
950 1.1.1.2 christos OBJ_MACH_O_FILE_PROP_NONE = 0,
951 1.1.1.2 christos OBJ_MACH_O_FILE_PROP_SUBSECTS_VIA_SYMS,
952 1.1.1.2 christos OBJ_MACH_O_FILE_PROP_MAX
953 1.1.1.2 christos } obj_mach_o_file_properties;
954 1.1.1.2 christos
955 1.1.1.3 christos static void
956 1.1.1.2 christos obj_mach_o_fileprop (int prop)
957 1.1.1.2 christos {
958 1.1.1.2 christos if (prop < 0 || prop >= OBJ_MACH_O_FILE_PROP_MAX)
959 1.1.1.2 christos as_fatal (_("internal error: bad file property ID %d"), prop);
960 1.1.1.3 christos
961 1.1.1.2 christos switch ((obj_mach_o_file_properties) prop)
962 1.1.1.2 christos {
963 1.1.1.2 christos case OBJ_MACH_O_FILE_PROP_SUBSECTS_VIA_SYMS:
964 1.1.1.2 christos obj_mach_o_subsections_by_symbols = 1;
965 1.1.1.3 christos if (!bfd_set_private_flags (stdoutput,
966 1.1.1.2 christos BFD_MACH_O_MH_SUBSECTIONS_VIA_SYMBOLS))
967 1.1.1.2 christos as_bad (_("failed to set subsections by symbols"));
968 1.1.1.2 christos demand_empty_rest_of_line ();
969 1.1.1.2 christos break;
970 1.1.1.2 christos default:
971 1.1.1.2 christos break;
972 1.1.1.2 christos }
973 1.1.1.2 christos }
974 1.1.1.2 christos
975 1.1.1.3 christos /* Temporary markers for symbol reference data.
976 1.1.1.2 christos Lazy will remain in place. */
977 1.1.1.2 christos #define LAZY 0x01
978 1.1.1.2 christos #define REFE 0x02
979 1.1.1.2 christos
980 1.1.1.2 christos /* We have a bunch of qualifiers that may be applied to symbols.
981 1.1.1.2 christos .globl is handled here so that we might make sure that conflicting qualifiers
982 1.1.1.2 christos are caught where possible. */
983 1.1.1.2 christos
984 1.1.1.2 christos typedef enum obj_mach_o_symbol_type {
985 1.1.1.2 christos OBJ_MACH_O_SYM_UNK = 0,
986 1.1.1.2 christos OBJ_MACH_O_SYM_LOCAL = 1,
987 1.1.1.2 christos OBJ_MACH_O_SYM_GLOBL = 2,
988 1.1.1.2 christos OBJ_MACH_O_SYM_REFERENCE = 3,
989 1.1.1.2 christos OBJ_MACH_O_SYM_WEAK_REF = 4,
990 1.1.1.2 christos OBJ_MACH_O_SYM_LAZY_REF = 5,
991 1.1.1.2 christos OBJ_MACH_O_SYM_WEAK_DEF = 6,
992 1.1.1.2 christos OBJ_MACH_O_SYM_PRIV_EXT = 7,
993 1.1.1.2 christos OBJ_MACH_O_SYM_NO_DEAD_STRIP = 8,
994 1.1.1.2 christos OBJ_MACH_O_SYM_WEAK = 9
995 1.1.1.2 christos } obj_mach_o_symbol_type;
996 1.1.1.2 christos
997 1.1.1.2 christos /* Set Mach-O-specific symbol qualifiers. */
998 1.1.1.2 christos
999 1.1.1.2 christos static int
1000 1.1.1.2 christos obj_mach_o_set_symbol_qualifier (symbolS *sym, int type)
1001 1.1.1.2 christos {
1002 1.1.1.2 christos int is_defined;
1003 1.1.1.2 christos bfd_mach_o_asymbol *s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (sym);
1004 1.1.1.2 christos bfd_mach_o_section *sec;
1005 1.1.1.2 christos int sectype = -1;
1006 1.1.1.2 christos
1007 1.1.1.2 christos /* If the symbol is defined, then we can do more rigorous checking on
1008 1.1.1.3 christos the validity of the qualifiers. Otherwise, we are stuck with waiting
1009 1.1.1.2 christos until it's defined - or until write the file.
1010 1.1.1.3 christos
1011 1.1.1.2 christos In certain cases (e.g. when a symbol qualifier is intended to introduce
1012 1.1.1.2 christos an undefined symbol in a stubs section) we should check that the current
1013 1.1.1.2 christos section is appropriate to the qualifier. */
1014 1.1.1.2 christos
1015 1.1.1.2 christos is_defined = s->symbol.section != bfd_und_section_ptr;
1016 1.1.1.2 christos if (is_defined)
1017 1.1.1.2 christos sec = bfd_mach_o_get_mach_o_section (s->symbol.section) ;
1018 1.1.1.2 christos else
1019 1.1.1.2 christos sec = bfd_mach_o_get_mach_o_section (now_seg) ;
1020 1.1.1.2 christos
1021 1.1.1.2 christos if (sec != NULL)
1022 1.1.1.2 christos sectype = sec->flags & BFD_MACH_O_SECTION_TYPE_MASK;
1023 1.1.1.2 christos
1024 1.1.1.2 christos switch ((obj_mach_o_symbol_type) type)
1025 1.1.1.2 christos {
1026 1.1.1.2 christos case OBJ_MACH_O_SYM_LOCAL:
1027 1.1.1.2 christos /* This is an extension over the system tools. */
1028 1.1.1.2 christos if (s->n_type & (BFD_MACH_O_N_PEXT | BFD_MACH_O_N_EXT))
1029 1.1.1.2 christos {
1030 1.1.1.2 christos as_bad (_("'%s' previously declared as '%s'."), s->symbol.name,
1031 1.1.1.2 christos (s->n_type & BFD_MACH_O_N_PEXT) ? "private extern"
1032 1.1.1.2 christos : "global" );
1033 1.1.1.3 christos s->symbol.udata.i = SYM_MACHO_FIELDS_UNSET;
1034 1.1.1.3 christos return 1;
1035 1.1.1.2 christos }
1036 1.1.1.2 christos else
1037 1.1.1.2 christos {
1038 1.1.1.2 christos s->n_type &= ~BFD_MACH_O_N_EXT;
1039 1.1.1.2 christos S_CLEAR_EXTERNAL (sym);
1040 1.1.1.2 christos }
1041 1.1.1.2 christos break;
1042 1.1.1.2 christos
1043 1.1.1.2 christos case OBJ_MACH_O_SYM_PRIV_EXT:
1044 1.1.1.2 christos s->n_type |= BFD_MACH_O_N_PEXT ;
1045 1.1.1.2 christos s->n_desc &= ~LAZY; /* The native tool switches this off too. */
1046 1.1.1.2 christos /* We follow the system tools in marking PEXT as also global. */
1047 1.1.1.2 christos /* Fall through. */
1048 1.1.1.2 christos
1049 1.1.1.2 christos case OBJ_MACH_O_SYM_GLOBL:
1050 1.1.1.2 christos /* It's not an error to define a symbol and then make it global. */
1051 1.1.1.2 christos s->n_type |= BFD_MACH_O_N_EXT;
1052 1.1.1.2 christos S_SET_EXTERNAL (sym);
1053 1.1.1.2 christos break;
1054 1.1.1.2 christos
1055 1.1.1.2 christos case OBJ_MACH_O_SYM_REFERENCE:
1056 1.1.1.2 christos if (is_defined)
1057 1.1.1.2 christos s->n_desc |= BFD_MACH_O_N_NO_DEAD_STRIP;
1058 1.1.1.2 christos else
1059 1.1.1.2 christos s->n_desc |= (REFE | BFD_MACH_O_N_NO_DEAD_STRIP);
1060 1.1.1.2 christos break;
1061 1.1.1.2 christos
1062 1.1.1.2 christos case OBJ_MACH_O_SYM_LAZY_REF:
1063 1.1.1.2 christos if (is_defined)
1064 1.1.1.2 christos s->n_desc |= BFD_MACH_O_N_NO_DEAD_STRIP;
1065 1.1.1.2 christos else
1066 1.1.1.2 christos s->n_desc |= (REFE | LAZY | BFD_MACH_O_N_NO_DEAD_STRIP);
1067 1.1.1.2 christos break;
1068 1.1.1.2 christos
1069 1.1.1.2 christos /* Force ld to retain the symbol - even if it appears unused. */
1070 1.1.1.2 christos case OBJ_MACH_O_SYM_NO_DEAD_STRIP:
1071 1.1.1.2 christos s->n_desc |= BFD_MACH_O_N_NO_DEAD_STRIP ;
1072 1.1.1.2 christos break;
1073 1.1.1.2 christos
1074 1.1.1.2 christos /* Mach-O's idea of weak ... */
1075 1.1.1.2 christos case OBJ_MACH_O_SYM_WEAK_REF:
1076 1.1.1.2 christos s->n_desc |= BFD_MACH_O_N_WEAK_REF ;
1077 1.1.1.2 christos break;
1078 1.1.1.2 christos
1079 1.1.1.2 christos case OBJ_MACH_O_SYM_WEAK_DEF:
1080 1.1.1.2 christos if (is_defined && sectype != BFD_MACH_O_S_COALESCED)
1081 1.1.1.2 christos {
1082 1.1.1.2 christos as_bad (_("'%s' can't be a weak_definition (currently only"
1083 1.1.1.2 christos " supported in sections of type coalesced)"),
1084 1.1.1.2 christos s->symbol.name);
1085 1.1.1.3 christos s->symbol.udata.i = SYM_MACHO_FIELDS_UNSET;
1086 1.1.1.3 christos return 1;
1087 1.1.1.2 christos }
1088 1.1.1.2 christos else
1089 1.1.1.2 christos s->n_desc |= BFD_MACH_O_N_WEAK_DEF;
1090 1.1.1.2 christos break;
1091 1.1.1.2 christos
1092 1.1.1.2 christos case OBJ_MACH_O_SYM_WEAK:
1093 1.1.1.2 christos /* A generic 'weak' - we try to figure out what it means at
1094 1.1.1.2 christos symbol frob time. */
1095 1.1.1.2 christos S_SET_WEAK (sym);
1096 1.1.1.2 christos break;
1097 1.1.1.2 christos
1098 1.1.1.2 christos default:
1099 1.1.1.2 christos break;
1100 1.1.1.2 christos }
1101 1.1.1.2 christos
1102 1.1.1.2 christos /* We've seen some kind of qualifier - check validity if or when the entity
1103 1.1.1.2 christos is defined. */
1104 1.1.1.2 christos s->symbol.udata.i = SYM_MACHO_FIELDS_NOT_VALIDATED;
1105 1.1.1.3 christos return 0;
1106 1.1.1.2 christos }
1107 1.1.1.2 christos
1108 1.1.1.2 christos /* Respond to symbol qualifiers.
1109 1.1.1.2 christos All of the form:
1110 1.1.1.2 christos .<qualifier> symbol [, symbol]*
1111 1.1.1.2 christos a list of symbols is an extension over the Darwin system as. */
1112 1.1.1.2 christos
1113 1.1.1.2 christos static void
1114 1.1.1.2 christos obj_mach_o_sym_qual (int ntype)
1115 1.1 christos {
1116 1.1 christos char *name;
1117 1.1.1.2 christos char c;
1118 1.1 christos symbolS *symbolP;
1119 1.1 christos
1120 1.1.1.2 christos #ifdef md_flush_pending_output
1121 1.1.1.2 christos md_flush_pending_output ();
1122 1.1.1.2 christos #endif
1123 1.1.1.2 christos
1124 1.1 christos do
1125 1.1 christos {
1126 1.1.1.3 christos c = get_symbol_name (&name);
1127 1.1 christos symbolP = symbol_find_or_make (name);
1128 1.1.1.2 christos obj_mach_o_set_symbol_qualifier (symbolP, ntype);
1129 1.1 christos *input_line_pointer = c;
1130 1.1.1.3 christos SKIP_WHITESPACE_AFTER_NAME ();
1131 1.1.1.2 christos c = *input_line_pointer;
1132 1.1.1.2 christos if (c == ',')
1133 1.1.1.2 christos {
1134 1.1.1.2 christos input_line_pointer++;
1135 1.1.1.2 christos SKIP_WHITESPACE ();
1136 1.1.1.2 christos if (is_end_of_line[(unsigned char) *input_line_pointer])
1137 1.1.1.2 christos c = '\n';
1138 1.1.1.2 christos }
1139 1.1.1.2 christos }
1140 1.1.1.2 christos while (c == ',');
1141 1.1 christos
1142 1.1.1.2 christos demand_empty_rest_of_line ();
1143 1.1.1.2 christos }
1144 1.1.1.2 christos
1145 1.1.1.2 christos typedef struct obj_mach_o_indirect_sym
1146 1.1.1.2 christos {
1147 1.1.1.2 christos symbolS *sym;
1148 1.1.1.2 christos segT sect;
1149 1.1.1.2 christos struct obj_mach_o_indirect_sym *next;
1150 1.1.1.2 christos } obj_mach_o_indirect_sym;
1151 1.1.1.2 christos
1152 1.1.1.2 christos /* We store in order an maintain a pointer to the last one - to save reversing
1153 1.1.1.2 christos later. */
1154 1.1.1.2 christos obj_mach_o_indirect_sym *indirect_syms;
1155 1.1.1.2 christos obj_mach_o_indirect_sym *indirect_syms_tail;
1156 1.1.1.2 christos
1157 1.1.1.2 christos static void
1158 1.1.1.2 christos obj_mach_o_indirect_symbol (int arg ATTRIBUTE_UNUSED)
1159 1.1.1.2 christos {
1160 1.1.1.2 christos bfd_mach_o_section *sec = bfd_mach_o_get_mach_o_section (now_seg);
1161 1.1.1.2 christos
1162 1.1.1.2 christos #ifdef md_flush_pending_output
1163 1.1.1.2 christos md_flush_pending_output ();
1164 1.1.1.2 christos #endif
1165 1.1.1.2 christos
1166 1.1.1.2 christos if (obj_mach_o_is_static)
1167 1.1.1.2 christos as_bad (_("use of .indirect_symbols requires `-dynamic'"));
1168 1.1.1.2 christos
1169 1.1.1.2 christos switch (sec->flags & BFD_MACH_O_SECTION_TYPE_MASK)
1170 1.1.1.2 christos {
1171 1.1.1.2 christos case BFD_MACH_O_S_SYMBOL_STUBS:
1172 1.1.1.2 christos case BFD_MACH_O_S_LAZY_SYMBOL_POINTERS:
1173 1.1.1.2 christos case BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS:
1174 1.1.1.2 christos {
1175 1.1.1.2 christos obj_mach_o_indirect_sym *isym;
1176 1.1.1.3 christos char *name;
1177 1.1.1.3 christos char c = get_symbol_name (&name);
1178 1.1.1.2 christos symbolS *sym = symbol_find_or_make (name);
1179 1.1.1.2 christos unsigned int elsize =
1180 1.1.1.2 christos bfd_mach_o_section_get_entry_size (stdoutput, sec);
1181 1.1.1.2 christos
1182 1.1.1.2 christos if (elsize == 0)
1183 1.1.1.2 christos {
1184 1.1.1.2 christos as_bad (_("attempt to add an indirect_symbol to a stub or"
1185 1.1.1.2 christos " reference section with a zero-sized element at %s"),
1186 1.1.1.2 christos name);
1187 1.1.1.3 christos (void) restore_line_pointer (c);
1188 1.1.1.2 christos ignore_rest_of_line ();
1189 1.1.1.2 christos return;
1190 1.1.1.3 christos }
1191 1.1.1.3 christos (void) restore_line_pointer (c);
1192 1.1.1.2 christos
1193 1.1.1.3 christos /* The indirect symbols are validated after the symbol table is
1194 1.1.1.3 christos frozen, we must make sure that if a local symbol is used as an
1195 1.1.1.2 christos indirect, it is promoted to a 'real' one. Fetching the bfd sym
1196 1.1.1.2 christos achieves this. */
1197 1.1.1.2 christos symbol_get_bfdsym (sym);
1198 1.1.1.4 christos isym = XNEW (obj_mach_o_indirect_sym);
1199 1.1.1.2 christos
1200 1.1.1.2 christos /* Just record the data for now, we will validate it when we
1201 1.1.1.2 christos compute the output in obj_mach_o_set_indirect_symbols. */
1202 1.1.1.2 christos isym->sym = sym;
1203 1.1.1.2 christos isym->sect = now_seg;
1204 1.1.1.2 christos isym->next = NULL;
1205 1.1.1.2 christos if (indirect_syms == NULL)
1206 1.1.1.2 christos indirect_syms = isym;
1207 1.1.1.2 christos else
1208 1.1.1.2 christos indirect_syms_tail->next = isym;
1209 1.1.1.2 christos indirect_syms_tail = isym;
1210 1.1.1.2 christos }
1211 1.1 christos break;
1212 1.1.1.2 christos
1213 1.1.1.2 christos default:
1214 1.1.1.2 christos as_bad (_("an .indirect_symbol must be in a symbol pointer"
1215 1.1.1.2 christos " or stub section."));
1216 1.1.1.2 christos ignore_rest_of_line ();
1217 1.1.1.2 christos return;
1218 1.1 christos }
1219 1.1 christos demand_empty_rest_of_line ();
1220 1.1 christos }
1221 1.1 christos
1222 1.1 christos const pseudo_typeS mach_o_pseudo_table[] =
1223 1.1 christos {
1224 1.1.1.2 christos /* Section directives. */
1225 1.1.1.2 christos { "comm", obj_mach_o_comm, 0 },
1226 1.1.1.2 christos { "lcomm", obj_mach_o_comm, 1 },
1227 1.1.1.2 christos
1228 1.1.1.2 christos { "text", obj_mach_o_base_section, 1},
1229 1.1.1.2 christos { "data", obj_mach_o_base_section, 2},
1230 1.1.1.2 christos { "bss", obj_mach_o_base_section, 3}, /* extension */
1231 1.1.1.2 christos
1232 1.1.1.2 christos { "const", obj_mach_o_known_section, 1},
1233 1.1.1.2 christos { "static_const", obj_mach_o_known_section, 2},
1234 1.1.1.2 christos { "cstring", obj_mach_o_known_section, 3},
1235 1.1.1.2 christos { "literal4", obj_mach_o_known_section, 4},
1236 1.1.1.2 christos { "literal8", obj_mach_o_known_section, 5},
1237 1.1.1.2 christos { "literal16", obj_mach_o_known_section, 6},
1238 1.1.1.2 christos { "constructor", obj_mach_o_known_section, 7},
1239 1.1.1.2 christos { "destructor", obj_mach_o_known_section, 8},
1240 1.1.1.2 christos { "eh_frame", obj_mach_o_known_section, 9},
1241 1.1.1.2 christos
1242 1.1.1.2 christos { "const_data", obj_mach_o_known_section, 10},
1243 1.1.1.2 christos { "static_data", obj_mach_o_known_section, 11},
1244 1.1.1.2 christos { "mod_init_func", obj_mach_o_known_section, 12},
1245 1.1.1.2 christos { "mod_term_func", obj_mach_o_known_section, 13},
1246 1.1.1.2 christos { "dyld", obj_mach_o_known_section, 14},
1247 1.1.1.2 christos { "cfstring", obj_mach_o_known_section, 15},
1248 1.1.1.2 christos
1249 1.1.1.2 christos { "objc_class", obj_mach_o_objc_section, 1},
1250 1.1.1.2 christos { "objc_meta_class", obj_mach_o_objc_section, 2},
1251 1.1.1.2 christos { "objc_cat_cls_meth", obj_mach_o_objc_section, 3},
1252 1.1.1.2 christos { "objc_cat_inst_meth", obj_mach_o_objc_section, 4},
1253 1.1.1.2 christos { "objc_protocol", obj_mach_o_objc_section, 5},
1254 1.1.1.2 christos { "objc_string_object", obj_mach_o_objc_section, 6},
1255 1.1.1.2 christos { "objc_cls_meth", obj_mach_o_objc_section, 7},
1256 1.1.1.2 christos { "objc_inst_meth", obj_mach_o_objc_section, 8},
1257 1.1.1.2 christos { "objc_cls_refs", obj_mach_o_objc_section, 9},
1258 1.1.1.2 christos { "objc_message_refs", obj_mach_o_objc_section, 10},
1259 1.1.1.2 christos { "objc_symbols", obj_mach_o_objc_section, 11},
1260 1.1.1.2 christos { "objc_category", obj_mach_o_objc_section, 12},
1261 1.1.1.2 christos { "objc_class_vars", obj_mach_o_objc_section, 13},
1262 1.1.1.2 christos { "objc_instance_vars", obj_mach_o_objc_section, 14},
1263 1.1.1.2 christos { "objc_module_info", obj_mach_o_objc_section, 15},
1264 1.1.1.2 christos { "objc_class_names", obj_mach_o_objc_section, 16}, /* Alias for .cstring */
1265 1.1.1.2 christos { "objc_meth_var_types", obj_mach_o_objc_section, 17}, /* Alias for .cstring */
1266 1.1.1.2 christos { "objc_meth_var_names", obj_mach_o_objc_section, 18}, /* Alias for .cstring */
1267 1.1.1.2 christos { "objc_selector_strs", obj_mach_o_objc_section, 19},
1268 1.1.1.2 christos { "objc_image_info", obj_mach_o_objc_section, 20}, /* extension. */
1269 1.1.1.2 christos { "objc_selector_fixup", obj_mach_o_objc_section, 21}, /* extension. */
1270 1.1.1.2 christos { "objc1_class_ext", obj_mach_o_objc_section, 22}, /* ObjC-1 extension. */
1271 1.1.1.2 christos { "objc1_property_list", obj_mach_o_objc_section, 23}, /* ObjC-1 extension. */
1272 1.1.1.2 christos { "objc1_protocol_ext", obj_mach_o_objc_section, 24}, /* ObjC-1 extension. */
1273 1.1.1.2 christos
1274 1.1.1.2 christos { "debug_frame", obj_mach_o_debug_section, 1}, /* extension. */
1275 1.1.1.2 christos { "debug_info", obj_mach_o_debug_section, 2}, /* extension. */
1276 1.1.1.2 christos { "debug_abbrev", obj_mach_o_debug_section, 3}, /* extension. */
1277 1.1.1.2 christos { "debug_aranges", obj_mach_o_debug_section, 4}, /* extension. */
1278 1.1.1.2 christos { "debug_macinfo", obj_mach_o_debug_section, 5}, /* extension. */
1279 1.1.1.2 christos { "debug_line", obj_mach_o_debug_section, 6}, /* extension. */
1280 1.1.1.2 christos { "debug_loc", obj_mach_o_debug_section, 7}, /* extension. */
1281 1.1.1.2 christos { "debug_pubnames", obj_mach_o_debug_section, 8}, /* extension. */
1282 1.1.1.2 christos { "debug_pubtypes", obj_mach_o_debug_section, 9}, /* extension. */
1283 1.1.1.2 christos { "debug_str", obj_mach_o_debug_section, 10}, /* extension. */
1284 1.1.1.2 christos { "debug_ranges", obj_mach_o_debug_section, 11}, /* extension. */
1285 1.1.1.2 christos { "debug_macro", obj_mach_o_debug_section, 12}, /* extension. */
1286 1.1.1.3 christos
1287 1.1.1.2 christos { "lazy_symbol_pointer", obj_mach_o_opt_tgt_section, 1},
1288 1.1.1.2 christos { "lazy_symbol_pointer2", obj_mach_o_opt_tgt_section, 2}, /* extension. */
1289 1.1.1.2 christos { "lazy_symbol_pointer3", obj_mach_o_opt_tgt_section, 3}, /* extension. */
1290 1.1.1.2 christos { "non_lazy_symbol_pointer", obj_mach_o_opt_tgt_section, 4},
1291 1.1.1.2 christos { "non_lazy_symbol_pointer_x86", obj_mach_o_opt_tgt_section, 5}, /* extension. */
1292 1.1.1.2 christos { "symbol_stub", obj_mach_o_opt_tgt_section, 6},
1293 1.1.1.2 christos { "symbol_stub1", obj_mach_o_opt_tgt_section, 7}, /* extension. */
1294 1.1.1.2 christos { "picsymbol_stub", obj_mach_o_opt_tgt_section, 8}, /* extension. */
1295 1.1.1.2 christos { "picsymbol_stub1", obj_mach_o_opt_tgt_section, 9}, /* extension. */
1296 1.1.1.2 christos { "picsymbol_stub2", obj_mach_o_opt_tgt_section, 4}, /* extension. */
1297 1.1.1.2 christos { "picsymbol_stub3", obj_mach_o_opt_tgt_section, 4}, /* extension. */
1298 1.1.1.2 christos
1299 1.1.1.2 christos { "section", obj_mach_o_section, 0},
1300 1.1.1.2 christos { "zerofill", obj_mach_o_zerofill, 0},
1301 1.1.1.2 christos
1302 1.1.1.2 christos /* Symbol qualifiers. */
1303 1.1.1.2 christos {"local", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_LOCAL},
1304 1.1.1.2 christos {"globl", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_GLOBL},
1305 1.1.1.2 christos {"reference", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_REFERENCE},
1306 1.1.1.2 christos {"weak_reference", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_WEAK_REF},
1307 1.1.1.2 christos {"lazy_reference", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_LAZY_REF},
1308 1.1.1.2 christos {"weak_definition", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_WEAK_DEF},
1309 1.1.1.2 christos {"private_extern", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_PRIV_EXT},
1310 1.1.1.2 christos {"no_dead_strip", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_NO_DEAD_STRIP},
1311 1.1.1.2 christos {"weak", obj_mach_o_sym_qual, OBJ_MACH_O_SYM_WEAK}, /* ext */
1312 1.1.1.2 christos
1313 1.1.1.2 christos { "indirect_symbol", obj_mach_o_indirect_symbol, 0},
1314 1.1.1.2 christos
1315 1.1.1.2 christos /* File flags. */
1316 1.1.1.3 christos { "subsections_via_symbols", obj_mach_o_fileprop,
1317 1.1.1.2 christos OBJ_MACH_O_FILE_PROP_SUBSECTS_VIA_SYMS},
1318 1.1 christos
1319 1.1 christos {NULL, NULL, 0}
1320 1.1 christos };
1321 1.1.1.2 christos
1322 1.1.1.2 christos /* Determine the default n_type value for a symbol from its section. */
1323 1.1.1.2 christos
1324 1.1.1.2 christos static unsigned
1325 1.1.1.2 christos obj_mach_o_type_for_symbol (bfd_mach_o_asymbol *s)
1326 1.1.1.2 christos {
1327 1.1.1.2 christos if (s->symbol.section == bfd_abs_section_ptr)
1328 1.1.1.2 christos return BFD_MACH_O_N_ABS;
1329 1.1.1.2 christos else if (s->symbol.section == bfd_com_section_ptr
1330 1.1.1.2 christos || s->symbol.section == bfd_und_section_ptr)
1331 1.1.1.2 christos return BFD_MACH_O_N_UNDF;
1332 1.1.1.2 christos else
1333 1.1.1.2 christos return BFD_MACH_O_N_SECT;
1334 1.1.1.2 christos }
1335 1.1.1.2 christos
1336 1.1.1.2 christos void
1337 1.1.1.2 christos obj_mach_o_frob_colon (const char *name)
1338 1.1.1.2 christos {
1339 1.1.1.2 christos if (!bfd_is_local_label_name (stdoutput, name))
1340 1.1.1.2 christos {
1341 1.1.1.2 christos /* A non-local label will create a new subsection, so start a new
1342 1.1.1.2 christos frag. */
1343 1.1.1.2 christos frag_wane (frag_now);
1344 1.1.1.2 christos frag_new (0);
1345 1.1.1.2 christos }
1346 1.1.1.2 christos }
1347 1.1.1.2 christos
1348 1.1.1.2 christos /* We need to check the correspondence between some kinds of symbols and their
1349 1.1.1.2 christos sections. Common and BSS vars will seen via the obj_macho_comm() function.
1350 1.1.1.3 christos
1351 1.1.1.2 christos The earlier we can pick up a problem, the better the diagnostics will be.
1352 1.1.1.3 christos
1353 1.1.1.2 christos However, when symbol type information is attached, the symbol section will
1354 1.1.1.2 christos quite possibly be unknown. So we are stuck with checking (most of the)
1355 1.1.1.2 christos validity at the time the file is written (unfortunately, then one doesn't
1356 1.1.1.2 christos get line number information in the diagnostic). */
1357 1.1.1.2 christos
1358 1.1.1.2 christos /* Here we pick up the case where symbol qualifiers have been applied that
1359 1.1.1.2 christos are possibly incompatible with the section etc. that the symbol is defined
1360 1.1.1.2 christos in. */
1361 1.1.1.2 christos
1362 1.1.1.2 christos void obj_mach_o_frob_label (struct symbol *sp)
1363 1.1.1.2 christos {
1364 1.1.1.2 christos bfd_mach_o_asymbol *s;
1365 1.1.1.2 christos unsigned base_type;
1366 1.1.1.2 christos bfd_mach_o_section *sec;
1367 1.1.1.2 christos int sectype = -1;
1368 1.1.1.2 christos
1369 1.1.1.2 christos if (!bfd_is_local_label_name (stdoutput, S_GET_NAME (sp)))
1370 1.1.1.2 christos {
1371 1.1.1.2 christos /* If this is a non-local label, it should have started a new sub-
1372 1.1.1.2 christos section. */
1373 1.1.1.2 christos gas_assert (frag_now->obj_frag_data.subsection == NULL);
1374 1.1.1.2 christos frag_now->obj_frag_data.subsection = sp;
1375 1.1.1.2 christos }
1376 1.1.1.2 christos
1377 1.1.1.2 christos /* Leave local symbols alone. */
1378 1.1.1.2 christos
1379 1.1.1.2 christos if (S_IS_LOCAL (sp))
1380 1.1.1.2 christos return;
1381 1.1.1.2 christos
1382 1.1.1.2 christos s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (sp);
1383 1.1.1.2 christos /* Leave debug symbols alone. */
1384 1.1.1.2 christos if ((s->n_type & BFD_MACH_O_N_STAB) != 0)
1385 1.1.1.2 christos return;
1386 1.1.1.2 christos
1387 1.1.1.2 christos /* This is the base symbol type, that we mask in. */
1388 1.1.1.2 christos base_type = obj_mach_o_type_for_symbol (s);
1389 1.1.1.2 christos
1390 1.1.1.3 christos sec = bfd_mach_o_get_mach_o_section (s->symbol.section);
1391 1.1.1.2 christos if (sec != NULL)
1392 1.1.1.2 christos sectype = sec->flags & BFD_MACH_O_SECTION_TYPE_MASK;
1393 1.1.1.2 christos
1394 1.1.1.2 christos /* If there is a pre-existing qualifier, we can make some checks about
1395 1.1.1.2 christos validity now. */
1396 1.1.1.2 christos
1397 1.1.1.2 christos if(s->symbol.udata.i == SYM_MACHO_FIELDS_NOT_VALIDATED)
1398 1.1.1.2 christos {
1399 1.1.1.2 christos if ((s->n_desc & BFD_MACH_O_N_WEAK_DEF)
1400 1.1.1.2 christos && sectype != BFD_MACH_O_S_COALESCED)
1401 1.1.1.3 christos {
1402 1.1.1.3 christos as_bad (_("'%s' can't be a weak_definition (currently only supported"
1403 1.1.1.3 christos " in sections of type coalesced)"), s->symbol.name);
1404 1.1.1.3 christos /* Don't cascade errors. */
1405 1.1.1.3 christos s->symbol.udata.i = SYM_MACHO_FIELDS_UNSET;
1406 1.1.1.3 christos }
1407 1.1.1.2 christos
1408 1.1.1.2 christos /* Have we changed from an undefined to defined ref? */
1409 1.1.1.2 christos s->n_desc &= ~(REFE | LAZY);
1410 1.1.1.2 christos }
1411 1.1.1.2 christos
1412 1.1.1.2 christos s->n_type &= ~BFD_MACH_O_N_TYPE;
1413 1.1.1.2 christos s->n_type |= base_type;
1414 1.1.1.2 christos }
1415 1.1.1.2 christos
1416 1.1.1.2 christos /* This is the fall-back, we come here when we get to the end of the file and
1417 1.1.1.2 christos the symbol is not defined - or there are combinations of qualifiers required
1418 1.1.1.2 christos (e.g. global + weak_def). */
1419 1.1.1.2 christos
1420 1.1.1.2 christos int
1421 1.1.1.2 christos obj_mach_o_frob_symbol (struct symbol *sp)
1422 1.1.1.2 christos {
1423 1.1.1.2 christos bfd_mach_o_asymbol *s;
1424 1.1.1.2 christos unsigned base_type;
1425 1.1.1.2 christos bfd_mach_o_section *sec;
1426 1.1.1.2 christos int sectype = -1;
1427 1.1.1.2 christos
1428 1.1.1.2 christos /* Leave local symbols alone. */
1429 1.1.1.2 christos if (S_IS_LOCAL (sp))
1430 1.1.1.2 christos return 0;
1431 1.1.1.2 christos
1432 1.1.1.2 christos s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (sp);
1433 1.1.1.2 christos /* Leave debug symbols alone. */
1434 1.1.1.2 christos if ((s->n_type & BFD_MACH_O_N_STAB) != 0)
1435 1.1.1.2 christos return 0;
1436 1.1.1.2 christos
1437 1.1.1.2 christos base_type = obj_mach_o_type_for_symbol (s);
1438 1.1.1.3 christos sec = bfd_mach_o_get_mach_o_section (s->symbol.section);
1439 1.1.1.2 christos if (sec != NULL)
1440 1.1.1.2 christos sectype = sec->flags & BFD_MACH_O_SECTION_TYPE_MASK;
1441 1.1.1.2 christos
1442 1.1.1.2 christos if (s->symbol.section == bfd_und_section_ptr)
1443 1.1.1.2 christos {
1444 1.1.1.2 christos /* ??? Do we really gain much from implementing this as well as the
1445 1.1.1.2 christos mach-o specific ones? */
1446 1.1.1.2 christos if (s->symbol.flags & BSF_WEAK)
1447 1.1.1.2 christos s->n_desc |= BFD_MACH_O_N_WEAK_REF;
1448 1.1.1.2 christos
1449 1.1.1.2 christos /* Undefined syms, become extern. */
1450 1.1.1.2 christos s->n_type |= BFD_MACH_O_N_EXT;
1451 1.1.1.2 christos S_SET_EXTERNAL (sp);
1452 1.1.1.2 christos }
1453 1.1.1.2 christos else if (s->symbol.section == bfd_com_section_ptr)
1454 1.1.1.2 christos {
1455 1.1.1.2 christos /* ... so do comm. */
1456 1.1.1.2 christos s->n_type |= BFD_MACH_O_N_EXT;
1457 1.1.1.2 christos S_SET_EXTERNAL (sp);
1458 1.1.1.2 christos }
1459 1.1.1.2 christos else
1460 1.1.1.2 christos {
1461 1.1.1.2 christos if ((s->symbol.flags & BSF_WEAK)
1462 1.1.1.2 christos && (sectype == BFD_MACH_O_S_COALESCED)
1463 1.1.1.2 christos && (s->n_type & (BFD_MACH_O_N_PEXT | BFD_MACH_O_N_EXT)))
1464 1.1.1.2 christos s->n_desc |= BFD_MACH_O_N_WEAK_DEF;
1465 1.1.1.2 christos /* ??? we should do this - but then that reveals that the semantics of weak
1466 1.1.1.2 christos are different from what's supported in mach-o object files.
1467 1.1.1.2 christos else
1468 1.1.1.2 christos as_bad (_("'%s' can't be a weak_definition."),
1469 1.1.1.2 christos s->symbol.name); */
1470 1.1.1.2 christos }
1471 1.1.1.2 christos
1472 1.1.1.2 christos if (s->symbol.udata.i == SYM_MACHO_FIELDS_UNSET)
1473 1.1.1.2 christos {
1474 1.1.1.2 christos /* Anything here that should be added that is non-standard. */
1475 1.1.1.2 christos s->n_desc &= ~BFD_MACH_O_REFERENCE_MASK;
1476 1.1.1.3 christos }
1477 1.1.1.2 christos else if (s->symbol.udata.i == SYM_MACHO_FIELDS_NOT_VALIDATED)
1478 1.1.1.2 christos {
1479 1.1.1.2 christos /* Try to validate any combinations. */
1480 1.1.1.2 christos if (s->n_desc & BFD_MACH_O_N_WEAK_DEF)
1481 1.1.1.2 christos {
1482 1.1.1.2 christos if (s->symbol.section == bfd_und_section_ptr)
1483 1.1.1.2 christos as_bad (_("'%s' can't be a weak_definition (since it is"
1484 1.1.1.2 christos " undefined)"), s->symbol.name);
1485 1.1.1.2 christos else if (sectype != BFD_MACH_O_S_COALESCED)
1486 1.1.1.2 christos as_bad (_("'%s' can't be a weak_definition (currently only supported"
1487 1.1.1.2 christos " in sections of type coalesced)"), s->symbol.name);
1488 1.1.1.2 christos else if (! (s->n_type & (BFD_MACH_O_N_PEXT | BFD_MACH_O_N_EXT)))
1489 1.1.1.2 christos as_bad (_("Non-global symbol: '%s' can't be a weak_definition."),
1490 1.1.1.2 christos s->symbol.name);
1491 1.1.1.2 christos }
1492 1.1.1.2 christos
1493 1.1.1.2 christos }
1494 1.1.1.2 christos else
1495 1.1.1.2 christos as_bad (_("internal error: [%s] unexpected code [%lx] in frob symbol"),
1496 1.1.1.2 christos s->symbol.name, (unsigned long)s->symbol.udata.i);
1497 1.1.1.2 christos
1498 1.1.1.2 christos s->n_type &= ~BFD_MACH_O_N_TYPE;
1499 1.1.1.2 christos s->n_type |= base_type;
1500 1.1.1.2 christos
1501 1.1.1.2 christos if (s->symbol.flags & BSF_GLOBAL)
1502 1.1.1.2 christos s->n_type |= BFD_MACH_O_N_EXT;
1503 1.1.1.2 christos
1504 1.1.1.2 christos /* This cuts both ways - we promote some things to external above. */
1505 1.1.1.2 christos if (s->n_type & (BFD_MACH_O_N_PEXT | BFD_MACH_O_N_EXT))
1506 1.1.1.2 christos S_SET_EXTERNAL (sp);
1507 1.1.1.2 christos
1508 1.1.1.2 christos return 0;
1509 1.1.1.2 christos }
1510 1.1.1.2 christos
1511 1.1.1.2 christos /* Support stabs for mach-o. */
1512 1.1.1.2 christos
1513 1.1.1.2 christos void
1514 1.1.1.2 christos obj_mach_o_process_stab (int what, const char *string,
1515 1.1.1.2 christos int type, int other, int desc)
1516 1.1.1.2 christos {
1517 1.1.1.2 christos symbolS *symbolP;
1518 1.1.1.2 christos bfd_mach_o_asymbol *s;
1519 1.1.1.2 christos
1520 1.1.1.2 christos switch (what)
1521 1.1.1.2 christos {
1522 1.1.1.2 christos case 'd':
1523 1.1.1.2 christos symbolP = symbol_new ("", now_seg, frag_now_fix (), frag_now);
1524 1.1.1.2 christos /* Special stabd NULL name indicator. */
1525 1.1.1.2 christos S_SET_NAME (symbolP, NULL);
1526 1.1.1.2 christos break;
1527 1.1.1.2 christos
1528 1.1.1.2 christos case 'n':
1529 1.1.1.2 christos case 's':
1530 1.1.1.2 christos symbolP = symbol_new (string, undefined_section, (valueT) 0,
1531 1.1.1.2 christos &zero_address_frag);
1532 1.1.1.2 christos pseudo_set (symbolP);
1533 1.1.1.2 christos break;
1534 1.1.1.2 christos
1535 1.1.1.2 christos default:
1536 1.1.1.2 christos as_bad(_("unrecognized stab type '%c'"), (char)what);
1537 1.1.1.2 christos abort ();
1538 1.1.1.2 christos break;
1539 1.1.1.2 christos }
1540 1.1.1.2 christos
1541 1.1.1.2 christos s = (bfd_mach_o_asymbol *) symbol_get_bfdsym (symbolP);
1542 1.1.1.2 christos s->n_type = type;
1543 1.1.1.2 christos s->n_desc = desc;
1544 1.1.1.2 christos /* For stabd, this will eventually get overwritten by the section number. */
1545 1.1.1.2 christos s->n_sect = other;
1546 1.1.1.2 christos
1547 1.1.1.2 christos /* It's a debug symbol. */
1548 1.1.1.2 christos s->symbol.flags |= BSF_DEBUGGING;
1549 1.1.1.3 christos
1550 1.1.1.2 christos /* We've set it - so check it, if you can, but don't try to create the
1551 1.1.1.2 christos flags. */
1552 1.1.1.2 christos s->symbol.udata.i = SYM_MACHO_FIELDS_NOT_VALIDATED;
1553 1.1.1.2 christos }
1554 1.1.1.2 christos
1555 1.1.1.2 christos /* This is a place to check for any errors that we can't detect until we know
1556 1.1.1.2 christos what remains undefined at the end of assembly. */
1557 1.1.1.2 christos
1558 1.1.1.2 christos static void
1559 1.1.1.2 christos obj_mach_o_check_before_writing (bfd *abfd ATTRIBUTE_UNUSED,
1560 1.1.1.2 christos asection *sec,
1561 1.1.1.2 christos void *unused ATTRIBUTE_UNUSED)
1562 1.1.1.2 christos {
1563 1.1.1.2 christos fixS *fixP;
1564 1.1.1.2 christos struct frchain *frchp;
1565 1.1.1.2 christos segment_info_type *seginfo = seg_info (sec);
1566 1.1.1.2 christos
1567 1.1.1.2 christos if (seginfo == NULL)
1568 1.1.1.2 christos return;
1569 1.1.1.2 christos
1570 1.1.1.2 christos /* We are not allowed subtractions where either of the operands is
1571 1.1.1.2 christos undefined. So look through the frags for any fixes to check. */
1572 1.1.1.2 christos for (frchp = seginfo->frchainP; frchp != NULL; frchp = frchp->frch_next)
1573 1.1.1.2 christos for (fixP = frchp->fix_root; fixP != NULL; fixP = fixP->fx_next)
1574 1.1.1.2 christos {
1575 1.1.1.2 christos if (fixP->fx_addsy != NULL
1576 1.1.1.2 christos && fixP->fx_subsy != NULL
1577 1.1.1.2 christos && (! S_IS_DEFINED (fixP->fx_addsy)
1578 1.1.1.2 christos || ! S_IS_DEFINED (fixP->fx_subsy)))
1579 1.1.1.2 christos {
1580 1.1.1.2 christos segT add_symbol_segment = S_GET_SEGMENT (fixP->fx_addsy);
1581 1.1.1.2 christos segT sub_symbol_segment = S_GET_SEGMENT (fixP->fx_subsy);
1582 1.1.1.2 christos
1583 1.1.1.2 christos if (! S_IS_DEFINED (fixP->fx_addsy)
1584 1.1.1.2 christos && S_IS_DEFINED (fixP->fx_subsy))
1585 1.1.1.2 christos {
1586 1.1.1.2 christos as_bad_where (fixP->fx_file, fixP->fx_line,
1587 1.1.1.2 christos _("`%s' can't be undefined in `%s' - `%s' {%s section}"),
1588 1.1.1.2 christos S_GET_NAME (fixP->fx_addsy), S_GET_NAME (fixP->fx_addsy),
1589 1.1.1.2 christos S_GET_NAME (fixP->fx_subsy), segment_name (sub_symbol_segment));
1590 1.1.1.2 christos }
1591 1.1.1.2 christos else if (! S_IS_DEFINED (fixP->fx_subsy)
1592 1.1.1.2 christos && S_IS_DEFINED (fixP->fx_addsy))
1593 1.1.1.2 christos {
1594 1.1.1.2 christos as_bad_where (fixP->fx_file, fixP->fx_line,
1595 1.1.1.2 christos _("`%s' can't be undefined in `%s' {%s section} - `%s'"),
1596 1.1.1.2 christos S_GET_NAME (fixP->fx_subsy), S_GET_NAME (fixP->fx_addsy),
1597 1.1.1.2 christos segment_name (add_symbol_segment), S_GET_NAME (fixP->fx_subsy));
1598 1.1.1.2 christos }
1599 1.1.1.2 christos else
1600 1.1.1.2 christos {
1601 1.1.1.2 christos as_bad_where (fixP->fx_file, fixP->fx_line,
1602 1.1.1.2 christos _("`%s' and `%s' can't be undefined in `%s' - `%s'"),
1603 1.1.1.2 christos S_GET_NAME (fixP->fx_addsy), S_GET_NAME (fixP->fx_subsy),
1604 1.1.1.2 christos S_GET_NAME (fixP->fx_addsy), S_GET_NAME (fixP->fx_subsy));
1605 1.1.1.2 christos }
1606 1.1.1.2 christos }
1607 1.1.1.2 christos }
1608 1.1.1.2 christos }
1609 1.1.1.2 christos
1610 1.1.1.2 christos /* Do any checks that we can't complete without knowing what's undefined. */
1611 1.1.1.2 christos void
1612 1.1.1.2 christos obj_mach_o_pre_output_hook (void)
1613 1.1.1.2 christos {
1614 1.1.1.2 christos bfd_map_over_sections (stdoutput, obj_mach_o_check_before_writing, (char *) 0);
1615 1.1.1.2 christos }
1616 1.1.1.2 christos
1617 1.1.1.2 christos /* Here we count up frags in each subsection (where a sub-section is defined
1618 1.1.1.2 christos as starting with a non-local symbol).
1619 1.1.1.2 christos Note that, if there are no non-local symbols in a section, all the frags will
1620 1.1.1.2 christos be attached as one anonymous subsection. */
1621 1.1.1.2 christos
1622 1.1.1.2 christos static void
1623 1.1.1.2 christos obj_mach_o_set_subsections (bfd *abfd ATTRIBUTE_UNUSED,
1624 1.1.1.2 christos asection *sec,
1625 1.1.1.2 christos void *unused ATTRIBUTE_UNUSED)
1626 1.1.1.2 christos {
1627 1.1.1.2 christos segment_info_type *seginfo = seg_info (sec);
1628 1.1.1.2 christos symbolS *cur_subsection = NULL;
1629 1.1.1.2 christos struct obj_mach_o_symbol_data *cur_subsection_data = NULL;
1630 1.1.1.2 christos fragS *frag;
1631 1.1.1.2 christos frchainS *chain;
1632 1.1.1.2 christos
1633 1.1.1.2 christos /* Protect against sections not created by gas. */
1634 1.1.1.2 christos if (seginfo == NULL)
1635 1.1.1.2 christos return;
1636 1.1.1.2 christos
1637 1.1.1.2 christos /* Attach every frag to a subsection. */
1638 1.1.1.2 christos for (chain = seginfo->frchainP; chain != NULL; chain = chain->frch_next)
1639 1.1.1.2 christos for (frag = chain->frch_root; frag != NULL; frag = frag->fr_next)
1640 1.1.1.2 christos {
1641 1.1.1.2 christos if (frag->obj_frag_data.subsection == NULL)
1642 1.1.1.2 christos frag->obj_frag_data.subsection = cur_subsection;
1643 1.1.1.2 christos else
1644 1.1.1.2 christos {
1645 1.1.1.2 christos cur_subsection = frag->obj_frag_data.subsection;
1646 1.1.1.2 christos cur_subsection_data = symbol_get_obj (cur_subsection);
1647 1.1.1.2 christos cur_subsection_data->subsection_size = 0;
1648 1.1.1.2 christos }
1649 1.1.1.2 christos if (cur_subsection_data != NULL)
1650 1.1.1.2 christos {
1651 1.1.1.2 christos /* Update subsection size. */
1652 1.1.1.2 christos cur_subsection_data->subsection_size += frag->fr_fix;
1653 1.1.1.2 christos }
1654 1.1.1.2 christos }
1655 1.1.1.2 christos }
1656 1.1.1.2 christos
1657 1.1.1.3 christos /* Handle mach-o subsections-via-symbols counting up frags belonging to each
1658 1.1.1.2 christos sub-section. */
1659 1.1.1.2 christos
1660 1.1.1.2 christos void
1661 1.1.1.2 christos obj_mach_o_pre_relax_hook (void)
1662 1.1.1.2 christos {
1663 1.1.1.2 christos bfd_map_over_sections (stdoutput, obj_mach_o_set_subsections, (char *) 0);
1664 1.1.1.2 christos }
1665 1.1.1.2 christos
1666 1.1.1.2 christos /* Zerofill and GB Zerofill sections must be sorted to follow all other
1667 1.1.1.2 christos sections in their segments.
1668 1.1.1.2 christos
1669 1.1.1.2 christos The native 'as' leaves the sections physically in the order they appear in
1670 1.1.1.2 christos the source, and adjusts the section VMAs to meet the constraint.
1671 1.1.1.3 christos
1672 1.1.1.2 christos We follow this for now - if nothing else, it makes comparison easier.
1673 1.1.1.2 christos
1674 1.1.1.2 christos An alternative implementation would be to sort the sections as ld requires.
1675 1.1.1.2 christos It might be advantageous to implement such a scheme in the future (or even
1676 1.1.1.2 christos to make the style of section ordering user-selectable). */
1677 1.1.1.2 christos
1678 1.1.1.2 christos typedef struct obj_mach_o_set_vma_data
1679 1.1.1.2 christos {
1680 1.1.1.2 christos bfd_vma vma;
1681 1.1.1.2 christos unsigned vma_pass;
1682 1.1.1.2 christos unsigned zerofill_seen;
1683 1.1.1.2 christos unsigned gb_zerofill_seen;
1684 1.1.1.2 christos } obj_mach_o_set_vma_data;
1685 1.1.1.2 christos
1686 1.1.1.2 christos /* We do (possibly) three passes through to set the vma, so that:
1687 1.1.1.2 christos
1688 1.1.1.2 christos zerofill sections get VMAs after all others in their segment
1689 1.1.1.2 christos GB zerofill get VMAs last.
1690 1.1.1.3 christos
1691 1.1.1.2 christos As we go, we notice if we see any Zerofill or GB Zerofill sections, so that
1692 1.1.1.2 christos we can skip the additional passes if there's nothing to do. */
1693 1.1.1.2 christos
1694 1.1.1.2 christos static void
1695 1.1.1.2 christos obj_mach_o_set_section_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *v_p)
1696 1.1.1.2 christos {
1697 1.1.1.2 christos bfd_mach_o_section *ms = bfd_mach_o_get_mach_o_section (sec);
1698 1.1.1.2 christos unsigned bfd_align = bfd_get_section_alignment (abfd, sec);
1699 1.1.1.2 christos obj_mach_o_set_vma_data *p = (struct obj_mach_o_set_vma_data *)v_p;
1700 1.1.1.2 christos unsigned sectype = (ms->flags & BFD_MACH_O_SECTION_TYPE_MASK);
1701 1.1.1.2 christos unsigned zf;
1702 1.1.1.2 christos
1703 1.1.1.2 christos zf = 0;
1704 1.1.1.2 christos if (sectype == BFD_MACH_O_S_ZEROFILL)
1705 1.1.1.2 christos {
1706 1.1.1.2 christos zf = 1;
1707 1.1.1.2 christos p->zerofill_seen = zf;
1708 1.1.1.2 christos }
1709 1.1.1.2 christos else if (sectype == BFD_MACH_O_S_GB_ZEROFILL)
1710 1.1.1.2 christos {
1711 1.1.1.2 christos zf = 2;
1712 1.1.1.2 christos p->gb_zerofill_seen = zf;
1713 1.1.1.2 christos }
1714 1.1.1.2 christos
1715 1.1.1.2 christos if (p->vma_pass != zf)
1716 1.1.1.2 christos return;
1717 1.1.1.2 christos
1718 1.1.1.2 christos /* We know the section size now - so make a vma for the section just
1719 1.1.1.2 christos based on order. */
1720 1.1.1.2 christos ms->size = bfd_get_section_size (sec);
1721 1.1.1.3 christos
1722 1.1.1.2 christos /* Make sure that the align agrees, and set to the largest value chosen. */
1723 1.1.1.2 christos ms->align = ms->align > bfd_align ? ms->align : bfd_align;
1724 1.1.1.2 christos bfd_set_section_alignment (abfd, sec, ms->align);
1725 1.1.1.3 christos
1726 1.1.1.2 christos p->vma += (1 << ms->align) - 1;
1727 1.1.1.2 christos p->vma &= ~((1 << ms->align) - 1);
1728 1.1.1.2 christos ms->addr = p->vma;
1729 1.1.1.2 christos bfd_set_section_vma (abfd, sec, p->vma);
1730 1.1.1.2 christos p->vma += ms->size;
1731 1.1.1.2 christos }
1732 1.1.1.2 christos
1733 1.1.1.3 christos /* (potentially) three passes over the sections, setting VMA. We skip the
1734 1.1.1.2 christos {gb}zerofill passes if we didn't see any of the relevant sections. */
1735 1.1.1.2 christos
1736 1.1.1.2 christos void obj_mach_o_post_relax_hook (void)
1737 1.1.1.2 christos {
1738 1.1.1.2 christos obj_mach_o_set_vma_data d;
1739 1.1.1.2 christos
1740 1.1.1.2 christos memset (&d, 0, sizeof (d));
1741 1.1.1.3 christos
1742 1.1.1.2 christos bfd_map_over_sections (stdoutput, obj_mach_o_set_section_vma, (char *) &d);
1743 1.1.1.2 christos if ((d.vma_pass = d.zerofill_seen) != 0)
1744 1.1.1.2 christos bfd_map_over_sections (stdoutput, obj_mach_o_set_section_vma, (char *) &d);
1745 1.1.1.2 christos if ((d.vma_pass = d.gb_zerofill_seen) != 0)
1746 1.1.1.2 christos bfd_map_over_sections (stdoutput, obj_mach_o_set_section_vma, (char *) &d);
1747 1.1.1.2 christos }
1748 1.1.1.2 christos
1749 1.1.1.2 christos static void
1750 1.1.1.2 christos obj_mach_o_set_indirect_symbols (bfd *abfd, asection *sec,
1751 1.1.1.2 christos void *xxx ATTRIBUTE_UNUSED)
1752 1.1.1.2 christos {
1753 1.1.1.2 christos bfd_vma sect_size = bfd_section_size (abfd, sec);
1754 1.1.1.2 christos bfd_mach_o_section *ms = bfd_mach_o_get_mach_o_section (sec);
1755 1.1.1.2 christos unsigned lazy = 0;
1756 1.1.1.2 christos
1757 1.1.1.2 christos /* See if we have any indirect syms to consider. */
1758 1.1.1.2 christos if (indirect_syms == NULL)
1759 1.1.1.2 christos return;
1760 1.1.1.2 christos
1761 1.1.1.2 christos /* Process indirect symbols.
1762 1.1.1.2 christos Check for errors, if OK attach them as a flat array to the section
1763 1.1.1.2 christos for which they are defined. */
1764 1.1.1.2 christos
1765 1.1.1.2 christos switch (ms->flags & BFD_MACH_O_SECTION_TYPE_MASK)
1766 1.1.1.2 christos {
1767 1.1.1.2 christos case BFD_MACH_O_S_SYMBOL_STUBS:
1768 1.1.1.2 christos case BFD_MACH_O_S_LAZY_SYMBOL_POINTERS:
1769 1.1.1.2 christos lazy = LAZY;
1770 1.1.1.2 christos /* Fall through. */
1771 1.1.1.2 christos case BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS:
1772 1.1.1.2 christos {
1773 1.1.1.2 christos unsigned int nactual = 0;
1774 1.1.1.2 christos unsigned int ncalc;
1775 1.1.1.2 christos obj_mach_o_indirect_sym *isym;
1776 1.1.1.2 christos obj_mach_o_indirect_sym *list = NULL;
1777 1.1.1.2 christos obj_mach_o_indirect_sym *list_tail = NULL;
1778 1.1.1.3 christos unsigned long eltsiz =
1779 1.1.1.2 christos bfd_mach_o_section_get_entry_size (abfd, ms);
1780 1.1.1.2 christos
1781 1.1.1.2 christos for (isym = indirect_syms; isym != NULL; isym = isym->next)
1782 1.1.1.2 christos {
1783 1.1.1.2 christos if (isym->sect == sec)
1784 1.1.1.2 christos {
1785 1.1.1.2 christos nactual++;
1786 1.1.1.2 christos if (list == NULL)
1787 1.1.1.2 christos list = isym;
1788 1.1.1.2 christos else
1789 1.1.1.2 christos list_tail->next = isym;
1790 1.1.1.2 christos list_tail = isym;
1791 1.1.1.2 christos }
1792 1.1.1.2 christos }
1793 1.1.1.2 christos
1794 1.1.1.2 christos /* If none are in this section, stop here. */
1795 1.1.1.2 christos if (nactual == 0)
1796 1.1.1.2 christos break;
1797 1.1.1.2 christos
1798 1.1.1.2 christos /* If we somehow added indirect symbols to a section with a zero
1799 1.1.1.2 christos entry size, we're dead ... */
1800 1.1.1.2 christos gas_assert (eltsiz != 0);
1801 1.1.1.2 christos
1802 1.1.1.2 christos ncalc = (unsigned int) (sect_size / eltsiz);
1803 1.1.1.2 christos if (nactual != ncalc)
1804 1.1.1.2 christos as_bad (_("the number of .indirect_symbols defined in section %s"
1805 1.1.1.2 christos " does not match the number expected (%d defined, %d"
1806 1.1.1.2 christos " expected)"), sec->name, nactual, ncalc);
1807 1.1.1.2 christos else
1808 1.1.1.2 christos {
1809 1.1.1.2 christos unsigned n;
1810 1.1.1.2 christos bfd_mach_o_asymbol *sym;
1811 1.1.1.5 christos
1812 1.1.1.5 christos /* FIXME: It seems that there can be more indirect symbols
1813 1.1.1.5 christos than is computed by the loop above. So be paranoid and
1814 1.1.1.5 christos allocate enough space for every symbol to be indirect.
1815 1.1.1.5 christos See PR 21939 for an example of where this is needed. */
1816 1.1.1.5 christos if (nactual < bfd_get_symcount (abfd))
1817 1.1.1.5 christos nactual = bfd_get_symcount (abfd);
1818 1.1.1.5 christos
1819 1.1.1.2 christos ms->indirect_syms =
1820 1.1.1.2 christos bfd_zalloc (abfd,
1821 1.1.1.2 christos nactual * sizeof (bfd_mach_o_asymbol *));
1822 1.1.1.2 christos
1823 1.1.1.2 christos if (ms->indirect_syms == NULL)
1824 1.1.1.5 christos as_fatal (_("internal error: failed to allocate %d indirect"
1825 1.1.1.5 christos "symbol pointers"), nactual);
1826 1.1.1.3 christos
1827 1.1.1.2 christos for (isym = list, n = 0; isym != NULL; isym = isym->next, n++)
1828 1.1.1.2 christos {
1829 1.1.1.2 christos sym = (bfd_mach_o_asymbol *)symbol_get_bfdsym (isym->sym);
1830 1.1.1.2 christos /* Array is init to NULL & NULL signals a local symbol
1831 1.1.1.2 christos If the section is lazy-bound, we need to keep the
1832 1.1.1.2 christos reference to the symbol, since dyld can override.
1833 1.1.1.3 christos
1834 1.1.1.2 christos Absolute symbols are handled specially. */
1835 1.1.1.2 christos if (sym->symbol.section == bfd_abs_section_ptr)
1836 1.1.1.5 christos {
1837 1.1.1.5 christos if (n >= nactual)
1838 1.1.1.5 christos as_fatal (_("internal error: more indirect mach-o symbols than expected"));
1839 1.1.1.5 christos ms->indirect_syms[n] = sym;
1840 1.1.1.5 christos }
1841 1.1.1.2 christos else if (S_IS_LOCAL (isym->sym) && ! lazy)
1842 1.1.1.2 christos ;
1843 1.1.1.2 christos else
1844 1.1.1.2 christos {
1845 1.1.1.2 christos if (sym == NULL)
1846 1.1.1.2 christos ;
1847 1.1.1.2 christos /* If the symbols is external ... */
1848 1.1.1.2 christos else if (S_IS_EXTERNAL (isym->sym)
1849 1.1.1.2 christos || (sym->n_type & BFD_MACH_O_N_EXT)
1850 1.1.1.2 christos || ! S_IS_DEFINED (isym->sym)
1851 1.1.1.2 christos || lazy)
1852 1.1.1.2 christos {
1853 1.1.1.2 christos sym->n_desc &= ~LAZY;
1854 1.1.1.2 christos /* ... it can be lazy, if not defined or hidden. */
1855 1.1.1.3 christos if ((sym->n_type & BFD_MACH_O_N_TYPE)
1856 1.1.1.3 christos == BFD_MACH_O_N_UNDF
1857 1.1.1.2 christos && ! (sym->n_type & BFD_MACH_O_N_PEXT)
1858 1.1.1.2 christos && (sym->n_type & BFD_MACH_O_N_EXT))
1859 1.1.1.2 christos sym->n_desc |= lazy;
1860 1.1.1.5 christos if (n >= nactual)
1861 1.1.1.5 christos as_fatal (_("internal error: more indirect mach-o symbols than expected"));
1862 1.1.1.2 christos ms->indirect_syms[n] = sym;
1863 1.1.1.2 christos }
1864 1.1.1.2 christos }
1865 1.1.1.2 christos }
1866 1.1.1.2 christos }
1867 1.1.1.2 christos }
1868 1.1.1.2 christos break;
1869 1.1.1.2 christos
1870 1.1.1.2 christos default:
1871 1.1.1.2 christos break;
1872 1.1.1.2 christos }
1873 1.1.1.2 christos }
1874 1.1.1.2 christos
1875 1.1.1.2 christos /* The process of relocation could alter what's externally visible, thus we
1876 1.1.1.2 christos leave setting the indirect symbols until last. */
1877 1.1.1.2 christos
1878 1.1.1.2 christos void
1879 1.1.1.2 christos obj_mach_o_frob_file_after_relocs (void)
1880 1.1.1.2 christos {
1881 1.1.1.2 christos bfd_map_over_sections (stdoutput, obj_mach_o_set_indirect_symbols, (char *) 0);
1882 1.1.1.2 christos }
1883 1.1.1.2 christos
1884 1.1.1.2 christos /* Reverse relocations order to make ld happy. */
1885 1.1.1.2 christos
1886 1.1.1.2 christos void
1887 1.1.1.2 christos obj_mach_o_reorder_section_relocs (asection *sec, arelent **rels, unsigned int n)
1888 1.1.1.2 christos {
1889 1.1.1.2 christos unsigned int i;
1890 1.1.1.2 christos unsigned int max = n / 2;
1891 1.1.1.2 christos
1892 1.1.1.2 christos for (i = 0; i < max; i++)
1893 1.1.1.2 christos {
1894 1.1.1.2 christos arelent *r = rels[i];
1895 1.1.1.2 christos rels[i] = rels[n - i - 1];
1896 1.1.1.2 christos rels[n - i - 1] = r;
1897 1.1.1.2 christos }
1898 1.1.1.2 christos bfd_set_reloc (stdoutput, sec, rels, n);
1899 1.1.1.2 christos }
1900 1.1.1.2 christos
1901 1.1.1.2 christos /* Relocation rules are different in frame sections. */
1902 1.1.1.2 christos
1903 1.1.1.2 christos static int
1904 1.1.1.2 christos obj_mach_o_is_frame_section (segT sec)
1905 1.1.1.2 christos {
1906 1.1.1.2 christos int l;
1907 1.1.1.2 christos l = strlen (segment_name (sec));
1908 1.1.1.2 christos if ((l == 9 && strncmp (".eh_frame", segment_name (sec), 9) == 0)
1909 1.1.1.2 christos || (l == 12 && strncmp (".debug_frame", segment_name (sec), 12) == 0))
1910 1.1.1.2 christos return 1;
1911 1.1.1.2 christos return 0;
1912 1.1.1.2 christos }
1913 1.1.1.2 christos
1914 1.1.1.2 christos /* Unless we're in a frame section, we need to force relocs to be generated for
1915 1.1.1.2 christos local subtractions. We might eliminate them later (if they are within the
1916 1.1.1.2 christos same sub-section) but we don't know that at the point that this decision is
1917 1.1.1.2 christos being made. */
1918 1.1.1.2 christos
1919 1.1.1.2 christos int
1920 1.1.1.3 christos obj_mach_o_allow_local_subtract (expressionS * left ATTRIBUTE_UNUSED,
1921 1.1.1.2 christos expressionS * right ATTRIBUTE_UNUSED,
1922 1.1.1.2 christos segT seg)
1923 1.1.1.2 christos {
1924 1.1.1.2 christos /* Don't interfere if it's one of the GAS internal sections. */
1925 1.1.1.2 christos if (! SEG_NORMAL (seg))
1926 1.1.1.2 christos return 1;
1927 1.1.1.2 christos
1928 1.1.1.2 christos /* Allow in frame sections, otherwise emit a reloc. */
1929 1.1.1.2 christos return obj_mach_o_is_frame_section (seg);
1930 1.1.1.2 christos }
1931 1.1.1.2 christos
1932 1.1.1.2 christos int
1933 1.1.1.2 christos obj_mach_o_in_different_subsection (symbolS *a, symbolS *b)
1934 1.1.1.2 christos {
1935 1.1.1.2 christos fragS *fa;
1936 1.1.1.2 christos fragS *fb;
1937 1.1.1.2 christos
1938 1.1.1.2 christos if (S_GET_SEGMENT (a) != S_GET_SEGMENT (b)
1939 1.1.1.2 christos || !S_IS_DEFINED (a)
1940 1.1.1.2 christos || !S_IS_DEFINED (b))
1941 1.1.1.2 christos {
1942 1.1.1.2 christos /* Not in the same segment, or undefined symbol. */
1943 1.1.1.2 christos return 1;
1944 1.1.1.2 christos }
1945 1.1.1.2 christos
1946 1.1.1.2 christos fa = symbol_get_frag (a);
1947 1.1.1.2 christos fb = symbol_get_frag (b);
1948 1.1.1.2 christos if (fa == NULL || fb == NULL)
1949 1.1.1.2 christos {
1950 1.1.1.2 christos /* One of the symbols is not in a subsection. */
1951 1.1.1.2 christos return 1;
1952 1.1.1.2 christos }
1953 1.1.1.2 christos
1954 1.1.1.2 christos return fa->obj_frag_data.subsection != fb->obj_frag_data.subsection;
1955 1.1.1.2 christos }
1956 1.1.1.2 christos
1957 1.1.1.2 christos int
1958 1.1.1.2 christos obj_mach_o_force_reloc_sub_same (fixS *fix, segT seg)
1959 1.1.1.2 christos {
1960 1.1.1.2 christos if (! SEG_NORMAL (seg))
1961 1.1.1.2 christos return 1;
1962 1.1.1.2 christos return obj_mach_o_in_different_subsection (fix->fx_addsy, fix->fx_subsy);
1963 1.1.1.2 christos }
1964 1.1.1.2 christos
1965 1.1.1.2 christos int
1966 1.1.1.2 christos obj_mach_o_force_reloc_sub_local (fixS *fix, segT seg ATTRIBUTE_UNUSED)
1967 1.1.1.2 christos {
1968 1.1.1.2 christos return obj_mach_o_in_different_subsection (fix->fx_addsy, fix->fx_subsy);
1969 1.1.1.2 christos }
1970 1.1.1.2 christos
1971 1.1.1.2 christos int
1972 1.1.1.2 christos obj_mach_o_force_reloc (fixS *fix)
1973 1.1.1.2 christos {
1974 1.1.1.2 christos if (generic_force_reloc (fix))
1975 1.1.1.2 christos return 1;
1976 1.1.1.2 christos
1977 1.1.1.2 christos /* Force a reloc if the target is not in the same subsection.
1978 1.1.1.2 christos FIXME: handle (a - b) where a and b belongs to the same subsection ? */
1979 1.1.1.2 christos if (fix->fx_addsy != NULL)
1980 1.1.1.2 christos {
1981 1.1.1.2 christos symbolS *subsec = fix->fx_frag->obj_frag_data.subsection;
1982 1.1.1.2 christos symbolS *targ = fix->fx_addsy;
1983 1.1.1.2 christos
1984 1.1.1.2 christos /* There might be no subsections at all. */
1985 1.1.1.2 christos if (subsec == NULL)
1986 1.1.1.2 christos return 0;
1987 1.1.1.2 christos
1988 1.1.1.2 christos if (S_GET_SEGMENT (targ) == absolute_section)
1989 1.1.1.2 christos return 0;
1990 1.1.1.2 christos
1991 1.1.1.2 christos return obj_mach_o_in_different_subsection (targ, subsec);
1992 1.1.1.2 christos }
1993 1.1.1.2 christos return 0;
1994 1.1.1.2 christos }
1995