1/* BFD back-end for Apple M68K COFF A/UX 3.x files.
2   Copyright 1996, 1997, 2000, 2002, 2007 Free Software Foundation, Inc.
3   Written by Richard Henderson <rth@tamu.edu>.
4
5   This file is part of BFD, the Binary File Descriptor library.
6
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 3 of the License, or
10   (at your option) any later version.
11
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.
16
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., 51 Franklin Street - Fifth Floor, Boston,
20   MA 02110-1301, USA.  */
21
22#define TARGET_SYM	m68kaux_coff_vec
23#define TARGET_NAME	"coff-m68k-aux"
24
25#ifndef TARG_AUX
26#define TARG_AUX
27#endif
28
29#define COFF_LONG_FILENAMES
30
31/* 4k pages */
32#define COFF_PAGE_SIZE 0x1000
33
34/* On AUX, a STYP_NOLOAD|STYP_BSS section is part of a shared library.  */
35#define BSS_NOLOAD_IS_SHARED_LIBRARY
36
37#define STATIC_RELOCS
38
39#define COFF_COMMON_ADDEND
40
41#include "sysdep.h"
42#include "bfd.h"
43
44static bfd_boolean coff_m68k_aux_link_add_one_symbol
45  PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword,
46           asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean,
47           struct bfd_link_hash_entry **));
48
49#define coff_link_add_one_symbol coff_m68k_aux_link_add_one_symbol
50
51#include "coff/aux-coff.h"  /* override coff/internal.h and coff/m68k.h */
52#include "coff-m68k.c"
53
54/* We need non-absolute symbols to override absolute symbols.  This
55   mirrors Apple's "solution" to let a static library symbol override
56   a shared library symbol.  On the whole not a good thing, given how
57   shared libraries work here, but can work if you are careful with
58   what you include in the shared object.  */
59
60static bfd_boolean
61coff_m68k_aux_link_add_one_symbol (info, abfd, name, flags, section, value,
62				   string, copy, collect, hashp)
63     struct bfd_link_info *info;
64     bfd *abfd;
65     const char *name;
66     flagword flags;
67     asection *section;
68     bfd_vma value;
69     const char *string;
70     bfd_boolean copy;
71     bfd_boolean collect;
72     struct bfd_link_hash_entry **hashp;
73{
74  struct bfd_link_hash_entry *h;
75
76  if ((flags & (BSF_WARNING | BSF_CONSTRUCTOR | BSF_WEAK)) == 0 &&
77      !bfd_is_und_section (section) &&
78      !bfd_is_com_section (section))
79    {
80      /* The new symbol is a definition or an indirect definition */
81
82      /* This bit copied from linker.c */
83      if (hashp != NULL && *hashp != NULL)
84	{
85	  h = *hashp;
86	  BFD_ASSERT (strcmp (h->root.string, name) == 0);
87	}
88      else
89	{
90	  h = bfd_link_hash_lookup (info->hash, name, TRUE, copy, FALSE);
91	  if (h == NULL)
92	    {
93	      if (hashp != NULL)
94		*hashp = NULL;
95	      return FALSE;
96	    }
97	}
98
99      if (info->notice_hash != (struct bfd_hash_table *) NULL
100	  && (bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE)
101	      != (struct bfd_hash_entry *) NULL))
102	{
103	  if (! (*info->callbacks->notice) (info, name, abfd, section, value))
104	    return FALSE;
105	}
106
107      if (hashp != (struct bfd_link_hash_entry **) NULL)
108	*hashp = h;
109      /* end duplication from linker.c */
110
111      if (h->type == bfd_link_hash_defined
112	  || h->type == bfd_link_hash_indirect)
113	{
114	  asection *msec;
115
116	  if (h->type == bfd_link_hash_defined)
117	    msec = h->u.def.section;
118	  else
119	    msec = bfd_ind_section_ptr;
120
121	  if (bfd_is_abs_section (msec) && !bfd_is_abs_section (section))
122	    {
123	      h->u.def.section = section;
124	      h->u.def.value = value;
125	      return TRUE;
126	    }
127	  else if (bfd_is_abs_section (section) && !bfd_is_abs_section (msec))
128	    return TRUE;
129	}
130    }
131
132  /* If we didn't exit early, finish processing in the generic routine */
133  return _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
134					   value, string, copy, collect,
135					   hashp);
136}
137