Skip to content

Commit

Permalink
remove adding CMAKE_CXX_IMPLICIT_LINK_LIBRARIES to PRIVATE_LIBS
Browse files Browse the repository at this point in the history
as on alpine linux this add gcc_s which is a shared library

on alpine:
Libs.private: -lstdc++ -lm -lssp_nonshared -lgcc_s -lgcc -lc -lgcc_s -lgcc
  • Loading branch information
a16bitsysop authored and markos committed Oct 12, 2021
1 parent bc57891 commit e5e2057
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 9 deletions.
8 changes: 0 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,6 @@ configure_file(${CMAKE_MODULE_PATH}/config.h.in ${PROJECT_BINARY_DIR}/config.h)
configure_file(src/hs_version.h.in ${PROJECT_BINARY_DIR}/hs_version.h)


# expand out library names for pkgconfig static link info
foreach (LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
# this is fragile, but protects us from toolchain specific files
if (NOT EXISTS ${LIB})
set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
endif()
endforeach()

configure_file(libhs.pc.in libhs.pc @ONLY) # only replace @ quoted vars
install(FILES ${CMAKE_BINARY_DIR}/libhs.pc
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
Expand Down
1 change: 0 additions & 1 deletion libhs.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ Name: libhs
Description: Intel(R) Hyperscan Library
Version: @HS_VERSION@
Libs: -L${libdir} -lhs
Libs.private: @PRIVATE_LIBS@
Cflags: -I${includedir}/hs

8 comments on commit e5e2057

@bradlarsen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a16bitsysop @markos: do you remember the specifics behind this change?

Is there some kind of test scenario I could try to reproduce the issue?

I ask because it appears that vectorscan as distributed in Homebrew and also in Ubuntu is broken for static linking, I believe because of the change in this commit to libhs.pc.in. Is this issue just that gcc_s shows up in @PRIVATE_LIBS@, when that is a shared library?

@a16bitsysop
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was similar, that a shared gcc lib shows up in libhs.pc for static linking. Or static linking links to a shared lib as well.

Probably to do with this: rspamd/rspamd#3915

@a16bitsysop
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its actually in the commit description

@bradlarsen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like the specific issue that instigated the patch is that Libs.private included -lgcc_s? If this is the case, probably a better thing to do is filter out -lgcc_s from PRIVATE_LIBS, rather than delete outright Libs.private from the pkg-config file (which seems to break static linking in the Homebrew and Ubuntu packages).

@a16bitsysop
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the problem was -lgcc_s, I tried rspamd static compile on alpine and it also fails at linking with /usr/lib/gcc/x86_64-alpine-linux-musl/12.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libhs.a: error adding symbols: file format not recognized

Is that the error you are getting?

@bradlarsen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me get back to you on that! 🙇

@bradlarsen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The particular troubles I see when trying to build Nosey Parker against vectorscan using pkg-config are linker errors that come from missing libstdc++ or libc++, e.g.:

  = note: "cc" "-arch" "arm64" "/var/folders/m0/x93w89fj7_qd3pb0vvktz9k00000gn/T/rustc8iYF2V/symbols.o" "/Users/blarsen/projects/npbuildtest/target/debug/deps/noseyparker-4c9a3059421a8720.101ggvipihlrh639.rcgu.o" "/Users/blarsen/projects/npbuildtest/target/debug/deps/noseyparker-4c9a3059421a8720.10fztk4pvmmq0840.rcgu.o" ... "/Users/blarsen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcore-e48a983765cd78b4.rlib" "/Users/blarsen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-635ac2664b5ede2a.rlib" "-liconv" "-lSystem" "-lc" "-lm" "-L" "/Users/blarsen/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/blarsen/projects/npbuildtest/target/debug/deps/noseyparker-4c9a3059421a8720" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: Undefined symbols for architecture arm64:
            "std::logic_error::what() const", referenced from:
                vtable for boost::wrapexcept<boost::not_a_dag> in libhyperscan_sys-f7edc87059abe0db.rlib(ng_util.cpp.o)
                vtable for boost::not_a_dag in libhyperscan_sys-f7edc87059abe0db.rlib(ng_util.cpp.o)
                vtable for boost::bad_graph in libhyperscan_sys-f7edc87059abe0db.rlib(ng_util.cpp.o)
            "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const", referenced from:
                ue2::ReferenceVisitor::pre(ue2::ComponentCondReference const&) in libhyperscan_sys-f7edc87059abe0db.rlib(check_refs.cpp.o)
                ue2::ComponentCondReference::addAlternation() in libhyperscan_sys-f7edc87059abe0db.rlib(ComponentCondReference.cpp.o)
            "std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::str() const", referenced from:
                ue2::LocatedParseError::locate(unsigned long) in libhyperscan_sys-f7edc87059abe0db.rlib(parse_error.cpp.o)
                ue2::ReportManager::registerExtReport(unsigned int, ue2::external_report_info const&) in libhyperscan_sys-f7edc87059abe0db.rlib(report_manager.cpp.o)
                ue2::UnsupportedVisitor::pre(ue2::ComponentEUS const&) in libhyperscan_sys-f7edc87059abe0db.rlib(unsupported.cpp.o)
                ue2::UnsupportedVisitor::pre(ue2::ComponentWordBoundary const&) in libhyperscan_sys-f7edc87059abe0db.rlib(unsupported.cpp.o)
                ue2::propagateExtendedParams(ue2::NGHolder&, ue2::ExpressionInfo&, ue2::ReportManager&) in libhyperscan_sys-f7edc87059abe0db.rlib(ng_extparam.cpp.o)
                ue2::parse(char const*, ue2::ParseMode&) in libhyperscan_sys-f7edc87059abe0db.rlib(Parser.cpp.o)
                ue2::ReferenceVisitor::invalid_index(char const*, unsigned int) in libhyperscan_sys-f7edc87059abe0db.rlib(check_refs.cpp.o)
                ...

No errors like this arise when linking Nosey Parker against Hyperscan instead, still using pkg-config (Hyperscan still has the Libs.private: @PRIVATE_LIBS@ pkgconfig bit).

There's a bunch of layers to the build failures I'm seeing above against Vectorscan. When I get a chance I might dig into it to isolate the problem, open an issue and a PR. But it does seem that static linking against Vectorscan at present doesn't work as intended.

@a16bitsysop
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if libgcc_s.a is for mingwin, on alpine its in the mingwin package

Please sign in to comment.