source: rtems-tools/linkers/rld-resolver.cpp @ 5825009

4.104.115
Last change on this file since 5825009 was b89ad2c6, checked in by Chris Johns <chrisj@…>, on 12/15/12 at 11:44:58

i386 related fixes

Fix the size of the section calculated in image::lay_out. It did not
correctly adjust for alignment. Make the sections being written
correctly align.

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Copyright (c) 2011, Chris Johns <chrisj@rtems.org>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16/**
17 * @file
18 *
19 * @ingroup rtems_ld
20 *
21 * @brief RTEMS Linker.
22 *
23 */
24
25#if HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include <iomanip>
30#include <iostream>
31
32#include <sys/stat.h>
33
34#include <rld.h>
35#include <rld.h>
36
37namespace rld
38{
39  namespace resolver
40  {
41    static void
42    resolve_symbols (rld::files::object_list& dependents,
43                     rld::files::cache&       cache,
44                     rld::symbols::table&     base_symbols,
45                     rld::symbols::table&     symbols,
46                     rld::symbols::table&     unresolved,
47                     const std::string&       name)
48    {
49      static int nesting = 0;
50
51      ++nesting;
52
53      /*
54       * Find each unresolved symbol in the symbol table pointing the
55       * unresolved symbol's object file to the file that resolves the
56       * symbol. Record each object file that is found and when all unresolved
57       * symbols in this object file have been found iterate over the found
58       * object files resolving them. The 'urs' is the unresolved symbol and
59       * 'es' is the exported symbol.
60       */
61
62      if (rld::verbose () >= RLD_VERBOSE_INFO)
63        std::cout << "resolver:resolving: "
64                  << std::setw (nesting - 1) << ' '
65                  << name
66                  << ", unresolved: "
67                  << unresolved.size ()
68                  << std::endl;
69
70      rld::files::object_list objects;
71
72      for (rld::symbols::table::iterator ursi = unresolved.begin ();
73           (ursi != unresolved.end ()) && !((*ursi).second)->object ();
74           ++ursi)
75      {
76        rld::symbols::symbol&         urs = *((*ursi).second);
77        rld::symbols::table::iterator esi = base_symbols.find (urs.name ());
78        bool                          base = true;
79
80        if (rld::verbose () >= RLD_VERBOSE_INFO)
81        {
82          std::cout << "resolver:resolve  : "
83                    << std::setw (nesting + 1) << ' '
84                    << urs.name () << std::endl;
85        }
86
87        if (esi == base_symbols.end ())
88        {
89          esi = symbols.find (urs.name ());
90          if (esi == symbols.end ())
91            throw rld::error ("symbol not found: " + urs.name (), name);
92          base = false;
93        }
94
95        rld::symbols::symbol& es = *((*esi).second);
96
97        if (rld::verbose () >= RLD_VERBOSE_INFO)
98        {
99          std::cout << "resolver:resolved : "
100                    << std::setw (nesting + 1) << ' '
101                    << urs.name ()
102                    << " -> ";
103          if (es.object())
104            std::cout << es.object()->name ().basename ();
105          else
106            std::cout << "null";
107          std::cout << std::endl;
108        }
109
110        if (!base)
111        {
112          urs.set_object (*es.object ());
113          objects.push_back (es.object ());
114        }
115
116        es.referenced ();
117      }
118
119      /*
120       * Recurse into any references object files. First remove any duplicate
121       * entries.
122       */
123      objects.unique ();
124
125      for (rld::files::object_list::iterator oli = objects.begin ();
126           oli != objects.end ();
127           ++oli)
128      {
129        rld::files::object& object = *(*oli);
130        if (rld::verbose () >= RLD_VERBOSE_INFO)
131          std::cout << "resolver:resolving:    : "
132                    << object.name ().basename () << std::endl;
133        resolve_symbols (dependents, cache, base_symbols, symbols,
134                         object.unresolved_symbols (),
135                         object.name ().basename ());
136      }
137
138      --nesting;
139
140      dependents.merge (objects);
141      dependents.unique ();
142    }
143
144    void
145    resolve (rld::files::object_list& dependents,
146             rld::files::cache&       cache,
147             rld::symbols::table&     base_symbols,
148             rld::symbols::table&     symbols,
149             rld::symbols::table&     undefined)
150    {
151      rld::files::object_list objects;
152      cache.get_objects (objects);
153
154      /*
155       * First resolve any undefined symbols that are forced by the linker or
156       * the user.
157       */
158      resolver::resolve_symbols (dependents, cache, base_symbols, symbols,
159                                 undefined, "undefines");
160
161      /*
162       * Resolve the symbols in the object files.
163       */
164      for (rld::files::object_list::iterator oi = objects.begin ();
165           oi != objects.end ();
166           ++oi)
167      {
168        rld::files::object& object = *(*oi);
169        if (rld::verbose () >= RLD_VERBOSE_INFO)
170          std::cout << "resolver:resolving: top: "
171                    << object.name ().basename () << std::endl;
172        resolver::resolve_symbols (dependents, cache, base_symbols, symbols,
173                                   object.unresolved_symbols (),
174                                   object.name ().basename ());
175      }
176    }
177  }
178
179}
Note: See TracBrowser for help on using the repository browser.