#include <set>
#include <string>
#include <utility>
+#include "demangle.h"
#include "object.h"
#include "dwarf_reader.h"
this->needs_value_in_got_ = false;
}
+// Return the demangled version of the symbol's name, but only
+// if the --demangle flag was set.
+
+static std::string
+demangle(const char* name)
+{
+ // cplus_demangle allocates memory for the result it returns,
+ // and returns NULL if the name is already demangled.
+ char* demangled_name = cplus_demangle(name, DMGL_ANSI | DMGL_PARAMS);
+ if (demangled_name == NULL)
+ return name;
+
+ std::string retval(demangled_name);
+ free(demangled_name);
+ return retval;
+}
+
+std::string
+Symbol::demangled_name() const
+{
+ if (parameters->demangle())
+ return demangle(name());
+ else
+ return name();
+}
+
// Initialize the fields in the base class Symbol for SYM in OBJECT.
template<int size, bool big_endian>
&& shndx != elfcpp::SHN_ABS)
{
gold_error(_("%s: unsupported symbol section 0x%x"),
- sym->name(), shndx);
+ sym->demangled_name().c_str(), shndx);
shndx = elfcpp::SHN_UNDEF;
}
&& in_shndx != elfcpp::SHN_ABS)
{
gold_error(_("%s: unsupported symbol section 0x%x"),
- sym->name(), in_shndx);
+ sym->demangled_name().c_str(), in_shndx);
shndx = in_shndx;
}
else
Dynobj* dynobj = static_cast<Dynobj*>(sym->object());
if (!dynobj->has_unknown_needed_entries())
gold_error(_("%s: undefined reference to '%s'"),
- sym->object()->name().c_str(), sym->name());
+ sym->object()->name().c_str(),
+ sym->demangled_name().c_str());
}
}
{
gold_warning(_("while linking %s: symbol %s defined in multiple "
"places (possible ODR violation):"),
- output_file_name, symbol_name);
+ output_file_name, demangle(symbol_name).c_str());
for (std::set<std::string>::const_iterator it2 = line_nums.begin();
it2 != line_nums.end();
++it2)