source: rtems-tools/linkers/rld.cpp @ 59c3ebd

4.104.115
Last change on this file since 59c3ebd was 977c3de, checked in by Chris Johns <chrisj@…>, on 11/17/12 at 06:34:33

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: 4.0 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 <iostream>
30
31#include <sys/stat.h>
32
33#include <rld.h>
34
35#define RLD_VERSION_MAJOR   (1)
36#define RLD_VERSION_MINOR   (0)
37#define RLD_VERSION_RELEASE (0)
38
39namespace rld
40{
41  static int verbose_level = 0;
42
43  /**
44   * The option container.
45   */
46  typedef std::vector < std::string > library_container;
47
48  /**
49   * The libraries the user provided on the command line.
50   */
51  static library_container libpaths;
52
53  /**
54   * The libraries pass on the command line.
55   */
56  static library_container libs;
57
58  /**
59   * The libraries.
60   */
61  static library_container libraries;
62
63  /**
64   * The output passed on the command line.
65   */
66  static std::string output;
67
68  void
69  verbose_inc ()
70  {
71    ++verbose_level;
72  }
73
74  int
75  verbose ()
76  {
77    return verbose_level;
78  }
79
80  const std::string
81  version ()
82  {
83    std::string v = (rld::to_string (RLD_VERSION_MAJOR) + '.' +
84                     rld::to_string (RLD_VERSION_MINOR) + '.' +
85                     rld::to_string (RLD_VERSION_RELEASE));
86    return v;
87  }
88
89  const std::string
90  rtems_version ()
91  {
92    return rld::to_string (RTEMS_VERSION);
93  }
94
95  void
96  split (const std::string& str, strings& strs, char separator)
97  {
98    if (str.size ())
99    {
100      std::string::size_type start = 0;
101      std::string::size_type end = 0;
102      while (start != std::string::npos)
103      {
104        end = str.find_first_of (separator, start);
105        if (end == std::string::npos)
106          end = str.size ();
107        strs.push_back (str.substr (start, end - start));
108        start = str.find_first_not_of (separator, end);
109      }
110    }
111  }
112
113  void
114  map (rld::files::cache& cache, rld::symbols::table& symbols)
115  {
116    std::cout << "Archive files    : " << cache.archive_count () << std::endl;
117    std::cout << "Object files     : " << cache.object_count () << std::endl;
118    std::cout << "Exported symbols : " << symbols.size () << std::endl;
119
120    std::cout << "Archives:" << std::endl;
121    cache.output_archive_files (std::cout);
122    std::cout << "Objects:" << std::endl;
123    cache.output_object_files (std::cout);
124
125    std::cout << "Exported symbols:" << std::endl;
126    rld::symbols::output (std::cout, symbols);
127    std::cout << "Unresolved symbols:" << std::endl;
128    cache.output_unresolved_symbols (std::cout);
129  }
130
131  void
132  warn_unused_externals (rld::files::object_list& objects)
133  {
134    bool first = true;
135    for (rld::files::object_list::iterator oli = objects.begin ();
136         oli != objects.end ();
137         ++oli)
138    {
139      rld::files::object&     object = *(*oli);
140      rld::symbols::pointers& externals = object.external_symbols ();
141
142      if (rld::symbols::referenced (externals) != externals.size ())
143      {
144        if (first)
145        {
146          std::cout << "Unreferenced externals in object files:" << std::endl;
147          first = false;
148        }
149
150        std::cout << ' ' << object.name ().basename () << std::endl;
151
152        for (rld::symbols::pointers::iterator sli = externals.begin ();
153             sli != externals.end ();
154             ++sli)
155        {
156          rld::symbols::symbol& sym = *(*sli);
157          if (sym.references () == 0)
158            std::cout << "  " << sym.name () << std::endl;
159        }
160      }
161    }
162  }
163
164}
Note: See TracBrowser for help on using the repository browser.