summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2014-09-06 20:19:45 +1000
committerChris Johns <chrisj@rtems.org>2014-09-06 20:19:45 +1000
commit0e448a4e8eff2f433f10309c8c832faa5adf4b94 (patch)
tree6a98a5b20ffd2bc8dc2d8ae0292c6b772234676b
parent82775e9e7006f2a66d900f7a99699788bfd5cd18 (diff)
Refactor the CC flags. Fix the various linkers. The trace linker is compiling.
-rw-r--r--rld-cc.cpp288
-rw-r--r--rld-cc.h124
-rw-r--r--rld-process.cpp17
-rw-r--r--rld-process.h5
-rw-r--r--rld-rtems.cpp71
-rw-r--r--rtems-ld.cpp17
-rw-r--r--rtems-ra.cpp16
-rw-r--r--rtems-syms.cpp16
-rw-r--r--rtems-tld.cpp63
-rw-r--r--rtld-base.ini2
-rw-r--r--test-trace-1.h7
-rw-r--r--test-trace-2.h7
12 files changed, 462 insertions, 171 deletions
diff --git a/rld-cc.cpp b/rld-cc.cpp
index f69b7c9..5fe7f89 100644
--- a/rld-cc.cpp
+++ b/rld-cc.cpp
@@ -26,20 +26,24 @@ namespace rld
{
namespace cc
{
- std::string cc;
- std::string cc_name = "gcc";
- std::string exec_prefix;
- std::string cppflags;
- std::string cflags;
- std::string cxxflags;
- std::string ldflags;
- std::string warning_cflags;
- std::string include_cflags;
- std::string machine_cflags;
- std::string spec_cflags;
- std::string install_path;
- std::string programs_path;
- std::string libraries_path;
+ static std::string cc; //< The CC executable as absolute path.
+ static bool cc_set; //< True when the CC has been set.
+ static std::string cc_name = "gcc"; //< The CC name, ie gcc, clang.
+ static std::string exec_prefix; //< The CC executable prefix.
+
+ static std::string cppflags; //< The CPP flags.
+ static std::string cflags; //< The CC flags.
+ static std::string cxxflags; //< The CXX flags.
+ static std::string ldflags; //< The LD flags.
+
+ static std::string warning_cflags; //< The warning flags in cflags.
+ static std::string include_cflags; //< The include flags in cflags.
+ static std::string machine_cflags; //< The machine flags in cflags.
+ static std::string spec_cflags; //< The spec flags in cflags.
+
+ static std::string install_path; //< The CC reported install path.
+ static std::string programs_path; //< The CC reported programs path.
+ static std::string libraries_path; //< The CC reported libraries path.
/**
* The list of standard libraries.
@@ -48,51 +52,6 @@ namespace rld
static const char* std_lib_c = "libgcc.a" RPS "libssp.a" RPS "libc.a";
static const char* std_lib_cplusplus = "libstdc++.a";
- void
- make_cc_command (rld::process::arg_container& args)
- {
- /*
- * Use the absolute path to CC if provided.
- */
- if (!cc.empty ())
- args.push_back (cc);
- else
- {
- std::string cmd = cc_name;
- if (!exec_prefix.empty ())
- cmd = exec_prefix + "-rtems" + rld::rtems_version () + '-' + cmd;
- args.push_back (cmd);
- }
- }
-
- void
- add_cppflags (rld::process::arg_container& args)
- {
- if (!cppflags.empty ())
- args.push_back (cppflags);
- }
-
- void
- add_cflags (rld::process::arg_container& args)
- {
- if (!cflags.empty ())
- args.push_back (cflags);
- }
-
- void
- add_cxxflags (rld::process::arg_container& args)
- {
- if (!cxxflags.empty ())
- args.push_back (cxxflags);
- }
-
- void
- add_ldflags (rld::process::arg_container& args)
- {
- if (!ldflags.empty ())
- args.push_back (ldflags);
- }
-
const std::string
strip_cflags (const std::string& flags)
{
@@ -270,6 +229,205 @@ namespace rld
}
}
+ void
+ set_cc (const std::string& cc_)
+ {
+ cc = cc_;
+ cc_set = true;
+ }
+
+ const std::string
+ get_cc ()
+ {
+ return cc;
+ }
+
+ bool
+ is_cc_set ()
+ {
+ return cc_set;
+ }
+
+ void
+ set_exec_prefix (const std::string& exec_prefix_)
+ {
+ exec_prefix = exec_prefix_;
+ }
+
+ const std::string
+ get_exec_prefix ()
+ {
+ return exec_prefix;
+ }
+
+ bool is_exec_prefix_set ()
+ {
+ return !exec_prefix.empty ();
+ }
+
+ void
+ set_flags (const std::string& flags,
+ const std::string& arch,
+ const std::string& path,
+ flag_type type)
+ {
+ std::string* oflags;
+ switch (type)
+ {
+ case ft_cppflags:
+ oflags = &cppflags;
+ break;
+ case ft_cflags:
+ oflags = &cflags;
+ break;
+ case ft_cxxflags:
+ oflags = &cxxflags;
+ break;
+ case ft_ldflags:
+ oflags = &ldflags;
+ break;
+ default:
+ throw rld::error ("Invalid flag type", "CC set flags");
+ }
+ (*oflags) = filter_flags (flags, arch, path, type);
+ }
+
+ void
+ set_flags (const std::string& flags, flag_type type)
+ {
+ std::string arch;
+ std::string path;
+ set_flags (flags, arch, path, type);
+ }
+
+ void
+ append_flags (const std::string& flags,
+ const std::string& arch,
+ const std::string& path,
+ flag_type type)
+ {
+ std::string* oflags;
+ switch (type)
+ {
+ case ft_cppflags:
+ oflags = &cppflags;
+ break;
+ case ft_cflags:
+ oflags = &cflags;
+ break;
+ case ft_cxxflags:
+ oflags = &cxxflags;
+ break;
+ case ft_ldflags:
+ oflags = &ldflags;
+ break;
+ default:
+ throw rld::error ("Invalid flag type", "CC set flags");
+ }
+ if (oflags->empty ())
+ *oflags += filter_flags (flags, arch, path, type);
+ else
+ *oflags += ' ' + filter_flags (flags, arch, path, type);
+ }
+
+ void
+ append_flags (const std::string& flags, flag_type type)
+ {
+ std::string arch;
+ std::string path;
+ append_flags (flags, arch, path, type);
+ }
+
+ const std::string
+ get_flags (flag_type type)
+ {
+ std::string* flags;
+ switch (type)
+ {
+ case ft_cppflags:
+ flags = &cppflags;
+ break;
+ case ft_cflags:
+ flags = &cflags;
+ break;
+ case ft_cxxflags:
+ flags = &cxxflags;
+ break;
+ case ft_ldflags:
+ flags = &ldflags;
+ break;
+ default:
+ throw rld::error ("Invalid flag type", "CC get flags");
+ }
+ return *flags;
+ }
+
+ const std::string
+ get_flags (flag_group group)
+ {
+ std::string* flags;
+ switch (group)
+ {
+ case fg_warning_flags:
+ flags = &warning_cflags;
+ break;
+ case fg_include_flags:
+ flags = &include_cflags;
+ break;
+ case fg_machine_flags:
+ flags = &machine_cflags;
+ break;
+ case fg_spec_flags:
+ flags = &spec_cflags;
+ break;
+ default:
+ throw rld::error ("Invalid flag group", "CC get flags");
+ }
+ return *flags;
+ }
+
+ void
+ append_flags (flag_type type, rld::process::arg_container& args)
+ {
+ const std::string* flags = 0;
+ switch (type)
+ {
+ case ft_cppflags:
+ flags = &cppflags;
+ break;
+ case ft_cflags:
+ flags = &cflags;
+ break;
+ case ft_cxxflags:
+ flags = &cxxflags;
+ break;
+ case ft_ldflags:
+ flags = &ldflags;
+ break;
+ default:
+ throw rld::error ("Invalid flag type", "CC append flags");
+ }
+ if (!flags->empty ())
+ rld::process::args_append (args, *flags);
+ }
+
+ void
+ make_cc_command (rld::process::arg_container& args)
+ {
+ /*
+ * Use the absolute path to CC if provided.
+ */
+ if (!cc.empty ())
+ args.push_back (cc);
+ else
+ {
+ std::string cmd = cc_name;
+ if (!exec_prefix.empty ())
+ cmd = exec_prefix + "-rtems" + rld::rtems_version () + '-' + cmd;
+ args.push_back (cmd);
+ }
+ }
+
static bool
match_and_trim (const char* prefix, std::string& line, std::string& result)
{
@@ -290,8 +448,8 @@ namespace rld
rld::process::arg_container args;
make_cc_command (args);
- add_cppflags (args);
- add_cflags (args);
+ append_flags (ft_cppflags, args);
+ append_flags (ft_cflags, args);
args.push_back ("-print-search-dirs");
rld::process::tempfile out;
@@ -339,8 +497,8 @@ namespace rld
rld::process::arg_container args;
make_cc_command (args);
- add_cflags (args);
- add_ldflags (args);
+ append_flags (ft_cppflags, args);
+ append_flags (ft_cflags, args);
args.push_back ("-print-file-name=" + name);
rld::process::tempfile out;
@@ -370,7 +528,7 @@ namespace rld
get_standard_libpaths (rld::path::paths& libpaths)
{
search_dirs ();
- rld::split (libraries_path, libpaths, RLD_PATHSTR_SEPARATOR);
+ rld::split (libpaths, libraries_path, RLD_PATHSTR_SEPARATOR);
}
void
@@ -380,7 +538,7 @@ namespace rld
{
strings libnames;
- rld::split (std_lib_c, libnames, RLD_PATHSTR_SEPARATOR);
+ rld::split (libnames, std_lib_c, RLD_PATHSTR_SEPARATOR);
if (cplusplus)
rld::path::path_split (std_lib_cplusplus, libnames);
diff --git a/rld-cc.h b/rld-cc.h
index f5365c4..a16bd3e 100644
--- a/rld-cc.h
+++ b/rld-cc.h
@@ -35,7 +35,7 @@ namespace rld
namespace cc
{
/*
- * Defintion of flags to be filtered.
+ * The type of flags.
*/
enum flag_type
{
@@ -45,48 +45,16 @@ namespace rld
ft_ldflags = 1 << 3
};
- extern std::string cc; //< The CC executable as absolute path.
- extern std::string cc_name; //< The CC name, ie gcc, clang.
- extern std::string exec_prefix; //< The CC executable prefix.
-
- extern std::string cppflags; //< The CPP flags.
- extern std::string cflags; //< The CC flags.
- extern std::string cxxflags; //< The CXX flags.
- extern std::string ldflags; //< The LD flags.
-
- extern std::string warning_cflags; //< The warning flags in cflags.
- extern std::string include_cflags; //< The include flags in cflags.
- extern std::string machine_cflags; //< The machine flags in cflags.
- extern std::string spec_cflags; //< The spec flags in cflags.
-
- extern std::string install_path; //< The CC reported install path.
- extern std::string programs_path; //< The CC reported programs path.
- extern std::string libraries_path; //< The CC reported libraries path.
-
- /**
- * Make a CC command from the set arguments.
- */
- void make_cc_command (rld::process::arg_container& args);
-
- /**
- * If the cppflags has been set append to the arguments.
- */
- void add_cppflags (rld::process::arg_container& args);
-
- /**
- * If the cflags has been set append to the arguments.
- */
- void add_cflags (rld::process::arg_container& args);
-
- /**
- * If the cxxflags has been set append to the arguments.
- */
- void add_cxxflags (rld::process::arg_container& args);
-
- /**
- * If the ldflags has been set append to the arguments.
+ /*
+ * Flags groups.
*/
- void add_ldflags (rld::process::arg_container& args);
+ enum flag_group
+ {
+ fg_warning_flags,
+ fg_include_flags,
+ fg_machine_flags,
+ fg_spec_flags
+ };
/**
* Strip the flags of -O and -g options.
@@ -138,6 +106,78 @@ namespace rld
flag_type type);
/**
+ * Set CC. The exec-prefix is ignored if this is set.
+ */
+ void set_cc (const std::string& cc);
+
+ /**
+ * Get the CC.
+ */
+ const std::string get_cc ();
+
+ /**
+ * Is the CC set ?
+ */
+ bool is_cc_set ();
+
+ /**
+ * Set the exec-prefix. If CC is set the exec-prefix is ignored.
+ */
+ void set_exec_prefix (const std::string& exec_prefix);
+
+ /**
+ * Get the exec-prefix.
+ */
+ const std::string get_exec_prefix ();
+
+ /**
+ * Is exec-prefix set ?
+ */
+ bool is_exec_prefix_set ();
+
+ /**
+ * Set the flags with a specific arch and include path.
+ */
+ void set_flags (const std::string& flags,
+ const std::string& arch,
+ const std::string& path,
+ flag_type type);
+
+ /**
+ * Set the flags.
+ */
+ void set_flags (const std::string& flags, flag_type type);
+
+ /**
+ * Append the flags with a specific arch and include path.
+ */
+ void append_flags (const std::string& flags,
+ const std::string& arch,
+ const std::string& path,
+ flag_type type);
+
+ /**
+ * Append the flags.
+ */
+ void append_flags (const std::string& flags, flag_type type);
+
+ /**
+ * Get the flags.
+ */
+ const std::string get_flags (flag_type type);
+ const std::string get_flags (flag_group group);
+
+ /**
+ * Append the flags if set.
+ */
+ void append_flags (flag_type type, rld::process::arg_container& args);
+
+ /**
+ * Make a CC command from the set arguments.
+ */
+ void make_cc_command (rld::process::arg_container& args);
+
+ /**
* Get the standard libraries paths from the compiler.
*/
void get_standard_libpaths (rld::path::paths& libpaths);
diff --git a/rld-process.cpp b/rld-process.cpp
index bb2f8a4..2174cce 100644
--- a/rld-process.cpp
+++ b/rld-process.cpp
@@ -88,6 +88,10 @@ namespace rld
std::string name = temp;
+ name = rld::find_replace (name,
+ RLD_PATH_SEPARATOR_STR RLD_PATH_SEPARATOR_STR,
+ RLD_PATH_SEPARATOR_STR);
+
tempfiles.push_back (name);
return name;
@@ -334,6 +338,19 @@ namespace rld
temporaries.clean_up ();
}
+ void
+ args_append (arg_container& args, const std::string& str)
+ {
+ rld::strings ss;
+ rld::split (ss, str);
+ for (rld::strings::iterator ssi = ss.begin ();
+ ssi != ss.end ();
+ ++ssi)
+ {
+ args.push_back (*ssi);
+ }
+ }
+
status
execute (const std::string& pname,
const std::string& command,
diff --git a/rld-process.h b/rld-process.h
index c50bb08..30033a7 100644
--- a/rld-process.h
+++ b/rld-process.h
@@ -180,6 +180,11 @@ namespace rld
typedef std::vector < std::string > arg_container;
/**
+ * Split a string and append to the arguments.
+ */
+ void args_append (arg_container& args, const std::string& str);
+
+ /**
* Execute result.
*/
struct status
diff --git a/rld-rtems.cpp b/rld-rtems.cpp
index b332aa4..c96bd62 100644
--- a/rld-rtems.cpp
+++ b/rld-rtems.cpp
@@ -48,11 +48,15 @@ namespace rld
}
const std::string
- rtems_bsp (const std::string& ab)
+ rtems_arch_prefix (const std::string& ab)
{
- const std::string a = arch (ab);
- const std::string b = bsp (ab);
- return a + "-rtems" + version + '-' + b;
+ return arch (ab) + "-rtems" + version;
+ }
+
+ const std::string
+ rtems_arch_bsp (const std::string& ab)
+ {
+ return rtems_arch_prefix (ab) + '-' + bsp (ab);
}
void
@@ -65,7 +69,7 @@ namespace rld
if (path.empty ())
throw rld::error ("Not set; see -r", "RTEMS path");
- bsp = rtems_bsp (arch_bsp);
+ bsp = rtems_arch_bsp (arch_bsp);
parts.push_back ("lib");
parts.push_back ("pkgconfig");
@@ -86,61 +90,70 @@ namespace rld
pkgconfig::package pkg (rtems_pkgconfig);
+ /*
+ * Check the pc file matches what we ask for.
+ */
+ std::string name;
+ if (!pkg.get ("name", name))
+ throw rld::error ("RTEMS BSP no name in pkgconfig file", arch_bsp);
+
+ if (name != bsp)
+ throw rld::error ("RTEMS BSP does not match the name in pkgconfig file", arch_bsp);
+
std::string flags;
if (pkg.get ("CPPFLAGS", flags))
{
- rld::cc::cppflags = rld::cc::filter_flags (flags,
- arch_bsp,
- path,
- rld::cc::ft_cppflags);
+ rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_cppflags);
if (rld::verbose () >= RLD_VERBOSE_INFO)
std::cout << " rtems: " << arch_bsp
- << ": CPPFLAGS=" << rld::cc::cppflags << std::endl;
+ << ": CPPFLAGS="
+ << rld::cc::get_flags (rld::cc::ft_cppflags)
+ << std::endl;
}
if (pkg.get ("CFLAGS", flags))
{
- rld::cc::cflags = rld::cc::filter_flags (flags,
- arch_bsp,
- path,
- rld::cc::ft_cflags);
+ rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_cflags);
if (rld::verbose () >= RLD_VERBOSE_INFO)
{
std::cout << " rtems: " << arch_bsp
- << ": CFLAGS=" << rld::cc::cflags << std::endl;
+ << ": CFLAGS=" << rld::cc::get_flags (rld::cc::ft_cflags)
+ << std::endl;
std::cout << " rtems: " << arch_bsp
- << ": WARNINGS=" << rld::cc::warning_cflags << std::endl;
+ << ": WARNINGS=" << rld::cc::get_flags (rld::cc::fg_warning_flags)
+ << std::endl;
std::cout << " rtems: " << arch_bsp
- << ": INCLUDES=" << rld::cc::include_cflags << std::endl;
+ << ": INCLUDES=" << rld::cc::get_flags (rld::cc::fg_include_flags)
+ << std::endl;
std::cout << " rtems: " << arch_bsp
- << ": MACHINES=" << rld::cc::machine_cflags << std::endl;
+ << ": MACHINES=" << rld::cc::get_flags (rld::cc::fg_machine_flags)
+ << std::endl;
std::cout << " rtems: " << arch_bsp
- << ": SPECS=" << rld::cc::spec_cflags << std::endl;
+ << ": SPECS=" << rld::cc::get_flags (rld::cc::fg_spec_flags)
+ << std::endl;
}
}
if (pkg.get ("CXXFLAGS", flags))
{
- rld::cc::cxxflags = rld::cc::filter_flags (flags,
- arch_bsp,
- path,
- rld::cc::ft_cxxflags);
+ rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_cxxflags);
if (rld::verbose () >= RLD_VERBOSE_INFO)
std::cout << " rtems: " << arch_bsp
- << ": CXXFLAGS=" << rld::cc::cxxflags << std::endl;
+ << ": CXXFLAGS=" << rld::cc::get_flags (rld::cc::ft_cxxflags)
+ << std::endl;
}
if (pkg.get ("LDFLAGS", flags))
{
- rld::cc::ldflags = rld::cc::filter_flags (flags,
- arch_bsp,
- path,
- rld::cc::ft_ldflags);
+ rld::cc::append_flags (flags, arch (arch_bsp), path, rld::cc::ft_ldflags);
if (rld::verbose () >= RLD_VERBOSE_INFO)
std::cout << " rtems: " << arch_bsp
- << ": LDFLAGS=" << rld::cc::ldflags << std::endl;
+ << ": LDFLAGS=" << rld::cc::get_flags (rld::cc::ft_ldflags)
+ << std::endl;
}
+
+ rld::cc::set_exec_prefix (arch (arch_bsp));
}
}
}
diff --git a/rtems-ld.cpp b/rtems-ld.cpp
index 189e699..cf28937 100644
--- a/rtems-ld.cpp
+++ b/rtems-ld.cpp
@@ -190,10 +190,8 @@ main (int argc, char* argv[])
std::string output = "a.out";
std::string outra;
std::string base_name;
- std::string cc_name;
std::string output_type = "rap";
bool standard_libs = true;
- bool exec_prefix_set = false;
bool map = false;
bool warnings = false;
bool one_file = false;
@@ -268,18 +266,19 @@ main (int argc, char* argv[])
break;
case 'C':
- if (exec_prefix_set == true)
+ if (rld::cc::is_exec_prefix_set ())
std::cerr << "warning: exec-prefix ignored when CC provided" << std::endl;
- rld::cc::cc = optarg;
+ rld::cc::set_cc (optarg);
break;
case 'E':
- exec_prefix_set = true;
- rld::cc::exec_prefix = optarg;
+ if (rld::cc::is_cc_set ())
+ std::cerr << "warning: exec-prefix ignored when CC provided" << std::endl;
+ rld::cc::set_exec_prefix (optarg);
break;
case 'c':
- rld::cc::cflags = optarg;
+ rld::cc::set_flags (optarg, rld::cc::ft_cflags);
break;
case 'e':
@@ -397,8 +396,8 @@ main (int argc, char* argv[])
* types. This must be after we have added the object files because they
* are used when detecting.
*/
- if (rld::cc::cc.empty () && !exec_prefix_set)
- rld::cc::exec_prefix = rld::elf::machine_type ();
+ if (!rld::cc::is_cc_set () && !rld::cc::is_exec_prefix_set ())
+ rld::cc::set_exec_prefix (rld::elf::machine_type ());
/*
* If we have a base image add it.
diff --git a/rtems-ra.cpp b/rtems-ra.cpp
index 8d1830c..7b7a98b 100644
--- a/rtems-ra.cpp
+++ b/rtems-ra.cpp
@@ -167,7 +167,6 @@ main (int argc, char* argv[])
std::string output_path = "./";
std::string output = "a.ra";
bool standard_libs = true;
- bool exec_prefix_set = false;
bool convert = true;
rld::files::object_list dependents;
@@ -241,18 +240,19 @@ main (int argc, char* argv[])
break;
case 'C':
- if (exec_prefix_set == true)
+ if (rld::cc::is_exec_prefix_set ())
std::cerr << "warning: exec-prefix ignored when CC provided" << std::endl;
- rld::cc::cc = optarg;
+ rld::cc::set_cc (optarg);
break;
case 'E':
- exec_prefix_set = true;
- rld::cc::exec_prefix = optarg;
+ if (rld::cc::is_cc_set ())
+ std::cerr << "warning: exec-prefix ignored when CC provided" << std::endl;
+ rld::cc::set_exec_prefix (optarg);
break;
case 'c':
- rld::cc::cflags = optarg;
+ rld::cc::set_flags (optarg, rld::cc::ft_cflags);
break;
case 'S':
@@ -296,8 +296,8 @@ main (int argc, char* argv[])
* types. This must be after we have added the object files because they
* are used when detecting.
*/
- if (rld::cc::cc.empty () && !exec_prefix_set)
- rld::cc::exec_prefix = rld::elf::machine_type ();
+ if (!rld::cc::is_cc_set () && !rld::cc::is_exec_prefix_set ())
+ rld::cc::set_exec_prefix (rld::elf::machine_type ());
if (convert)
{
diff --git a/rtems-syms.cpp b/rtems-syms.cpp
index 24c7826..031f46a 100644
--- a/rtems-syms.cpp
+++ b/rtems-syms.cpp
@@ -138,7 +138,6 @@ main (int argc, char* argv[])
std::string base_name;
std::string cc_name;
bool standard_libs = false;
- bool exec_prefix_set = false;
#if HAVE_WARNINGS
bool warnings = false;
#endif
@@ -188,18 +187,19 @@ main (int argc, char* argv[])
break;
case 'C':
- if (exec_prefix_set == true)
+ if (rld::cc::is_exec_prefix_set ())
std::cerr << "warning: exec-prefix ignored when CC provided" << std::endl;
- rld::cc::cc = optarg;
+ rld::cc::set_cc (optarg);
break;
case 'E':
- exec_prefix_set = true;
- rld::cc::exec_prefix = optarg;
+ if (rld::cc::is_cc_set ())
+ std::cerr << "warning: exec-prefix ignored when CC provided" << std::endl;
+ rld::cc::set_exec_prefix (optarg);
break;
case 'c':
- rld::cc::cflags = optarg;
+ rld::cc::set_flags (optarg, rld::cc::ft_cflags);
break;
case '?':
@@ -246,8 +246,8 @@ main (int argc, char* argv[])
* types. This must be after we have added the object files because they
* are used when detecting.
*/
- if (rld::cc::cc.empty () && !exec_prefix_set)
- rld::cc::exec_prefix = rld::elf::machine_type ();
+ if (!rld::cc::is_cc_set () && !rld::cc::is_exec_prefix_set ())
+ rld::cc::set_exec_prefix (rld::elf::machine_type ());
/*
* Get the standard library paths
diff --git a/rtems-tld.cpp b/rtems-tld.cpp
index 05be0be..0861674 100644
--- a/rtems-tld.cpp
+++ b/rtems-tld.cpp
@@ -186,7 +186,7 @@ namespace rld
/**
* Generate the wrapper object file.
*/
- void generate ();
+ const std::string generate ();
/**
* Generate the trace functions.
@@ -227,14 +227,21 @@ namespace rld
void generate_wrapper ();
/**
+ * Compile the C file.
+ */
+ void compile_wrapper ();
+
+ /**
* Dump the linker.
*/
void dump (std::ostream& out) const;
private:
- rld::config::config config; /**< User configuration. */
- tracer tracer_; /**< The tracer */
+ rld::config::config config; /**< User configuration. */
+ tracer tracer_; /**< The tracer */
+ std::string wrapper_c; /**< Wrapper C source file. */
+ std::string wrapper_o; /**< Wrapper object file. */
};
/**
@@ -536,7 +543,7 @@ namespace rld
generator_ = generator (config, gen);
}
- void
+ const std::string
tracer::generate ()
{
rld::process::tempfile c (".c");
@@ -571,6 +578,8 @@ namespace rld
}
c.close ();
+
+ return c.name ();
}
void
@@ -706,7 +715,44 @@ namespace rld
void
linker::generate_wrapper ()
{
- tracer_.generate ();
+ wrapper_c = tracer_.generate ();
+ }
+
+ void
+ linker::compile_wrapper ()
+ {
+ rld::process::arg_container args;
+
+ rld::process::tempfile o (".o");
+
+ if (rld::verbose ())
+ std::cout << "wrapper O file: " << o.name () << std::endl;
+
+ rld::cc::make_cc_command (args);
+ rld::cc::append_flags (rld::cc::ft_cflags, args);
+
+ args.push_back ("-c");
+ args.push_back ("-o ");
+ args.push_back (o.name ());
+ args.push_back (wrapper_c);
+
+ rld::process::tempfile out;
+ rld::process::tempfile err;
+ rld::process::status status;
+
+ status = rld::process::execute (rld::cc::get_cc (),
+ args,
+ out.name (),
+ err.name ());
+
+ if ((status.type != rld::process::status::normal) ||
+ (status.code != 0))
+ {
+ err.output (rld::cc::get_cc (), std::cout);
+ throw rld::error ("Compiler error", "compiling wrapper");
+ }
+
+ wrapper_o = o.name ();
}
void
@@ -811,7 +857,6 @@ main (int argc, char* argv[])
std::string ld_cmd;
std::string configuration;
std::string trace = "tracer";
- bool exec_prefix_set = false;
bool arch_bsp_load = false;
while (true)
@@ -843,12 +888,11 @@ main (int argc, char* argv[])
break;
case 'E':
- exec_prefix_set = true;
- rld::cc::exec_prefix = optarg;
+ rld::cc::set_exec_prefix (optarg);
break;
case 'c':
- rld::cc::cflags = optarg;
+ rld::cc::append_flags (optarg, rld::cc::ft_cflags);
break;
case 'r':
@@ -909,6 +953,7 @@ main (int argc, char* argv[])
{
linker.load_config (configuration, trace);
linker.generate_wrapper ();
+ linker.compile_wrapper ();
if (rld::verbose ())
linker.dump (std::cout);
diff --git a/rtld-base.ini b/rtld-base.ini
index b574e0b..3293ea8 100644
--- a/rtld-base.ini
+++ b/rtld-base.ini
@@ -22,7 +22,7 @@ code = <<<CODE
static inline void rtld_pg_print_arg(int arg_num,
const char* arg_type,
int arg_size,
- void* arg
+ void* arg)
{
const char* p = arg;
int i;
diff --git a/test-trace-1.h b/test-trace-1.h
new file mode 100644
index 0000000..8d79b1c
--- /dev/null
+++ b/test-trace-1.h
@@ -0,0 +1,7 @@
+
+#if !defined (_TEST_TRACE_1_H_)
+#define _TEST_TRACE_1_H_
+
+typedef char* test_type_1;
+
+#endif
diff --git a/test-trace-2.h b/test-trace-2.h
new file mode 100644
index 0000000..4239baa
--- /dev/null
+++ b/test-trace-2.h
@@ -0,0 +1,7 @@
+
+#if !defined (_TEST_TRACE_2_H_)
+#define _TEST_TRACE_2_H_
+
+typedef double test_type_2;
+
+#endif