* elflink.h (elf_link_add_object_symbols): Calling check_relocs
[deliverable/binutils-gdb.git] / bfd / cf-m68klynx.c
CommitLineData
c4a42381 1/* BFD back-end for Motorola M68K COFF LynxOS files.
a9dd34a9 2 Copyright 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
48ee0757
SS
3 Written by Cygnus Support.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
943fbd5b 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
48ee0757 20
c4a42381
SS
21#define TARGET_SYM m68klynx_coff_vec
22#define TARGET_NAME "coff-m68k-lynx"
48ee0757 23
c9368a3b
SS
24#define LYNXOS
25
26#define COFF_LONG_FILENAMES
27
f71481ba
ME
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
74329939 31#define _bfd_m68kcoff_reloc_type_lookup _bfd_m68klynx_reloc_type_lookup
f71481ba
ME
32
33#define LYNX_SPECIAL_FN _bfd_m68klynx_special_fn
34
35#include "bfd.h"
7e29158a 36#include "sysdep.h"
f71481ba 37
bd23b552
ILT
38#ifdef ANSI_PROTOTYPES
39struct internal_reloc;
40struct coff_link_hash_entry;
41struct internal_syment;
42#endif
43
44static bfd_reloc_status_type _bfd_m68klynx_special_fn
45 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
d01a0278 46static reloc_howto_type *coff_m68k_lynx_rtype_to_howto
bd23b552
ILT
47 PARAMS ((bfd *, asection *, struct internal_reloc *,
48 struct coff_link_hash_entry *, struct internal_syment *,
49 bfd_vma *));
f71481ba
ME
50
51/* For some reason when using m68k COFF the value stored in the .text
52 section for a reference to a common symbol is the value itself plus
53 any desired offset. (taken from work done by Ian Taylor, Cygnus Support,
54 for I386 COFF). */
55
56/* If we are producing relocateable output, we need to do some
57 adjustments to the object file that are not done by the
58 bfd_perform_relocation function. This function is called by every
59 reloc type to make any required adjustments. */
60
61static bfd_reloc_status_type
bd23b552
ILT
62_bfd_m68klynx_special_fn (abfd, reloc_entry, symbol, data, input_section,
63 output_bfd, error_message)
f71481ba
ME
64 bfd *abfd;
65 arelent *reloc_entry;
66 asymbol *symbol;
67 PTR data;
68 asection *input_section;
69 bfd *output_bfd;
70 char **error_message;
71{
72 symvalue diff;
73
74 if (output_bfd == (bfd *) NULL)
75 return bfd_reloc_continue;
76
77 if (bfd_is_com_section (symbol->section))
78 {
79 /* We are relocating a common symbol. The current value in the
80 object file is ORIG + OFFSET, where ORIG is the value of the
81 common symbol as seen by the object file when it was compiled
82 (this may be zero if the symbol was undefined) and OFFSET is
83 the offset into the common symbol (normally zero, but may be
84 non-zero when referring to a field in a common structure).
85 ORIG is the negative of reloc_entry->addend, which is set by
86 the CALC_ADDEND macro below. We want to replace the value in
87 the object file with NEW + OFFSET, where NEW is the value of
88 the common symbol which we are going to put in the final
89 object file. NEW is symbol->value. */
90 diff = symbol->value + reloc_entry->addend;
91 }
92 else
93 {
94 /* For some reason bfd_perform_relocation always effectively
95 ignores the addend for a COFF target when producing
96 relocateable output. This seems to be always wrong for 386
97 COFF, so we handle the addend here instead. */
98 diff = reloc_entry->addend;
99 }
100
101#define DOIT(x) \
102 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
103
104 if (diff != 0)
105 {
82b1edf7 106 reloc_howto_type *howto = reloc_entry->howto;
f71481ba
ME
107 unsigned char *addr = (unsigned char *) data + reloc_entry->address;
108
109 switch (howto->size)
110 {
111 case 0:
112 {
113 char x = bfd_get_8 (abfd, addr);
114 DOIT (x);
115 bfd_put_8 (abfd, x, addr);
116 }
117 break;
118
119 case 1:
120 {
121 short x = bfd_get_16 (abfd, addr);
122 DOIT (x);
123 bfd_put_16 (abfd, x, addr);
124 }
125 break;
126
127 case 2:
128 {
129 long x = bfd_get_32 (abfd, addr);
130 DOIT (x);
131 bfd_put_32 (abfd, x, addr);
132 }
133 break;
134
135 default:
136 abort ();
137 }
138 }
139
140 /* Now let bfd_perform_relocation finish everything up. */
141 return bfd_reloc_continue;
142}
143/* Compute the addend of a reloc. If the reloc is to a common symbol,
144 the object file contains the value of the common symbol. By the
145 time this is called, the linker may be using a different symbol
146 from a different object file with a different value. Therefore, we
147 hack wildly to locate the original symbol from this file so that we
148 can make the correct adjustment. This macro sets coffsym to the
149 symbol from the original file, and uses it to set the addend value
150 correctly. If this is not a common symbol, the usual addend
151 calculation is done, except that an additional tweak is needed for
152 PC relative relocs.
153 FIXME: This macro refers to symbols and asect; these are from the
154 calling function, not the macro arguments. */
155
156#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
157 { \
158 coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
159 if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
160 coffsym = (obj_symbols (abfd) \
161 + (cache_ptr->sym_ptr_ptr - symbols)); \
162 else if (ptr) \
163 coffsym = coff_symbol_from (abfd, ptr); \
164 if (coffsym != (coff_symbol_type *) NULL \
165 && coffsym->native->u.syment.n_scnum == 0) \
166 cache_ptr->addend = - coffsym->native->u.syment.n_value; \
167 else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
168 && ptr->section != (asection *) NULL) \
169 cache_ptr->addend = - (ptr->section->vma + ptr->value); \
170 else \
171 cache_ptr->addend = 0; \
e3361fc3
ILT
172 if (ptr && (reloc.r_type == R_PCRBYTE \
173 || reloc.r_type == R_PCRWORD \
174 || reloc.r_type == R_PCRLONG)) \
f71481ba
ME
175 cache_ptr->addend += asect->vma; \
176 }
177
bd23b552 178#define coff_rtype_to_howto coff_m68k_lynx_rtype_to_howto
c9368a3b 179
c4a42381 180#include "coff-m68k.c"
bd23b552
ILT
181
182/* coff-m68k.c uses the special COFF backend linker. We need to
2a895595 183 adjust common symbols.
bd23b552
ILT
184
185 We can't define this function until after we have included
186 coff-m68k.c, because it uses RTYPE2HOWTO. */
187
188/*ARGSUSED*/
d01a0278 189static reloc_howto_type *
bd23b552
ILT
190coff_m68k_lynx_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
191 bfd *abfd;
192 asection *sec;
193 struct internal_reloc *rel;
194 struct coff_link_hash_entry *h;
195 struct internal_syment *sym;
196 bfd_vma *addendp;
197{
198 arelent relent;
d01a0278 199 reloc_howto_type *howto;
bd23b552
ILT
200
201 RTYPE2HOWTO (&relent, rel);
202
203 howto = relent.howto;
204
a9dd34a9
ILT
205 if (howto->pc_relative)
206 *addendp += sec->vma;
207
2a895595 208 if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
bd23b552
ILT
209 {
210 /* This is a common symbol. The section contents include the
211 size (sym->n_value) as an addend. The relocate_section
212 function will be adding in the final value of the symbol. We
213 need to subtract out the current size in order to get the
214 correct result. */
215 BFD_ASSERT (h != NULL);
216 *addendp -= sym->n_value;
217 }
218
219 /* If the output symbol is common (in which case this must be a
220 relocateable link), we need to add in the final size of the
221 common symbol. */
222 if (h != NULL && h->root.type == bfd_link_hash_common)
223 *addendp += h->root.u.c.size;
224
225 return howto;
226}
This page took 0.139914 seconds and 4 git commands to generate.