RTEMS Linker  0.0.1
RTEMS Tools Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
/Users/chris/Development/rtems/src/apps/rtl-host.chrisj/rld.h
Go to the documentation of this file.
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 <iostream>
29 #include <sstream>
30 #include <string>
31 
32 /**
33  * Path handling for Windows.
34  */
35 #if __WIN32__
36 #define RLD_PATH_SEPARATOR '\\'
37 #define RLD_PATHSTR_SEPARATOR ';'
38 #define RLD_PATHSTR_SEPARATOR_STR ";"
39 #define RLD_DRIVE_SEPARATOR (1)
40 #else
41 #define RLD_PATH_SEPARATOR '/'
42 #define RLD_PATHSTR_SEPARATOR ':'
43 #define RLD_PATHSTR_SEPARATOR_STR ":"
44 #define RLD_DRIVE_SEPARATOR (0)
45 #endif
46 
47 namespace rld
48 {
49  /**
50  * Forward declarations.
51  */
52  namespace files
53  {
54  class file;
55  class image;
56  class archive;
57  class object;
58  }
59 }
60 
61 #include <rld-elf-types.h>
62 #include <rld-symbols.h>
63 #include <rld-elf.h>
64 #include <rld-files.h>
65 
66 /**
67  * The debug levels.
68  */
69 #define RLD_VERBOSE_OFF (0)
70 #define RLD_VERBOSE_INFO (1)
71 #define RLD_VERBOSE_DETAILS (2)
72 #define RLD_VERBOSE_TRACE (3)
73 #define RLD_VERBOSE_TRACE_SYMS (4)
74 #define RLD_VERBOSE_TRACE_FILE (5)
75 #define RLD_VERBOSE_FULL_DEBUG (6)
76 
77 namespace rld
78 {
79  /**
80  * Convert a supported type to a string.
81  */
82  template <class T>
83  std::string to_string (T t, std::ios_base & (*f)(std::ios_base&) = std::dec)
84  {
85  std::ostringstream oss;
86  oss << f << t;
87  return oss.str();
88  }
89 
90  /**
91  * General error.
92  */
93  struct error
94  {
95  const std::string what;
96  const std::string where;
97 
98  error (const std::ostringstream& what, const std::string& where) :
99  what (what.str ()), where (where) {
100  }
101 
102  error (const std::string& what, const std::string& where) :
103  what (what), where (where) {
104  }
105  };
106 
107  /**
108  * A convenience macro to make where a file and line number.
109  */
110  #define rld_error_at(_what) \
111  rld::error (_what, std::string (__FILE__) + ":" + to_string (__LINE__))
112 
113  /**
114  * Increment the verbose level.
115  */
116  void verbose_inc ();
117 
118  /**
119  * Return the verbose level. Setting the flag more than once raises the
120  * level.
121  */
122  int verbose ();
123 
124  /**
125  * The version string.
126  */
127  const std::string version ();
128 
129  /**
130  * The RTEMS version string.
131  */
132  const std::string rtems_version ();
133 
134  /**
135  * Container of strings to hold the results of a split.
136  */
137  typedef std::vector < std::string > strings;
138 
139  /**
140  * Split a string into strings by the separator.
141  */
142  void split (const std::string& str, strings& strs, char separator);
143 
144  /**
145  * Map of the symbol table.
146  */
147  void map (rld::files::cache& cache, rld::symbols::table& symbols);
148 
149  /**
150  * Warn is externals in referenced object files are not used.
151  */
153 }
154 
155 #endif