]> git.tdb.fi Git - builder.git/commitdiff
Add a list of symbols to keep in the binary to BuildInfo
authorMikko Rasa <tdb@tdb.fi>
Sat, 11 Oct 2014 06:35:21 +0000 (09:35 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 11 Oct 2014 06:35:21 +0000 (09:35 +0300)
The linker normally does not pull unnecessary symbols from static
libraries, which can cause problems if those symbols are meant to be
referenced externally.

source/binary.cpp
source/buildinfo.cpp
source/buildinfo.h
source/gnulinker.cpp

index e5968c0de411d8c548b0365e69099adfc276aa8a..448292cf051a5899412ba89329888053312276cc 100644 (file)
@@ -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<Target *>::iterator insert_pos = j;
                ++insert_pos;
index 0e06a5908ff984d1e67def75d64e643106e47ace..1d598caa7a42a56178d25cee7b9f35800f903098 100644 (file)
@@ -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;
index 0af7374575e1a5979111ea12c999d99e8a288b45..1bba8195bc536014270ba8eff7664d31e63e7069 100644 (file)
@@ -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<LibraryMode> libmode;
        LibModeMap libmodes;
+       WordList keep_symbols;
        StandardMap standards;
        Tracked<bool> threads;
        Tracked<bool> debug;
index 2ec4c048d613372205f0a48421c2dcc24d19eff4..75a1bac280609086da046f86e3c71e1cc115d5e5 100644 (file)
@@ -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();