From: Mikko Rasa Date: Sat, 11 Oct 2014 06:35:21 +0000 (+0300) Subject: Add a list of symbols to keep in the binary to BuildInfo X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=8f8f10fe41bbb68866e8fb05f8cbab0b325dc7da;p=builder.git Add a list of symbols to keep in the binary to BuildInfo The linker normally does not pull unnecessary symbols from static libraries, which can cause problems if those symbols are meant to be referenced externally. --- diff --git a/source/binary.cpp b/source/binary.cpp index e5968c0..448292c 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -56,7 +56,10 @@ void Binary::find_dependencies() BuildInfo binfo; tgt->collect_build_info(binfo); if(tgt!=this) + { static_binfo.libpath.insert(static_binfo.libpath.end(), binfo.libpath.begin(), binfo.libpath.end()); + static_binfo.keep_symbols.insert(static_binfo.keep_symbols.end(), binfo.keep_symbols.begin(), binfo.keep_symbols.end()); + } list::iterator insert_pos = j; ++insert_pos; diff --git a/source/buildinfo.cpp b/source/buildinfo.cpp index 0e06a59..1d598ca 100644 --- a/source/buildinfo.cpp +++ b/source/buildinfo.cpp @@ -62,6 +62,7 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level) libmode = bi.libmode; for(LibModeMap::const_iterator i=bi.libmodes.begin(); i!=bi.libmodes.end(); ++i) libmodes[i->first] = i->second; + keep_symbols.insert(keep_symbols.end(), bi.keep_symbols.begin(), bi.keep_symbols.end()); for(StandardMap::const_iterator i=bi.standards.begin(); i!=bi.standards.end(); ++i) standards[i->first] = i->second; debug = bi.debug; @@ -83,6 +84,7 @@ BuildInfo::Loader::Loader(BuildInfo &bi): add("debug", &BuildInfo::debug); add("define", &Loader::define); add("incpath", &Loader::incpath); + add("keep_symbol", &Loader::keep_symbol); add("libpath", &Loader::libpath); add("library", &Loader::library); add("libmode", &BuildInfo::libmode); @@ -107,6 +109,11 @@ void BuildInfo::Loader::define(const string &d, const string &v) obj.defines[d] = v; } +void BuildInfo::Loader::keep_symbol(const string &s) +{ + obj.keep_symbols.push_back(s); +} + void BuildInfo::Loader::libmode_for_lib(const string &l, LibraryMode m) { obj.libmodes[l] = m; diff --git a/source/buildinfo.h b/source/buildinfo.h index 0af7374..1bba819 100644 --- a/source/buildinfo.h +++ b/source/buildinfo.h @@ -28,6 +28,7 @@ public: private: void incpath(const std::string &); void define(const std::string &, const std::string &); + void keep_symbol(const std::string &); void libmode_for_lib(const std::string &, LibraryMode); void libpath(const std::string &); void library(const std::string &); @@ -83,6 +84,7 @@ public: WordList libs; Tracked libmode; LibModeMap libmodes; + WordList keep_symbols; StandardMap standards; Tracked threads; Tracked debug; diff --git a/source/gnulinker.cpp b/source/gnulinker.cpp index 2ec4c04..75a1bac 100644 --- a/source/gnulinker.cpp +++ b/source/gnulinker.cpp @@ -223,6 +223,9 @@ Task *GnuLinker::Linker::run(const Target &target) const argv.push_back("-o"); argv.push_back(relative(bin.get_path(), work_dir).str()); + for(BuildInfo::WordList::const_iterator i=binfo.keep_symbols.begin(); i!=binfo.keep_symbols.end(); ++i) + argv.push_back("-u"+*i); + bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC); const Target::Dependencies &depends = target.get_dependencies();