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

4.104.11
Last change on this file since df7fd26 was df7fd26, checked in by Chris Johns <chrisj@…>, on Oct 28, 2014 at 8:13:19 AM

toolkit: Update the comment.

  • Property mode set to 100644
File size: 5.8 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 readies the RTEMS object files for dynamic linking.
22 *
23 */
24
25#if !defined (_RLD_H_)
26#define _RLD_H_
27
28#include <algorithm>
29#include <cctype>
30#include <functional>
31#include <iostream>
32#include <locale>
33#include <sstream>
34#include <string>
35
36/**
37 * Path handling for Windows.
38 */
39#if __WIN32__
40#define RLD_PATH_SEPARATOR        '\\'
41#define RLD_PATH_SEPARATOR_STR    "\\"
42#define RLD_PATHSTR_SEPARATOR     ';'
43#define RLD_PATHSTR_SEPARATOR_STR ";"
44#define RLD_DRIVE_SEPARATOR       (1)
45#define RLD_LINE_SEPARATOR        "\r\n"
46#else
47#define RLD_PATH_SEPARATOR        '/'
48#define RLD_PATH_SEPARATOR_STR    "/"
49#define RLD_PATHSTR_SEPARATOR     ':'
50#define RLD_PATHSTR_SEPARATOR_STR ":"
51#define RLD_DRIVE_SEPARATOR       (0)
52#define RLD_LINE_SEPARATOR        "\n"
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)
81#define RLD_VERBOSE_TRACE_SYMS (4)
82#define RLD_VERBOSE_TRACE_FILE (5)
83#define RLD_VERBOSE_FULL_DEBUG (6)
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
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
126  /**
127   * Does a string start with another string ?
128   */
129  bool starts_with(const std::string& s1, const std::string& s2);
130
131  /**
132   * Trim from start.
133   */
134  const std::string ltrim (const std::string& s);
135
136  /**
137   * Trim from end.
138   */
139  const std::string rtrim (const std::string& s);
140
141  /**
142   * Trim from both ends.
143   */
144  const std::string trim (const std::string& s);
145
146  /**
147   * Dequote a string.
148   */
149  const std::string dequote (const std::string& s);
150
151  /**
152   * Find and replace.
153   */
154  const std::string find_replace(const std::string& sin,
155                                 const std::string& out,
156                                 const std::string& in);
157
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   */
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);
170
171  /**
172   * Join the strings together with the separator.
173   */
174  const std::string join (const strings& ss, const std::string& separator);
175
176  /**
177   * Convert a string to lower case.
178   */
179  const std::string tolower (const std::string& sin);
180
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   */
190  int verbose (int level = 0);
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
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
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
240  /**
241   * Map of the cache and the symbol table.
242   */
243  void map (rld::files::cache& cache, rld::symbols::table& symbols);
244
245  /**
246   * Warn if externals in referenced object files are not used.
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.