1 /* BFD back-end for Motorola M68K COFF LynxOS files.
2 Copyright 1993 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #define TARGET_SYM m68klynx_coff_vec
22 #define TARGET_NAME "coff-m68k-lynx"
26 #define COFF_LONG_FILENAMES
28 #define _bfd_m68kcoff_howto_table _bfd_m68klynx_howto_table
29 #define _bfd_m68kcoff_rtype2howto _bfd_m68klynx_rtype2howto
30 #define _bfd_m68kcoff_howto2rtype _bfd_m68klynx_howto2rtype
31 #define _bfd_m68kcoff_reloc_type_lookup _bfd_m68klynx_reloc_type_lookup
33 #define LYNX_SPECIAL_FN _bfd_m68klynx_special_fn
38 static bfd_reloc_status_type _bfd_m68klynx_special_fn
PARAMS ((bfd
*abfd
,
42 asection
*input_section
,
44 char **error_message
));
46 /* For some reason when using m68k COFF the value stored in the .text
47 section for a reference to a common symbol is the value itself plus
48 any desired offset. (taken from work done by Ian Taylor, Cygnus Support,
51 /* If we are producing relocateable output, we need to do some
52 adjustments to the object file that are not done by the
53 bfd_perform_relocation function. This function is called by every
54 reloc type to make any required adjustments. */
56 static bfd_reloc_status_type
57 _bfd_m68klynx_special_fn (abfd
, reloc_entry
, symbol
, data
, input_section
, output_bfd
,
63 asection
*input_section
;
69 if (output_bfd
== (bfd
*) NULL
)
70 return bfd_reloc_continue
;
72 if (bfd_is_com_section (symbol
->section
))
74 /* We are relocating a common symbol. The current value in the
75 object file is ORIG + OFFSET, where ORIG is the value of the
76 common symbol as seen by the object file when it was compiled
77 (this may be zero if the symbol was undefined) and OFFSET is
78 the offset into the common symbol (normally zero, but may be
79 non-zero when referring to a field in a common structure).
80 ORIG is the negative of reloc_entry->addend, which is set by
81 the CALC_ADDEND macro below. We want to replace the value in
82 the object file with NEW + OFFSET, where NEW is the value of
83 the common symbol which we are going to put in the final
84 object file. NEW is symbol->value. */
85 diff
= symbol
->value
+ reloc_entry
->addend
;
89 /* For some reason bfd_perform_relocation always effectively
90 ignores the addend for a COFF target when producing
91 relocateable output. This seems to be always wrong for 386
92 COFF, so we handle the addend here instead. */
93 diff
= reloc_entry
->addend
;
97 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
101 const reloc_howto_type
*howto
= reloc_entry
->howto
;
102 unsigned char *addr
= (unsigned char *) data
+ reloc_entry
->address
;
108 char x
= bfd_get_8 (abfd
, addr
);
110 bfd_put_8 (abfd
, x
, addr
);
116 short x
= bfd_get_16 (abfd
, addr
);
118 bfd_put_16 (abfd
, x
, addr
);
124 long x
= bfd_get_32 (abfd
, addr
);
126 bfd_put_32 (abfd
, x
, addr
);
135 /* Now let bfd_perform_relocation finish everything up. */
136 return bfd_reloc_continue
;
138 /* Compute the addend of a reloc. If the reloc is to a common symbol,
139 the object file contains the value of the common symbol. By the
140 time this is called, the linker may be using a different symbol
141 from a different object file with a different value. Therefore, we
142 hack wildly to locate the original symbol from this file so that we
143 can make the correct adjustment. This macro sets coffsym to the
144 symbol from the original file, and uses it to set the addend value
145 correctly. If this is not a common symbol, the usual addend
146 calculation is done, except that an additional tweak is needed for
148 FIXME: This macro refers to symbols and asect; these are from the
149 calling function, not the macro arguments. */
151 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
153 coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
154 if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
155 coffsym = (obj_symbols (abfd) \
156 + (cache_ptr->sym_ptr_ptr - symbols)); \
158 coffsym = coff_symbol_from (abfd, ptr); \
159 if (coffsym != (coff_symbol_type *) NULL \
160 && coffsym->native->u.syment.n_scnum == 0) \
161 cache_ptr->addend = - coffsym->native->u.syment.n_value; \
162 else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
163 && ptr->section != (asection *) NULL) \
164 cache_ptr->addend = - (ptr->section->vma + ptr->value); \
166 cache_ptr->addend = 0; \
167 if (ptr && (reloc.r_type == R_PCRBYTE \
168 || reloc.r_type == R_PCRWORD \
169 || reloc.r_type == R_PCRLONG)) \
170 cache_ptr->addend += asect->vma; \
174 #include "coff-m68k.c"