Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 784173 - app-text/ghostscript-gpl fails to build with Clang/LLVM/LLD.
Summary: app-text/ghostscript-gpl fails to build with Clang/LLVM/LLD.
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal with 2 votes (vote)
Assignee: Codec Project
Keywords: NeedPatch
Depends on:
Blocks: systemwide-clang
  Show dependency tree
Reported: 2021-04-19 15:38 UTC by Alexander Julian Moch
Modified: 2021-12-10 09:45 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---

Output of `emerge --info` (,6.26 KB, text/plain)
2021-04-19 18:13 UTC, Alexander Julian Moch
`build.log` with Clang + LLD and LTO enabled (build.clang-lld-lto.log.xz,66.03 KB, application/x-xz)
2021-04-19 18:15 UTC, Alexander Julian Moch
`build.log` with Clang + BFD without LTO (build.clang-bfd-no_lto.log.xz,89.05 KB, application/x-xz)
2021-04-19 18:16 UTC, Alexander Julian Moch

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Julian Moch 2021-04-19 15:38:39 UTC
I'm using the entire LLVM toolchain v12.0.0 to build my packages. ghostscript-gpl fails with `ld.lld: error: undefined symbol: ...`. It works fine with GCC and Gold or BFD linker.

All undefined symbol errors are related to app-text/tesseract. Adding `--without-tesseract` to `src_configure()` fixes the problem and ghostscript-gpl builds without issue.

Here is one excerpt from the log file:

ld.lld: error: undefined symbol: std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()
>>> referenced by altorenderer.cpp
>>>               ./obj/tesseract_api_altorenderer.o:(tesseract::TessBaseAPI::GetAltoText(tesseract::ETEXT_DESC*, int))
>>> referenced by baseapi.cpp
>>>               ./obj/tesseract_api_baseapi.o:(tesseract::TessBaseAPI::GetOsdText(int))
>>> referenced by hocrrenderer.cpp
>>>               ./obj/tesseract_api_hocrrenderer.o:(tesseract::TessBaseAPI::GetHOCRText(tesseract::ETEXT_DESC*, int))
>>> referenced 9 more times

Reproducible: Always
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-04-19 17:48:36 UTC
The full build.log and emerge —-info output is always needed. Could you provide that please?

Also, how about Clang with the normal GNU ld? ldd often exposes other issues unrelated to the compiler
Comment 2 Alexander Julian Moch 2021-04-19 18:13:02 UTC
Created attachment 700881 [details]
Output of `emerge --info`
Comment 3 Alexander Julian Moch 2021-04-19 18:15:35 UTC
Created attachment 700884 [details]
`build.log` with Clang + LLD and LTO enabled
Comment 4 Alexander Julian Moch 2021-04-19 18:16:18 UTC
Created attachment 700887 [details]
`build.log` with Clang + BFD without LTO
Comment 5 Alexander Julian Moch 2021-04-19 18:23:18 UTC
Sorry, in previous bug reports no one asked for `build.log` and the output of `emerge --info`. Now I included them.

The build process also fails when using Clang and BFD. Whether or not I enable LTO makes no difference.

app-text/tesseract is not installed and installing tesseract also did not fix the issue.
Comment 6 Perfect Gentleman 2021-05-14 16:22:13 UTC
confirm bug.
Adding `--without-tesseract' to EXTRA_ECONF solves it.
Comment 7 Thomas Deutschmann gentoo-dev Security 2021-05-14 18:29:05 UTC
Note that app-text/ghostscript-gpl is bundling an own fork of tesseract since 9.53... so app-text/ghostscript-gpl does NOT use app-text/tesseract.

I personally do not care about Clang/LLVM/LLD at this point. Please report upstream and report back the link to their issue tracker. Also, patches are welcome.
Comment 8 Perfect Gentleman 2021-05-15 04:25:05 UTC
In Arch's PKGBUILD -
  # *** remove after final decision ***
  # new in 9.54.0: 

  # 1) inclusion of the tesseract/leptonica sources for OCR capabilities
  # at the moment we do not support linking with tesseract/leptonica shared libraries. 
  # As is normal with such included libraries, deleting those directories and (re)running
  # configure (on Unix like systems) will automatically build without the OCR functionality.
  # increases package size ghostpcl 2.7->4.9MB | ghostscript 18->23MB | ghostxps 2,7->4.9MB
  # - 
  # this doesn't seem to be worth to keep enabled until linking with shared libs is supported
  rm -r tesseract leptonica
Comment 9 Perfect Gentleman 2021-05-15 04:27:08 UTC
So, maybe just remove those directories as other internal copies ?
Comment 10 Paul Mulders 2021-11-23 18:15:04 UTC
do you have libcxx enabled? probably caused by it linking against libstdc++ instead of libc++. the invocation has "-lstdc++"
Comment 11 Alec Ari 2021-12-10 09:25:34 UTC
This is an actual bug. ghostscript-gpl hard-codes -lstdc++ and -stdlib=stdc++ in the Makefile, so having USE="libcxx" for sys-devel/clang doesn't actually do anything for this particular package. ghostscript-gpl should honor this but it doesn't.

I added a package.env conf file for it with the following:

CFLAGS="-O2 -stdlib=libc++ -fPIC -fstack-protector-strong -fstack-clash-protection -fomit-frame-pointer -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"

# ghostscript-gpl completely ignores CXXFLAGS
# -stdlib must actually be in CFLAGS
CXXFLAGS="-O2 -stdlib=libc++ -fPIC -fstack-protector-strong -fstack-clash-protection -fomit-frame-pointer -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"

LDFLAGS="-Wl,-O1 -Wl,--as-needed -lc++ -fuse-ld=lld -Wl,-z,now -Wl,-z,relro -Wl,--strip-debug"

And the package built. The only relevant part for the bug is:

-stdlib=libc++ in CFLAGS
-lc++ in LDFLAGS.

Rest are all hardening flags, don't worry about that.