1 /* BFD back-end for Apple M68K COFF A/UX 3.x files.
2 Copyright 1996 Free Software Foundation, Inc.
3 Portions written by Richard Henderson <rth@tamu.edu>,
4 COMMON symbol munging cribbed from cf-m68klynx.c which was
5 written by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #define TARGET_SYM m68kaux_coff_vec
24 #define TARGET_NAME "coff-m68k-aux"
30 #define COFF_LONG_FILENAMES
33 #define COFF_PAGE_SIZE 0x1000
35 /* On AUX, a STYP_NOLOAD|STYP_BSS section is part of a shared library. */
36 #define BSS_NOLOAD_IS_SHARED_LIBRARY
38 #define _bfd_m68kcoff_howto_table _bfd_m68kaux_howto_table
39 #define _bfd_m68kcoff_rtype2howto _bfd_m68kaux_rtype2howto
40 #define _bfd_m68kcoff_howto2rtype _bfd_m68kaux_howto2rtype
41 #define _bfd_m68kcoff_reloc_type_lookup _bfd_m68kaux_reloc_type_lookup
43 /* Rather than change names lots of places, reuse the same hack */
44 #define LYNX_SPECIAL_FN _bfd_m68kaux_special_fn
49 #ifdef ANSI_PROTOTYPES
50 struct internal_reloc;
51 struct coff_link_hash_entry;
52 struct internal_syment;
56 static bfd_reloc_status_type _bfd_m68kaux_special_fn
57 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
58 static reloc_howto_type *coff_m68k_aux_rtype_to_howto
59 PARAMS ((bfd *, asection *, struct internal_reloc *,
60 struct coff_link_hash_entry *, struct internal_syment *,
62 static boolean coff_m68k_aux_link_add_one_symbol
63 PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword,
64 asection *, bfd_vma, const char *, boolean, boolean,
65 struct bfd_link_hash_entry **));
68 #define coff_rtype_to_howto coff_m68k_aux_rtype_to_howto
69 #define coff_link_add_one_symbol coff_m68k_aux_link_add_one_symbol
72 /* Compute the addend of a reloc. If the reloc is to a common symbol,
73 the object file contains the value of the common symbol. By the
74 time this is called, the linker may be using a different symbol
75 from a different object file with a different value. Therefore, we
76 hack wildly to locate the original symbol from this file so that we
77 can make the correct adjustment. This macro sets coffsym to the
78 symbol from the original file, and uses it to set the addend value
79 correctly. If this is not a common symbol, the usual addend
80 calculation is done, except that an additional tweak is needed for
82 FIXME: This macro refers to symbols and asect; these are from the
83 calling function, not the macro arguments. */
85 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
87 coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
88 if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
89 coffsym = (obj_symbols (abfd) \
90 + (cache_ptr->sym_ptr_ptr - symbols)); \
92 coffsym = coff_symbol_from (abfd, ptr); \
93 if (coffsym != (coff_symbol_type *) NULL \
94 && coffsym->native->u.syment.n_scnum == 0) \
95 cache_ptr->addend = - coffsym->native->u.syment.n_value; \
96 else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
97 && ptr->section != (asection *) NULL) \
98 cache_ptr->addend = - (ptr->section->vma + ptr->value); \
100 cache_ptr->addend = 0; \
101 if (ptr && (reloc.r_type == R_PCRBYTE \
102 || reloc.r_type == R_PCRWORD \
103 || reloc.r_type == R_PCRLONG)) \
104 cache_ptr->addend += asect->vma; \
109 #include "coff/aux.h" /* override coff/internal.h and coff/m68k.h */
110 #include "coff-m68k.c"
114 /* For some reason when using m68k COFF the value stored in the .text
115 section for a reference to a common symbol is the value itself plus
116 any desired offset. (taken from work done by Ian Taylor, Cygnus Support,
119 /* If we are producing relocateable output, we need to do some
120 adjustments to the object file that are not done by the
121 bfd_perform_relocation function. This function is called by every
122 reloc type to make any required adjustments. */
124 static bfd_reloc_status_type
125 _bfd_m68kaux_special_fn (abfd, reloc_entry, symbol, data, input_section,
126 output_bfd, error_message)
128 arelent *reloc_entry;
131 asection *input_section;
133 char **error_message;
137 if (output_bfd == (bfd *) NULL)
138 return bfd_reloc_continue;
140 if (bfd_is_com_section (symbol->section))
142 /* We are relocating a common symbol. The current value in the
143 object file is ORIG + OFFSET, where ORIG is the value of the
144 common symbol as seen by the object file when it was compiled
145 (this may be zero if the symbol was undefined) and OFFSET is
146 the offset into the common symbol (normally zero, but may be
147 non-zero when referring to a field in a common structure).
148 ORIG is the negative of reloc_entry->addend, which is set by
149 the CALC_ADDEND macro below. We want to replace the value in
150 the object file with NEW + OFFSET, where NEW is the value of
151 the common symbol which we are going to put in the final
152 object file. NEW is symbol->value. */
153 diff = symbol->value + reloc_entry->addend;
157 /* For some reason bfd_perform_relocation always effectively
158 ignores the addend for a COFF target when producing
159 relocateable output. This seems to be always wrong for 386
160 COFF, so we handle the addend here instead. */
161 diff = reloc_entry->addend;
165 x = ((x & ~howto->dst_mask) | \
166 (((x & howto->src_mask) + diff) & howto->dst_mask))
170 reloc_howto_type *howto = reloc_entry->howto;
171 unsigned char *addr = (unsigned char *) data + reloc_entry->address;
177 char x = bfd_get_8 (abfd, addr);
179 bfd_put_8 (abfd, x, addr);
185 short x = bfd_get_16 (abfd, addr);
187 bfd_put_16 (abfd, x, addr);
193 long x = bfd_get_32 (abfd, addr);
195 bfd_put_32 (abfd, x, addr);
204 /* Now let bfd_perform_relocation finish everything up. */
205 return bfd_reloc_continue;
209 /* coff-m68k.c uses the special COFF backend linker. We need to
210 adjust common symbols. */
213 static reloc_howto_type *
214 coff_m68k_aux_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
217 struct internal_reloc *rel;
218 struct coff_link_hash_entry *h;
219 struct internal_syment *sym;
223 reloc_howto_type *howto;
225 RTYPE2HOWTO (&relent, rel);
227 howto = relent.howto;
229 if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
231 /* This is a common symbol. The section contents include the
232 size (sym->n_value) as an addend. The relocate_section
233 function will be adding in the final value of the symbol. We
234 need to subtract out the current size in order to get the
236 BFD_ASSERT (h != NULL);
237 *addendp -= sym->n_value;
240 /* If the output symbol is common (in which case this must be a
241 relocateable link), we need to add in the final size of the
243 if (h != NULL && h->root.type == bfd_link_hash_common)
244 *addendp += h->root.u.c.size;
250 /* We need non-absolute symbols to override absolute symbols. This
251 mirrors Apple's "solution" to let a static library symbol override
252 a shared library symbol. On the whole not a good thing, given how
253 shared libraries work here, but can work if you are careful with
254 what you include in the shared object. */
257 coff_m68k_aux_link_add_one_symbol (info, abfd, name, flags, section, value,
258 string, copy, collect, hashp)
259 struct bfd_link_info *info;
268 struct bfd_link_hash_entry **hashp;
270 struct bfd_link_hash_entry *h;
272 if ((flags & (BSF_WARNING | BSF_CONSTRUCTOR | BSF_WEAK)) == 0 &&
273 !bfd_is_und_section (section) &&
274 !bfd_is_com_section (section))
276 /* The new symbol is a definition or an indirect definition */
278 /* This bit copied from linker.c */
279 if (hashp != NULL && *hashp != NULL)
282 BFD_ASSERT (strcmp (h->root.string, name) == 0);
286 h = bfd_link_hash_lookup (info->hash, name, true, copy, false);
295 if (info->notice_hash != (struct bfd_hash_table *) NULL
296 && (bfd_hash_lookup (info->notice_hash, name, false, false)
297 != (struct bfd_hash_entry *) NULL))
299 if (! (*info->callbacks->notice) (info, name, abfd, section, value))
303 if (hashp != (struct bfd_link_hash_entry **) NULL)
305 /* end duplication from linker.c */
307 if (h->type == bfd_link_hash_defined
308 || h->type == bfd_link_hash_indirect)
312 if (h->type == bfd_link_hash_defined)
313 msec = h->u.def.section;
315 msec = bfd_ind_section_ptr;
317 if (bfd_is_abs_section (msec) && !bfd_is_abs_section (section))
319 h->u.def.section = section;
320 h->u.def.value = value;
323 else if (bfd_is_abs_section (section) && !bfd_is_abs_section (msec))
328 /* If we didn't exit early, finish processing in the generic routine */
329 return _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
330 value, string, copy, collect,