source: rtems-tools/rtemstoolkit/rld.h @ df7fd26

4.104.115
Last change on this file since df7fd26 was df7fd26, checked in by Chris Johns <chrisj@…>, on 10/28/14 at 08:13:19

toolkit: Update the comment.

  • Property mode set to 100644
File size: 5.8 KB
RevLine 
[ec24a37]1/*
[1d60a4a]2 * Copyright (c) 2011, Chris Johns <chrisj@rtems.org>
[ec24a37]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.
[1d60a4a]7 *
[ec24a37]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 readies the RTEMS object files for dynamic linking.
22 *
23 */
24
25#if !defined (_RLD_H_)
26#define _RLD_H_
27
[b6d7f5f]28#include <algorithm>
29#include <cctype>
30#include <functional>
[ec24a37]31#include <iostream>
[b6d7f5f]32#include <locale>
[ec24a37]33#include <sstream>
34#include <string>
35
36/**
37 * Path handling for Windows.
38 */
39#if __WIN32__
40#define RLD_PATH_SEPARATOR        '\\'
[a72a9e35]41#define RLD_PATH_SEPARATOR_STR    "\\"
[ec24a37]42#define RLD_PATHSTR_SEPARATOR     ';'
43#define RLD_PATHSTR_SEPARATOR_STR ";"
44#define RLD_DRIVE_SEPARATOR       (1)
[4fd758e]45#define RLD_LINE_SEPARATOR        "\r\n"
[ec24a37]46#else
47#define RLD_PATH_SEPARATOR        '/'
[a72a9e35]48#define RLD_PATH_SEPARATOR_STR    "/"
[ec24a37]49#define RLD_PATHSTR_SEPARATOR     ':'
50#define RLD_PATHSTR_SEPARATOR_STR ":"
51#define RLD_DRIVE_SEPARATOR       (0)
[4fd758e]52#define RLD_LINE_SEPARATOR        "\n"
[ec24a37]53#endif
54
55namespace rld
56{
57  /**
58   * Forward declarations.
59   */
60  namespace files
61  {
62    class file;
63    class image;
64    class archive;
65    class object;
66  }
67}
68
69#include <rld-elf-types.h>
70#include <rld-symbols.h>
71#include <rld-elf.h>
72#include <rld-files.h>
73
74/**
75 * The debug levels.
76 */
77#define RLD_VERBOSE_OFF        (0)
78#define RLD_VERBOSE_INFO       (1)
79#define RLD_VERBOSE_DETAILS    (2)
80#define RLD_VERBOSE_TRACE      (3)
[1d60a4a]81#define RLD_VERBOSE_TRACE_SYMS (4)
[13b9f2b]82#define RLD_VERBOSE_TRACE_FILE (5)
83#define RLD_VERBOSE_FULL_DEBUG (6)
[ec24a37]84
85namespace rld
86{
87  /**
88   * General error.
89   */
90  struct error
91  {
92    const std::string what;
93    const std::string where;
94
95    error (const std::ostringstream& what, const std::string& where) :
96      what (what.str ()), where (where) {
97    }
98
99    error (const std::string& what, const std::string& where) :
100      what (what), where (where) {
101    }
102  };
103
104  /**
105   * A convenience macro to make where a file and line number.
106   */
107  #define rld_error_at(_what) \
108    rld::error (_what, std::string (__FILE__) + ":" + to_string (__LINE__))
109
[b6d7f5f]110  /**
111   * Convert a supported type to a string.
112   */
113  template <class T>
114  std::string to_string (T t, std::ios_base & (*f)(std::ios_base&) = std::dec)
115  {
116    std::ostringstream oss;
117    oss << f << t;
118    return oss.str();
119  }
120
121  /**
122   * A container of strings.
123   */
124  typedef std::vector < std::string > strings;
125
[7ccb6701]126  /**
127   * Does a string start with another string ?
128   */
[6506aa1]129  bool starts_with(const std::string& s1, const std::string& s2);
[7ccb6701]130
[b6d7f5f]131  /**
132   * Trim from start.
133   */
[6506aa1]134  const std::string ltrim (const std::string& s);
[b6d7f5f]135
136  /**
137   * Trim from end.
138   */
[6506aa1]139  const std::string rtrim (const std::string& s);
[b6d7f5f]140
141  /**
142   * Trim from both ends.
143   */
[6506aa1]144  const std::string trim (const std::string& s);
[b6d7f5f]145
[058d502]146  /**
147   * Dequote a string.
148   */
[6506aa1]149  const std::string dequote (const std::string& s);
[058d502]150
151  /**
152   * Find and replace.
153   */
[6506aa1]154  const std::string find_replace(const std::string& sin,
155                                 const std::string& out,
156                                 const std::string& in);
[058d502]157
[b6d7f5f]158  /**
159   * Split the string in a contain of strings based on the the
160   * delimiter. Optionally trim any white space or include empty string.
161   *
162   * @todo The split should optionally honour string quoting.
163   */
[6506aa1]164  const strings split (strings&           se,
165                       const std::string& s,
166                       char               delimiter = ' ',
167                       bool               strip_quotes = true,
168                       bool               strip_whitespace = true,
169                       bool               empty = false);
[b6d7f5f]170
171  /**
172   * Join the strings together with the separator.
173   */
[6506aa1]174  const std::string join (const strings& ss, const std::string& separator);
[b6d7f5f]175
[7ccb6701]176  /**
177   * Convert a string to lower case.
178   */
[6506aa1]179  const std::string tolower (const std::string& sin);
[7ccb6701]180
[ec24a37]181  /**
182   * Increment the verbose level.
183   */
184  void verbose_inc ();
185
186  /**
187   * Return the verbose level. Setting the flag more than once raises the
188   * level.
189   */
[30a7f06]190  int verbose (int level = 0);
[ec24a37]191
192  /**
193   * The version string.
194   */
195  const std::string version ();
196
197  /**
198   * Container of strings to hold the results of a split.
199   */
200  typedef std::vector < std::string > strings;
201
[b7ad4a2]202  /**
203   * Set the command line.
204   */
205  void set_cmdline (int argc, char* argv[]);
206
207  /**
208   * Get the command line.
209   */
210  const std::string get_cmdline ();
211
[6506aa1]212  /**
213   * Set the progname.
214   */
215  void set_progname (const std::string& progname);
216
217  /**
218   * Get the progname. This is an absolute path.
219   */
220  const std::string get_progname ();
221
222  /**
223   * Get the program name.
224   */
225  const std::string get_program_name ();
226
227  /**
228   * Get the program path.
229   */
230  const std::string get_program_path ();
231
232  /**
233   * Get the current install prefix. If the path to the executable has 'bin' as
234   * the executable's parent directory it is assumed the executable has been
235   * installed under a standard PREFIX. If "bin" is not found return the
236   * executable's absolute path.
237   */
238  const std::string get_prefix ();
239
[ec24a37]240  /**
[df7fd26]241   * Map of the cache and the symbol table.
[ec24a37]242   */
243  void map (rld::files::cache& cache, rld::symbols::table& symbols);
244
245  /**
[6506aa1]246   * Warn if externals in referenced object files are not used.
[ec24a37]247   */
248  void warn_unused_externals (rld::files::object_list& objects);
249}
250
251#endif
Note: See TracBrowser for help on using the repository browser.