source: rtems-tools/linkers/rld-outputter.cpp @ 977c3de

4.104.11
Last change on this file since 977c3de was 977c3de, checked in by Chris Johns <chrisj@…>, on Nov 17, 2012 at 6:34:33 AM

Refactor the ELF support to allow ELF write suppport.

The refactoring allows better reuse of the ELF support and cleans up
some hacks from the generic file and archive handling improving the
separation of the file handling from the file format, ie ELF. The
handling of ELF object files and ELF object files inside archives
is cleaner.

The refactor cleaned up the symbol handling where the symbols now
reside in the ELF file object and references are take in symbol
pointer containers and symbol table containers.

The main purpose of the refactor is to allow support for creating
and writing ELF files.

Also added an rtems-syms command where special symbol support
can be added.

  • Property mode set to 100644
File size: 3.4 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      objects.unique ();
102
103      rld::files::archive arch (name);
104      arch.create (objects);
105    }
106
107    void
108    script (const std::string&       name,
109            rld::files::object_list& dependents,
110            rld::files::cache&       cache)
111    {
112      if (rld::verbose () >= RLD_VERBOSE_INFO)
113        std::cout << "outputter:script: " << name << std::endl;
114
115      std::fstream out (name.c_str (),
116                        std::ios_base::out | std::ios_base::trunc);
117
118      /*
119       * Tag for the shell to use.
120       */
121      out << "!# rls" << std::endl;
122
123      try
124      {
125        out << script_text (dependents, cache);
126      }
127      catch (...)
128      {
129        out.close ();
130      }
131
132      out.close ();
133    }
134  }
135}
Note: See TracBrowser for help on using the repository browser.