[ec24a37] | 1 | /* |
---|
[8d1ab1f] | 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. |
---|
[8d1ab1f] | 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. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #if HAVE_CONFIG_H |
---|
| 26 | #include "config.h" |
---|
| 27 | #endif |
---|
| 28 | |
---|
| 29 | #include <fstream> |
---|
| 30 | #include <iostream> |
---|
| 31 | |
---|
| 32 | #include <errno.h> |
---|
| 33 | |
---|
| 34 | #include <rld.h> |
---|
| 35 | #include <rld.h> |
---|
| 36 | |
---|
| 37 | namespace rld |
---|
| 38 | { |
---|
| 39 | namespace outputter |
---|
| 40 | { |
---|
[810d0ad] | 41 | const std::string |
---|
| 42 | script_text (rld::files::object_list& dependents, |
---|
| 43 | rld::files::cache& cache) |
---|
| 44 | { |
---|
| 45 | std::ostringstream out; |
---|
| 46 | rld::files::object_list objects; |
---|
| 47 | |
---|
| 48 | cache.get_objects (objects); |
---|
| 49 | |
---|
| 50 | objects.merge (dependents); |
---|
| 51 | objects.unique (); |
---|
| 52 | |
---|
| 53 | for (rld::files::object_list::iterator oi = objects.begin (); |
---|
| 54 | oi != objects.end (); |
---|
| 55 | ++oi) |
---|
| 56 | { |
---|
| 57 | rld::files::object& obj = *(*oi); |
---|
| 58 | |
---|
| 59 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
| 60 | std::cout << " o: " << obj.name ().full () << std::endl; |
---|
| 61 | |
---|
| 62 | out << "o:" << obj.name ().basename () << std::endl; |
---|
| 63 | |
---|
| 64 | rld::symbols::table& unresolved = obj.unresolved_symbols (); |
---|
| 65 | |
---|
| 66 | int count = 0; |
---|
| 67 | for (rld::symbols::table::iterator ursi = unresolved.begin (); |
---|
| 68 | ursi != unresolved.begin (); |
---|
| 69 | ++ursi) |
---|
| 70 | { |
---|
[977c3de] | 71 | rld::symbols::symbol& urs = *((*ursi).second); |
---|
[810d0ad] | 72 | |
---|
| 73 | ++count; |
---|
| 74 | |
---|
| 75 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
| 76 | std::cout << " u: " << count << ':' << urs.name () << std::endl; |
---|
| 77 | |
---|
| 78 | out << " u:" << count << ':' << urs.name () << std::endl; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | return out.str (); |
---|
| 83 | } |
---|
| 84 | |
---|
[ec24a37] | 85 | void |
---|
| 86 | archive (const std::string& name, |
---|
[8d1ab1f] | 87 | rld::files::object_list& dependents, |
---|
[ec24a37] | 88 | rld::files::cache& cache) |
---|
| 89 | { |
---|
| 90 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
| 91 | std::cout << "outputter:archive: " << name << std::endl; |
---|
| 92 | |
---|
| 93 | rld::files::object_list objects; |
---|
| 94 | cache.get_objects (objects); |
---|
| 95 | |
---|
| 96 | for (rld::files::object_list::iterator oi = dependents.begin (); |
---|
| 97 | oi != dependents.end (); |
---|
| 98 | ++oi) |
---|
| 99 | objects.push_back (*oi); |
---|
| 100 | |
---|
[977c3de] | 101 | objects.unique (); |
---|
| 102 | |
---|
[ec24a37] | 103 | rld::files::archive arch (name); |
---|
| 104 | arch.create (objects); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void |
---|
| 108 | script (const std::string& name, |
---|
[8d1ab1f] | 109 | rld::files::object_list& dependents, |
---|
[ec24a37] | 110 | rld::files::cache& cache) |
---|
| 111 | { |
---|
| 112 | if (rld::verbose () >= RLD_VERBOSE_INFO) |
---|
| 113 | std::cout << "outputter:script: " << name << std::endl; |
---|
| 114 | |
---|
[8d1ab1f] | 115 | std::fstream out (name.c_str (), |
---|
[ec24a37] | 116 | std::ios_base::out | std::ios_base::trunc); |
---|
| 117 | |
---|
| 118 | /* |
---|
| 119 | * Tag for the shell to use. |
---|
| 120 | */ |
---|
| 121 | out << "!# rls" << std::endl; |
---|
| 122 | |
---|
[810d0ad] | 123 | try |
---|
| 124 | { |
---|
| 125 | out << script_text (dependents, cache); |
---|
| 126 | } |
---|
| 127 | catch (...) |
---|
| 128 | { |
---|
| 129 | out.close (); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | out.close (); |
---|
[ec24a37] | 133 | } |
---|
| 134 | } |
---|
| 135 | } |
---|