-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix building with -z defs #994
Conversation
Building with LDFLAGS='-Wl,-z,defs' shows among others: $ /usr/bin/c++ -fPIC -O0 -g -Wl,-z,defs -shared -o builddep_cmd_plugin.so CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o -Wl,-rpath,/tmp/d/libdnf5-cli:/tmp/d/libdnf5: /usr/lib64/librpmbuild.so ../../libdnf5-cli/libdnf5-cli.so.1 ../../libdnf5/libdnf5.so.1 -ldl -lstdc++ -lfmt -lsmartcols [...] /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:125:(.text+0xba8): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:127:(.text+0xbba): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:126:(.text+0xbe1): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:129:(.text+0xbf6): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:130:(.text+0xc0f): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:132:(.text+0xc21): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:131:(.text+0xc48): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:134:(.text+0xc5d): undefined reference to `rpmdsFree' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::add_from_srpm_file(std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, char const*)': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:141:(.text+0xc9f): undefined reference to `Fopen' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:142:(.text+0xcb6): undefined reference to `Ferror' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:143:(.text+0xd1d): undefined reference to `Fstrerror' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:145:(.text+0xd4d): undefined reference to `Fclose' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:152:(.text+0xd64): undefined reference to `rpmtsCreate' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:153:(.text+0xd79): undefined reference to `rpmtsSetVSFlags' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:154:(.text+0xd95): undefined reference to `rpmReadPackageFile' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:155:(.text+0xda4): undefined reference to `rpmtsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:156:(.text+0xdb0): undefined reference to `Fclose' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:160:(.text+0xddd): undefined reference to `rpmdsNewPool' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:160:(.text+0xde5): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:162:(.text+0xdf7): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:161:(.text+0xe46): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:167:(.text+0xe5b): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:168:(.text+0xe76): undefined reference to `rpmdsNewPool' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:168:(.text+0xe7e): undefined reference to `rpmdsInit' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:170:(.text+0xe90): undefined reference to `rpmdsDNEVR' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:169:(.text+0xeb7): undefined reference to `rpmdsNext' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:172:(.text+0xecc): undefined reference to `rpmdsFree' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:177:(.text+0xf2c): undefined reference to `headerFree' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::run()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:223:(.text+0x1966): undefined reference to `rpmPushMacro' /usr/bin/ld: /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:231:(.text+0x1aae): undefined reference to `rpmPopMacro' All these functions are explicitly called from builddep.cpp, hence builddep.cpp must include header files defining the functions and must link to libraries providing them. rpmbuild header and library were utilizied. But librpm and librpmio were completely missing. This patch adds them. Related to <rpm-software-management#267>.
dnf5-plugins are plugins which use symbols from dnf5 program. On ELF platforms, these symbols remain unresolved at compilation time. GNU linker knows that and thus does not enforce -z defs semantics by default. Yet some overzeleous distributions or devolopers use -z defs linker flags to quality-check for an underlinking and then the build fails like this: $ /usr/bin/c++ -fPIC -O0 -g -Wl,-z,defs -shared -o builddep_cmd_plugin.so CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o -Wl,-rpath,/tmp/d/libdnf5-cli:/tmp/d/libdnf5: /usr/lib64/librpmbuild.so -lrpm -lrpmio -lpopt ../../libdnf5-cli/libdnf5-cli.so.1 ../../libdnf5/libdnf5.so.1 -ldl -lstdc++ -lfmt -lsmartcols /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::set_argument_parser()::{lambda(char const*)rpm-software-management#1}::operator()(char const*) const': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:62:(.text+0x104): undefined reference to `dnf5::match_specs(dnf5::Context&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, bool, bool, bool, char const*)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::set_argument_parser()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:68:(.text+0x5e7): undefined reference to `dnf5::create_allow_downgrade_options(dnf5::Command&)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::BuildDepCommand::run()': /home/test/dnf5/dnf5-plugins/builddep_plugin/builddep.cpp:258:(.text+0x1d1d): undefined reference to `dnf5::Context::get_goal(bool)' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o: in function `dnf5::Command::~Command()': /home/test/dnf5/dnf5/include/dnf5/context.hpp:164:(.text._ZN4dnf57CommandD2Ev[_ZN4dnf57CommandD5Ev]+0xf): undefined reference to `vtable for dnf5::Command' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep.cpp.o:(.data.rel.ro._ZTIN4dnf515BuildDepCommandE[_ZTIN4dnf515BuildDepCommandE]+0x10): undefined reference to `typeinfo for dnf5::Command' /usr/bin/ld: CMakeFiles/builddep_cmd_plugin.dir/builddep_cmd_plugin.cpp.o: in function `dnf5::Command::Command(libdnf5::cli::session::Session&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/test/dnf5/dnf5/include/dnf5/context.hpp:166:(.text._ZN4dnf57CommandCI2N7libdnf53cli7session7CommandEERNS3_7SessionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN4dnf57CommandCI5N7libdnf53cli7session7CommandEERNS3_7SessionERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x2e): undefined reference to `vtable for dnf5::Command' collect2: error: ld returned 1 exit status This patch works around it by appending -z undefs when linking dnf5 program plugins. Implementation detail: target_link_options() as well as other CMake functions place their values before system-wide flags inherited from an envirnoment. Therefore this patch simply modifies CMAKE_MODULE_LINKER_FLAGS CMake variable. Resolves: rpm-software-management#267
I changed the order to included headers to be in alphabetical order as recommended by the clang linter. |
The inclusion of the missing headers and linking to rpm libraries in the builddep plugin is a bug fix. |
e13d3c1
This patchset fixes issue #267. First commit fixes a transitive reliance on directly used librpm fucntions in builddep_plugin dnf plugin. The second commit disables -z defs for program plugins. As a result, it is possible to build DNF5 with "-z defs" among system-wide linker flags.