1 | /* |
---|
2 | * Copyright (c) 2011-2013, 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 | * @mainpage RTEMS Linker Tools |
---|
18 | * |
---|
19 | * The RTEMS Linker is a suite of tools that create and manage @subpage rtems-apps |
---|
20 | * that are dynamically loadable by the @subpage rtems-rtl on target |
---|
21 | * hardware. The target code uses the standard `dlopen`, `dlclose` type calls |
---|
22 | * to load and manage modules, object files or archives on the target at |
---|
23 | * runtime. The RTEMS Linker forms a part of this process by helping managing |
---|
24 | * the object files, libraries and applications on a host machine. This host |
---|
25 | * processing simplifies the demands on the target and avoids wastefull excess |
---|
26 | * of files and data that may not be used at runtime. |
---|
27 | * |
---|
28 | * These tools are written in C++ with some 3rd party packages in C. The |
---|
29 | * license for this RTEMS Tools code is a BSD type open source license. The |
---|
30 | * package includes code from: |
---|
31 | * |
---|
32 | * -# @b efltoolchain - http://sourceforge.net/apps/trac/elftoolchain/ |
---|
33 | * -# @b libiberty - Libiberty code from GCC (GPL) |
---|
34 | * -# @b fastlz - http://fastlz.org/ |
---|
35 | * |
---|
36 | * The project uses a C++ demangler and PEX code from the GCC project. This |
---|
37 | * code is GPL making this project GPL. A platform independent way to execute |
---|
38 | * sub-processes and capture the output that is not GPL is most welcome. |
---|
39 | * |
---|
40 | * @subpage build-me details building this package with @subpage waf. |
---|
41 | * |
---|
42 | * The tools provided are: |
---|
43 | * |
---|
44 | * - @subpage rtems-ld |
---|
45 | * - @subpage rtems-syms |
---|
46 | * - @subpage rtems-rap |
---|
47 | * |
---|
48 | * ____________________________________________________________________________ |
---|
49 | * @copyright |
---|
50 | * Copyright (c) 2011-2013, Chris Johns <chrisj@rtems.org> |
---|
51 | * @copyright |
---|
52 | * Permission to use, copy, modify, and/or distribute this software for any |
---|
53 | * purpose with or without fee is hereby granted, provided that the above |
---|
54 | * copyright notice and this permission notice appear in all copies. |
---|
55 | * @copyright |
---|
56 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
---|
57 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
---|
58 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
---|
59 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
---|
60 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
---|
61 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
---|
62 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
63 | * |
---|
64 | */ |
---|
65 | |
---|
66 | /** |
---|
67 | * @page rtems-apps RTEMS Applications |
---|
68 | * |
---|
69 | * The RTEMS Linker and @ref rtems-rtl provides RTEMS with the ability to |
---|
70 | * support applications loaded and linked at runtime. RTEMS is a single address |
---|
71 | * space real-time operating system designed for embedded systems that are |
---|
72 | * statically linked therefore the idea of applications requires some extra |
---|
73 | * understanding when applied to RTEMS. They are not essential, rather they are |
---|
74 | * important in a range of systems that have the resources available to support |
---|
75 | * them. |
---|
76 | * |
---|
77 | * Applications allow: |
---|
78 | * |
---|
79 | * - A team to create a single verified base kernel image that is used by all |
---|
80 | * team developers. This kernel could be embedded on the target hardware and |
---|
81 | * applications loaded over a network. The verified kernel binary used during |
---|
82 | * development can be shipped without being changed. |
---|
83 | * |
---|
84 | * - Layered applications designed as modules that are loaded at runtime to |
---|
85 | * create a specific target environment for a specific system. This approach |
---|
86 | * allows development of modules that become verified components. An example |
---|
87 | * is the NASA Core Flight Executive. |
---|
88 | * |
---|
89 | * - Runtime configuration and loading of features or drivers based on |
---|
90 | * configuration data or detected hardware. This is important if your target |
---|
91 | * hardware has an external bus such as PCI. You can add a new driver to a |
---|
92 | * system without needing to rebuild the kernel and application lowering the |
---|
93 | * verify and validation costs. If these are high the savings can be |
---|
94 | * substantial. |
---|
95 | * |
---|
96 | * RTEMS is a single address space operating system therefore any code loaded |
---|
97 | * is loaded into that address space. This means applications are not operating |
---|
98 | * in a separate protected address space you typically get with host type |
---|
99 | * operating systems. You need to control and manage what you allow to load on |
---|
100 | * your system. This is no differerent to how single image RTEMS are currently |
---|
101 | * created and managed. The point being RTEMS applications only changes the way |
---|
102 | * you package and maintain your applications and do not provide any improved |
---|
103 | * security or protection. You need to do this as your currently do with |
---|
104 | * testing and careful design. |
---|
105 | * |
---|
106 | * RTEMS is statically linked to a fixed address and does not support dynamic |
---|
107 | * ELF files. Dynamic ELF files are designed for use in virtual memory |
---|
108 | * protected address space operating systems. They contain Position Independent |
---|
109 | * Code (PIC) code, Procedure Linkage Tables (PLT) and Global Offset Tables |
---|
110 | * (GOT) and are effective in not only allowing dynamic linking at runtime but |
---|
111 | * also the sharing of the code between separate process address spaces. Using |
---|
112 | * virtual memory and a memory management unit, a protected address space |
---|
113 | * operating system can efficiently share code between processes with minimal |
---|
114 | * performance overhead. RTEMS has no such need because it is a single address |
---|
115 | * space and all code is shared therefore ELF dynamic files only add complexity |
---|
116 | * and performance overhead. This means RTEMS needs a target based run-time |
---|
117 | * link editor that can relocate and fix up static code when loading it and |
---|
118 | * RTEMS loadable files need to contain the symbols and relocation records to |
---|
119 | * allow relocation to happen. |
---|
120 | * |
---|
121 | * The @ref rtems-rtl supports the followiing file formats: |
---|
122 | * |
---|
123 | * -# Relocatable ELF (ELF) |
---|
124 | * -# RTEMS Application (RAP) |
---|
125 | * -# Archive (AR) Libraries with GNU extensions |
---|
126 | * |
---|
127 | * ### Relocation ELF Files |
---|
128 | * |
---|
129 | * The @ref rtems-rtl can load standard relocatable ELF format files. They can |
---|
130 | * be stripped or unstripped. This ELF file is the standard output from the |
---|
131 | * compiler and is contained in the standard libraries. |
---|
132 | * |
---|
133 | * ### RTEMS Application (RAP) Files. |
---|
134 | * |
---|
135 | * The @ref rtems-rtl can load RAP format files. This format is RTEMS specific |
---|
136 | * and is designed to minimise the overhead and resources needed to load the |
---|
137 | * file on the target. A RAP file is compressed using LZ77 compression and |
---|
138 | * contains only the following sections: |
---|
139 | * |
---|
140 | * - `.text` - The executable code section. |
---|
141 | * - `.const` - The constants and strings section. |
---|
142 | * - `.ctor` - The constructor table section. |
---|
143 | * - `.dtor` - The destructor table section. |
---|
144 | * - `.data` - The initialised data section. |
---|
145 | * |
---|
146 | * The `.bss` uninitialised data section is only a size. A RAP file also |
---|
147 | * contains a symbol string table and symbol table that are directly loadable |
---|
148 | * into into the target memory. Finally the RAP contains the relocation |
---|
149 | * records. The format is structured so it can be read and processed as a |
---|
150 | * stream with the need to seek on the file. |
---|
151 | * |
---|
152 | * The @ref rtems-ld can output RAP format files suitable for loading. It will |
---|
153 | * take the object files from the command line and the referenced files from |
---|
154 | * the libraries and merge all the sections, symbols and relocation records to |
---|
155 | * create the RAP format file. |
---|
156 | * |
---|
157 | * RAP format files are the most efficient way to load applications or modules |
---|
158 | * because all object files are merged into an single image. Each file loaded |
---|
159 | * on the target has and overhead therefore lowering the number of files loaded |
---|
160 | * lowers the overhead. You could also use the standard linker to incrementally |
---|
161 | * link the command line object files to archieve the same effect. |
---|
162 | * |
---|
163 | * ### Archive (AR) Library Files |
---|
164 | * |
---|
165 | * The @ref rtems-rtl can load from archive ior library type files. The file |
---|
166 | * name syntax lets a user reference a file in an archive. The format is: |
---|
167 | * |
---|
168 | * @par |
---|
169 | * `libme.a:foo.o@12345` |
---|
170 | * |
---|
171 | * where `libme.a` is the archive file name, `foo.o` is the file in the archive |
---|
172 | * and `@12345` is optionally the offset in the archive where the file |
---|
173 | * starts. The optional offset helps speed up load by avoiding the file name |
---|
174 | * table search. If the archive is stable and known the offset will be |
---|
175 | * fixed. If the file is located at the offset the file name table is searched. |
---|
176 | * |
---|
177 | * At this point in time only ELF files can be loaded from archives. Loading of |
---|
178 | * RAP format files is planned. |
---|
179 | * |
---|
180 | * ## An Application |
---|
181 | * |
---|
182 | * Applications are created the same way you create standard host type |
---|
183 | * programs. You compile the source files and link them using the @ref |
---|
184 | * rtems-ld. |
---|
185 | * |
---|
186 | * @code |
---|
187 | * $ rtems-ld --base my-rtems foo.o bar.o -o my-app.rap -L /lib/path -lstuff |
---|
188 | * @endcode |
---|
189 | * |
---|
190 | * The command line of the @ref rtems-ld is similar to a standard linker with |
---|
191 | * some extra features specific to RTEMS. You provide a list of object files, |
---|
192 | * libraries and library paths plus you need to provide the RTEMS kernel image |
---|
193 | * you will use to load the application. The RTEMS kernel image provides the |
---|
194 | * symbols in the kernel to the linker. Errors will be generated if symbols are |
---|
195 | * not located. |
---|
196 | * |
---|
197 | * The linker can output a archive of ELF files, a RAP file for a text script |
---|
198 | * of files that need to be loaded. |
---|
199 | * |
---|
200 | * The script lets you load and link the application at runtime on the |
---|
201 | * target. You need to copy the libraries referenced to the target. |
---|
202 | * |
---|
203 | * If you break your application into separate modules and each module |
---|
204 | * references a symbol in a library that is not in the base image the linker |
---|
205 | * will include the object file containing the symbol into each application |
---|
206 | * module. This is only of concern for the RAP format because it merges the |
---|
207 | * object files together. With the archive and scripts the loader will not load |
---|
208 | * object files with duplicate symbols. |
---|
209 | * |
---|
210 | * @note In time the linker will gain an option to not pull object modules from |
---|
211 | * libraries into the RAP file. Another option will be added that will |
---|
212 | * copy referenced library object files into a target library all |
---|
213 | * application modules can share. |
---|
214 | * |
---|
215 | * ## Linking |
---|
216 | * |
---|
217 | * The @ref rtems-ld places the command line object files in the output image |
---|
218 | * and any reference object files found in libraries. If a symbol is located in |
---|
219 | * the kernel base image it is not searched for in the libraries. |
---|
220 | * |
---|
221 | * The architecture is automatically detected by inspecting the first object |
---|
222 | * file passed on the command line. All future object files loaded must match |
---|
223 | * the architecture for an error is raised. The linker supports all |
---|
224 | * architectures in a single binrary. It is not like the GNU tools which are |
---|
225 | * specific to an architecture. |
---|
226 | * |
---|
227 | * The linker needs to be able to locate the C compiler for the architecture |
---|
228 | * being linked. The compiler can be in the path for a command line option can |
---|
229 | * explicitly set the compiler. The compiler is used to locate the standard |
---|
230 | * libraries such as the C library. |
---|
231 | * |
---|
232 | * |
---|
233 | */ |
---|
234 | |
---|
235 | /** |
---|
236 | * @page rtems-rtl RTEMS Target Link Editor |
---|
237 | * |
---|
238 | * The RTEMS Target link editor is a C module you link to the RTEMS kernel to |
---|
239 | * provide the `dlopen`, `dlclose` etc family of calls. This code is a stand |
---|
240 | * alone project: |
---|
241 | * |
---|
242 | * @par |
---|
243 | * http://git.rtems.org/chrisj/rtl.git |
---|
244 | */ |
---|
245 | |
---|
246 | /** |
---|
247 | * @page build-me Building The RTEMS Linker |
---|
248 | * |
---|
249 | * This package is written in C++ therefore you need a current working C++ |
---|
250 | * compiler for your host. The GCC or clang compilers can be used and clang was |
---|
251 | * used during the development. The build system is @ref waf. |
---|
252 | * |
---|
253 | * -# Clone the git repository: |
---|
254 | * @code |
---|
255 | * $ git clone http://git.rtems.org/chrisj/rtl-host.git rtl-host.git |
---|
256 | * @endcode |
---|
257 | * -# Configure with the default C++ compiler, default options, and an install |
---|
258 | * prefix of `$HOME/development/rtems/4.11`: |
---|
259 | * @code |
---|
260 | * $ waf configure --prefix=$HOME/development/rtems/4.11 |
---|
261 | * @endcode |
---|
262 | * With @ref waf you build in the source directory and the @ref waf script |
---|
263 | * (`wscript`) will create a host specific directory. On MacOS the output is in |
---|
264 | * `build-darwin`. If you clean the build tree by deleting this directly you |
---|
265 | * will need to run the configure stage again. |
---|
266 | * @note The nominal RTEMS prefix is `/opt/rtems-4.11` where `4.11` is the |
---|
267 | * version of RTEMS you are building the tools for. If you are using |
---|
268 | * RTEMS 4.10 or a different version please use that version number. I |
---|
269 | * always work under my home directory and under the `development/rtems` |
---|
270 | * tree and then use the version number. |
---|
271 | * -# Build the tools: |
---|
272 | * @code |
---|
273 | * $ waf |
---|
274 | * @endcode |
---|
275 | * -# Install the tools to the configured prefix: |
---|
276 | * @code |
---|
277 | * $ waf install |
---|
278 | * @endcode |
---|
279 | * |
---|
280 | * You will now have the tools contained in this package build and installed. |
---|
281 | * |
---|
282 | * At this stage of the project's development there are no tests. I am wondering |
---|
283 | * if this could be a suitable GSoC project. |
---|
284 | * |
---|
285 | * To build with `clang` use the documented @ref waf method: |
---|
286 | * @code |
---|
287 | * $ CC=clang waf configure --prefix=$HOME/development/rtems/4.11 |
---|
288 | * @endcode |
---|
289 | * |
---|
290 | * You can add some extra options to @ref waf's configure to change the |
---|
291 | * configuration. The options are: |
---|
292 | * @code |
---|
293 | * --rtems-version=RTEMS_VERSION |
---|
294 | * Set the RTEMS version |
---|
295 | * --c-opts=C_OPTS Set build options, default: -O2. |
---|
296 | * --show-commands Print the commands as strings. |
---|
297 | * @endcode |
---|
298 | * |
---|
299 | * - @b --rtems-version Set the RTEMS version number. |
---|
300 | * Not used. |
---|
301 | * - @b --c-opts Set the C and C++ compiler flags the tools are built with. For |
---|
302 | * example to disable all optimization flags to allow better debugging do: |
---|
303 | * @code |
---|
304 | * $ waf configure --prefix=$HOME/development/rtems/4.11 --c-opts= |
---|
305 | * @endcode |
---|
306 | * - @b --show-commands Prints the command string used to the invoke the |
---|
307 | * compiler or linker. @ref waf normally prints a summary type line. |
---|
308 | * |
---|
309 | */ |
---|
310 | |
---|
311 | /** |
---|
312 | * @page waf Waf |
---|
313 | * |
---|
314 | * It is best you install waf by just downloading it from the Waf project |
---|
315 | * website: |
---|
316 | * |
---|
317 | * @par |
---|
318 | * http://code.google.com/p/waf/ |
---|
319 | * |
---|
320 | * Waf is a Python program so you will also need to have a current Python |
---|
321 | * version installed and in your path. |
---|
322 | * |
---|
323 | * I download the latest "run from writable folder" version named single waf |
---|
324 | * file from http://code.google.com/p/waf/downloads/list to `$HOME/bin` and |
---|
325 | * symlink it to `waf`. The directory `$HOME/bin` is in my path. |
---|
326 | * |
---|
327 | * @code |
---|
328 | * $ cd $HOME/bin |
---|
329 | * $ curl http://waf.googlecode.com/files/waf-1.7.9 > waf-1.7.9 |
---|
330 | * % Total % Received % Xferd Average Speed Time Time Time Current |
---|
331 | * Dload Upload Total Spent Left Speed |
---|
332 | * 100 90486 100 90486 0 0 39912 0 0:00:02 0:00:02 --:--:-- 79934 |
---|
333 | * $ rm -f waf |
---|
334 | * $ chmod +x waf-1.7.9 |
---|
335 | * $ ln -s waf-1.7.9 waf |
---|
336 | * $ ./waf --version |
---|
337 | * waf 1.7.9 (9e92489dbc008e4abae9c147b1d63b48296797c2) |
---|
338 | * @endcode |
---|
339 | */ |
---|
340 | |
---|
341 | /** |
---|
342 | * @page rtems-ld RTEMS Linker |
---|
343 | * |
---|
344 | * The RTEMS Linker is a single tool that lets you create applications. It is a |
---|
345 | * special kind of linker and does not perform all the functions found in a |
---|
346 | * normal linker. RAP format output performs a partial increment link. |
---|
347 | * |
---|
348 | * ## Command |
---|
349 | * |
---|
350 | * `rtems-ld [options] objects` |
---|
351 | * |
---|
352 | * ## Options |
---|
353 | * |
---|
354 | * - @e Help (@b -h @b --help): \n |
---|
355 | * Print the command line help then exit. |
---|
356 | * |
---|
357 | * - @e Version (@b -V @b --version): \n |
---|
358 | * Print the linker's version then exit. |
---|
359 | * |
---|
360 | * - @e Verbose (@b -v @b --verbose): \n |
---|
361 | * Control the trace output level. The RTEMS linker is always built with |
---|
362 | * trace logic. The more times this appears on the command the more detailed |
---|
363 | * the output becomes. The amount of output can be large at higher levels. |
---|
364 | * |
---|
365 | * - @e Warnings (@b -w @--warn): \n |
---|
366 | * Print warnings. |
---|
367 | * |
---|
368 | * - @e Map (@b -M @b --map): \n |
---|
369 | * Generate map output to stdout. |
---|
370 | * |
---|
371 | * - @e Output (@b -o @b --output): \n |
---|
372 | * Set the output file name. |
---|
373 | * |
---|
374 | * - @e Output @e Format (@b -O @b --out-format): \n |
---|
375 | * Set the output format. The valid formats are: |
---|
376 | * Format | Description |
---|
377 | * -----------|---------------------------------------- |
---|
378 | * @b rap |RTEMS application (LZ77, single image) |
---|
379 | * @b elf |ELF application (script, ELF files) |
---|
380 | * @b script |Script format (list of object files) |
---|
381 | * @b archive |Archive format (collection of ELF files) |
---|
382 | * |
---|
383 | * - @e Library @e Path (@b -L @b --lib-path): \n |
---|
384 | * Add a library path. More than one path can be added with multiple library |
---|
385 | * path options. |
---|
386 | * |
---|
387 | * - @e Library (@b -l @b --lib): \n |
---|
388 | * Add a library. More than one library can be added with multiple library |
---|
389 | * paths. |
---|
390 | * |
---|
391 | * - @e No @e Standard @e Libraries (@b -n @b --no-stdlibs): \n |
---|
392 | * Do not search the standard libraries. The linker uses the architecture C |
---|
393 | * compiler to locate the installed standard libraries and these are |
---|
394 | * automatically searched. If this option is used the C compiler is not |
---|
395 | * called and the libraries are not added to the search list. |
---|
396 | * |
---|
397 | * - @e Entry @e Point (@b -e @b --entry): \n |
---|
398 | * Set the entry point. This is used with the RAP format and defaults to |
---|
399 | * `rtems`. The entry point is called when a RAP file is loaded by the |
---|
400 | * target RAP loader. |
---|
401 | * |
---|
402 | * - @e Define @e Symbol (@b -d @b --define): \n |
---|
403 | * Add a symbol to the symbol table. More than one symbol can be added |
---|
404 | * with multiple define options. |
---|
405 | * |
---|
406 | * - @e Undefined @e Symbol (@b -u @b --undefined): \n |
---|
407 | * Add an undefined symbol to the undefined symbol list. More than one |
---|
408 | * undefined symbol can be added with multiple undefined options. This |
---|
409 | * options will pull specific code into the output image. |
---|
410 | * |
---|
411 | * - @e RTEMS @e Kernel (@b -b @b --base): \n |
---|
412 | * Set the RTEMS kernel image. This is the ELF file of the RTEMS kernel |
---|
413 | * that will load the output from the linker. The RTEMS kernel is the |
---|
414 | * @e base module or image. The linker does not pull the symbol from a |
---|
415 | * library if the symbol is found in the base module. The kernel will |
---|
416 | * load the target symbol table with these symbols so they can be |
---|
417 | * resolved at runtime. |
---|
418 | * |
---|
419 | * - @e Architecture @e C @e Compiler (@b -C @b --cc): \n |
---|
420 | * Set the architecture's C compiler. This is used to find the standard |
---|
421 | * libraries. |
---|
422 | * |
---|
423 | * - @e Tool @e Prefix (@b -E @b --exec-prefix): \n |
---|
424 | * Set the tool prefix. The tool prefix is the architecture and this is |
---|
425 | * normally automatically set by inspecting the first object file |
---|
426 | * loaded. This option allows the automatic detection to be overridden. |
---|
427 | * |
---|
428 | * - @e Machine @e Architecture (@b -a @b --march): \n |
---|
429 | * Set the machine architecture. |
---|
430 | * |
---|
431 | * - @e Machine @e CPU (@b -c @b --mcpu): \n |
---|
432 | * Set the machine architecture's CPU. |
---|
433 | */ |
---|
434 | |
---|
435 | /** |
---|
436 | * @page rtems-syms RTEMS Symbols Utility |
---|
437 | * |
---|
438 | * The symbols tool lets you see symbols in various RTEMS support file formats. |
---|
439 | */ |
---|
440 | |
---|
441 | /** |
---|
442 | * @page rtems-rap RTEMS Application (RAP) Utility |
---|
443 | * |
---|
444 | * The symbols tool lets you see symbols in various RTEMS support file formats. |
---|
445 | */ |
---|