// the GNU General Public License.
// Benjamin Kosnik <bkoz@redhat.com>
+// Blame subsequent hacks on Loren J. Rittle <ljrittle@acm.org>, Phil
+// Edwards <pme@gcc.gnu.org>, and a cast of dozens at libstdc++@gcc.gnu.org.
#include <string>
#include <ext/hash_map>
#include <fstream>
#include <iostream>
#include <cxxabi.h>
+#include <stdlib.h> // for system(3)
+#include <unistd.h> // for access(2)
struct symbol_info
{
enum category { none, function, object, error };
category type;
std::string name;
- std::string name_demangled;
- std::string version;
+ std::string demangled_name;
int size;
+ std::string version_name;
symbol_info() : type(none), size(0) { }
symbol_info(const symbol_info& other)
- : type(other.type), name(other.name), name_demangled(other.name_demangled),
- version(other.version), size(other.size) { }
+ : type(other.type), name(other.name), demangled_name(other.demangled_name),
+ size(other.size), version_name(other.version_name) { }
};
+namespace __gnu_cxx
+{
+ using namespace std;
+
+ template<>
+ struct hash<string>
+ {
+ size_t operator()(const string& s) const
+ {
+ const collate<char>& c = use_facet<collate<char> >(locale::classic());
+ return c.hash(s.c_str(), s.c_str() + s.size());
+ }
+ };
+}
+
+typedef std::deque<std::string> symbol_names;
+typedef __gnu_cxx::hash_map<std::string, symbol_info> symbol_infos;
+
bool
-operator==(const symbol_info& lhs, const symbol_info& rhs)
+check_compatible(const symbol_info& lhs, const symbol_info& rhs,
+ bool verbose = false)
{
+ using namespace std;
bool ret = true;
+ const char tab = '\t';
// Check to see if symbol_infos are compatible.
- ret &= lhs.type == rhs.type;
- ret &= lhs.name == rhs.name;
- ret &= lhs.size == rhs.size;
+ if (lhs.type != rhs.type)
+ {
+ ret = false;
+ if (verbose)
+ {
+ cout << tab << "incompatible types" << endl;
+ }
+ }
+
+ if (lhs.name != rhs.name)
+ {
+ ret = false;
+ if (verbose)
+ {
+ cout << tab << "incompatible names" << endl;
+ }
+ }
+
+ if (lhs.size != rhs.size)
+ {
+ ret = false;
+ if (verbose)
+ {
+ cout << tab << "incompatible sizes" << endl;
+ }
+ }
+
+ if (lhs.version_name != rhs.version_name)
+ {
+ ret = false;
+ if (verbose)
+ {
+ cout << tab << "incompatible versions" << endl;
+ }
+ }
- // Expect something more sophisticated eventually.
- ret &= lhs.version == rhs.version;
return ret;
}
-bool
-operator!=(const symbol_info& lhs, const symbol_info& rhs)
-{ return !(lhs == rhs); }
-
-template<typename _CharT, typename _Traits>
- std::basic_ostream<_CharT, _Traits>&
- operator<<(std::basic_ostream<_CharT, _Traits>& os, symbol_info& si)
- {
- using namespace std;
- os << si.type << endl;
- os << si.name << endl;
- os << si.name_demangled << endl;
- os << si.version << endl;
- os << si.size << endl;
- return os;
- }
-
const char*
demangle(const std::string& mangled)
{
input.erase(input.begin(), input.begin() + n + 1);
// Set version name.
- output.version = input;
+ output.version_name = input;
}
else
{
}
// Set the demangled name.
- output.name_demangled = demangle(output.name);
+ output.demangled_name = demangle(output.name);
}
-typedef std::deque<std::string> symbol_names;
-typedef __gnu_cxx::hash_map<const char*, symbol_info> symbol_infos;
-
void
-collect_symbol_data(const char* file, symbol_infos& symbols,
- symbol_names& names)
+create_symbol_data(const char* file, symbol_infos& symbols,
+ symbol_names& names)
{
// Parse list of symbols in file into vectors of symbol_info.
// For 3.2.0 on x86/linux, this usually is
{
symbol_info symbol;
line_to_symbol_info(line, symbol);
- symbols[symbol.name.c_str()] = symbol;
+ symbols[symbol.name] = symbol;
names.push_back(symbol.name);
line = empty;
}
}
}
+void
+report_symbol_info(const symbol_info& symbol, std::size_t n)
+{
+ using namespace std;
+ const char tab = '\t';
+ cout << tab << n << endl;
+ cout << tab << "symbol"<< endl;
+ cout << tab << symbol.name << endl;
+
+ // Add any other information to display here.
+ cout << tab << "demangled symbol"<< endl;
+ cout << tab << symbol.demangled_name << endl;
-int main(int argc, char** argv)
+ cout << endl;
+}
+
+
+int
+main(int argc, char** argv)
{
using namespace std;
- // Get arguments.
- if (argc != 2)
+ // Get arguments. (Heading towards getopt_long, I can feel it.)
+ string argv1;
+ if (argc < 4 || (string("--help") == (argv1 = argv[1])))
{
- cerr << "Usage: abi_check baseline_file" << endl;
+ cerr << "Usage: abi_check --check cur baseline\n"
+ " --help\n\n"
+ "Where CUR is a file containing the current results from\n"
+ "extract_symvers, and BASELINE is one from config/abi.\n"
+ << endl;
exit(1);
}
- const char* baseline_file = argv[1];
- const char* test_file = "current_symbols.txt";
- const char* test_lib = "../src/.libs/libstdc++.so";
-
- // Get list of symbols.
- // Assume external symbol list computed "as if" by
- /*
- readelf -s -W libstdc++.so | sed '/\.dynsym/,/^$/p;d' | egrep -v
- ' (LOCAL|UND) ' | awk '{ if ($4 == "FUNC" || $4 == "NOTYPE") printf
- "%s:%s\n", $4, $8; else if ($4 == "OBJECT") printf "%s:%s:%s\n", $4,
- $3, $8;}' | sort >& current_symbols.txt
- */
- const char quote = '"';
- const char bslash = '\\';
-
- // GNU binutils, somewhere after version 2.11.2, requires -W/--wide
- // to avoid default line truncation. -W is not supported and
- // truncation did not occur by default before that point.
- bool readelf_need_wide =
- (system("readelf --help | grep -- --wide >/dev/null") == 0);
-
- ostringstream cmd;
- cmd << "readelf -s " << (readelf_need_wide ? "-W " : "")
- << test_lib << " | sed '/" << bslash
- << ".dynsym/,/^$/p;d' | egrep -v ' (LOCAL|UND) ' | "
- << "awk '{ if ($4 == " << quote << "FUNC" << quote << "|| $4 == "
- << quote << "NOTYPE" << quote << ") printf " << quote << "%s:%s"
- << bslash << "n" << quote << ", $4, $8; else if ($4 == "
- << quote << "OBJECT" << quote << ") printf " << quote
- << "%s:%s:%s" << bslash << "n" << quote << ", $4, $3, $8;}' | "
- << "sort > " << test_file << " 2>&1";
- if (system(cmd.str().c_str()) != 0)
+
+
+ // Quick sanity/setup check for arguments.
+ const char* test_file = argv[2];
+ const char* baseline_file = argv[3];
+ if (access(test_file, R_OK) != 0)
{
- cerr << "Unable to generate the list of exported symbols." << endl;
- exit(2);
+ cerr << "Cannot read symbols file " << test_file
+ << ", did you forget to build first?" << endl;
+ exit(1);
+ }
+ if (access(baseline_file, R_OK) != 0)
+ {
+ cerr << "Cannot read baseline file " << baseline_file << endl;
+ exit(1);
}
- // Input both list of symbols into container.
+ // Input both lists of symbols into container.
symbol_infos baseline_symbols;
symbol_names baseline_names;
symbol_infos test_symbols;
symbol_names test_names;
- collect_symbol_data(baseline_file, baseline_symbols, baseline_names);
- collect_symbol_data(test_file, test_symbols, test_names);
+ create_symbol_data(baseline_file, baseline_symbols, baseline_names);
+ create_symbol_data(test_file, test_symbols, test_names);
- // Basic sanity check. (Was: error checking, what's that?)
+ // Sanity check results.
const symbol_names::size_type baseline_size = baseline_names.size();
const symbol_names::size_type test_size = test_names.size();
if (!baseline_size || !test_size)
// Sort out names.
// Assuming baseline_names, test_names are both unique w/ no duplicates.
//
- // The pairs of names in shared_names are needed to do lookups on
- // the hash tables of common symbols to do compares.
- //
// The names added to missing_names are baseline_names not found in
// test_names
// -> symbols that have been deleted.
//
- // The names left in test_names are names not in baseline_names
+ // The names added to added_names are test_names are names not in
+ // baseline_names
// -> symbols that have been added.
- typedef pair<string, string> string_pair;
- vector<string_pair> shared_names;
+ symbol_names shared_names;
symbol_names missing_names;
+ symbol_names added_names = test_names;
for (size_t i = 0; i < baseline_size; ++i)
{
- symbol_names::iterator end = test_names.end();
- symbol_names::iterator it = find(test_names.begin(), end,
- baseline_names[i]);
+ string what(baseline_names[i]);
+ symbol_names::iterator end = added_names.end();
+ symbol_names::iterator it = find(added_names.begin(), end, what);
if (it != end)
{
// Found.
- shared_names.push_back(string_pair(baseline_names[i], *it));
- test_names.erase(it);
+ shared_names.push_back(what);
+ added_names.erase(it);
}
else
- missing_names.push_back(baseline_names[i]);
+ missing_names.push_back(what);
}
- // Check common names for detailed compatibility.
- const vector<string_pair>::size_type shared_size = shared_names.size();
+ // Check shared names for compatibility.
typedef pair<symbol_info, symbol_info> symbol_pair;
vector<symbol_pair> incompatible;
- for (size_t i = 0; i < shared_size; ++i)
+ for (size_t i = 0; i < shared_names.size(); ++i)
{
- symbol_info binfo = baseline_symbols[shared_names[i].first.c_str()];
- symbol_info tinfo = test_symbols[shared_names[i].second.c_str()];
- if (binfo != tinfo)
- incompatible.push_back(symbol_pair(binfo, tinfo));
+ symbol_info base = baseline_symbols[shared_names[i]];
+ symbol_info test = test_symbols[shared_names[i]];
+ if (!check_compatible(base, test))
+ incompatible.push_back(symbol_pair(base, test));
}
- // Output data.
- cout << test_names.size() << " added symbols " << endl;
- for (size_t j = 0; j < test_names.size() ; ++j)
- cout << '\t' << test_names[j] << endl;
+ // Check added names for compatibility.
+ for (size_t i = 0; i < added_names.size(); ++i)
+ {
+ vector<string> compatible_versions;
+ compatible_versions.push_back("GLIBCPP_3.2.1");
+
+ symbol_info test = test_symbols[added_names[i]];
+ vector<string>::iterator end = compatible_versions.end();
+
+ // Check version names for compatibility...
+ vector<string>::iterator it1 = find(compatible_versions.begin(), end,
+ test.version_name);
+
+ // Check for weak label.
+ vector<string>::iterator it2 = find(compatible_versions.begin(), end,
+ test.name);
+
+ if (it1 == end && it2 == end)
+ incompatible.push_back(symbol_pair(test, test));
+ }
+
+ // Report results.
+ cout << added_names.size() << " added symbols " << endl;
+ for (size_t j = 0; j < added_names.size() ; ++j)
+ report_symbol_info(test_symbols[added_names[j]], j + 1);
cout << missing_names.size() << " missing symbols " << endl;
for (size_t j = 0; j < missing_names.size() ; ++j)
- cout << '\t' << missing_names[j] << endl;
+ report_symbol_info(baseline_symbols[missing_names[j]], j + 1);
cout << incompatible.size() << " incompatible symbols " << endl;
for (size_t j = 0; j < incompatible.size() ; ++j)
{
- cout << "baseline symbol_info:" << endl;
- cout << incompatible[j].first << endl;
- cout << "test symbol_info:" << endl;
- cout << incompatible[j].second << endl;
+ // First, report name.
+ const symbol_info& base = incompatible[j].first;
+ const symbol_info& test = incompatible[j].second;
+ report_symbol_info(test, j + 1);
+
+ // Second, report reason or reasons incompatible.
+ check_compatible(base, test, true);
}
return 0;