source: rtems-tools/linkers/rld-outputter.cpp @ 810d0ad

4.104.115
Last change on this file since 810d0ad was 810d0ad, checked in by Chris Johns <chrisj@…>, on 10/23/12 at 00:58:34

Fix repeats in output when cmd line objects depend on each other.

If an object on the command line depends on another object the output
code wrote the object files and then the dependent files and a
command line object file that is dependent ended up in the object
and dependent lists. A simple merge and unique fixed it.

Also moved the script generation code into a separate function
that can be used in a application container.

  • Property mode set to 100644
File size: 4.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 <fstream>
30#include <iostream>
31
32#include <errno.h>
33
34#include <rld.h>
35#include <rld.h>
36
37namespace rld
38{
39  namespace outputter
40  {
41    const std::string
42    script_text (rld::files::object_list& dependents,
43                 rld::files::cache&       cache)
44    {
45      std::ostringstream      out;
46      rld::files::object_list objects;
47
48      cache.get_objects (objects);
49
50      objects.merge (dependents);
51      objects.unique ();
52
53      for (rld::files::object_list::iterator oi = objects.begin ();
54           oi != objects.end ();
55           ++oi)
56      {
57        rld::files::object& obj = *(*oi);
58
59        if (rld::verbose () >= RLD_VERBOSE_INFO)
60          std::cout << " o: " << obj.name ().full () << std::endl;
61
62        out << "o:" << obj.name ().basename () << std::endl;
63
64        rld::symbols::table& unresolved = obj.unresolved_symbols ();
65
66        int count = 0;
67        for (rld::symbols::table::iterator ursi = unresolved.begin ();
68             ursi != unresolved.begin ();
69             ++ursi)
70        {
71          rld::symbols::symbol& urs = (*ursi).second;
72
73          ++count;
74
75          if (rld::verbose () >= RLD_VERBOSE_INFO)
76            std::cout << " u: " << count << ':' << urs.name () << std::endl;
77
78          out << " u:" << count << ':' << urs.name () << std::endl;
79        }
80      }
81
82      return out.str ();
83    }
84
85    void
86    archive (const std::string&       name,
87             rld::files::object_list& dependents,
88             rld::files::cache&       cache)
89    {
90      if (rld::verbose () >= RLD_VERBOSE_INFO)
91        std::cout << "outputter:archive: " << name << std::endl;
92
93      rld::files::object_list objects;
94      cache.get_objects (objects);
95
96      for (rld::files::object_list::iterator oi = dependents.begin ();
97           oi != dependents.end ();
98           ++oi)
99        objects.push_back (*oi);
100
101      rld::files::archive arch (name);
102      arch.create (objects);
103    }
104
105    void
106    script (const std::string&       name,
107            rld::files::object_list& dependents,
108            rld::files::cache&       cache)
109    {
110      if (rld::verbose () >= RLD_VERBOSE_INFO)
111        std::cout << "outputter:script: " << name << std::endl;
112
113      std::fstream out (name.c_str (),
114                        std::ios_base::out | std::ios_base::trunc);
115
116      /*
117       * Tag for the shell to use.
118       */
119      out << "!# rls" << std::endl;
120
121      try
122      {
123        out << script_text (dependents, cache);
124      }
125      catch (...)
126      {
127        out.close ();
128      }
129
130      out.close ();
131
132#if 0
133      rld::files::object_list objects;
134      cache.get_objects (objects);
135
136      for (rld::files::object_list::iterator oi = objects.begin ();
137           oi != objects.end ();
138           ++oi)
139      {
140        rld::files::object& obj = *(*oi);
141
142        if (rld::verbose () >= RLD_VERBOSE_INFO)
143          std::cout << " o: " << obj.name ().full () << std::endl;
144
145        out << "o:" << obj.name ().basename () << std::endl;
146      }
147
148      for (rld::files::object_list::iterator oi = dependents.begin ();
149           oi != dependents.end ();
150           ++oi)
151      {
152        rld::files::object&  obj = *(*oi);
153        rld::symbols::table& unresolved = obj.unresolved_symbols ();
154
155        if (rld::verbose () >= RLD_VERBOSE_INFO)
156          std::cout << " d: " << obj.name ().full () << std::endl;
157
158        out << "d:" << obj.name ().basename () << std::endl;
159
160        int count = 0;
161        for (rld::symbols::table::iterator ursi = unresolved.begin ();
162             ursi != unresolved.begin ();
163             ++ursi)
164        {
165          ++count;
166          rld::symbols::symbol& urs = (*ursi).second;
167          out << " u:" << count << ':' << urs.name () << std::endl;
168        }
169      }
170#endif
171    }
172  }
173}
Note: See TracBrowser for help on using the repository browser.