Bug 234221

Summary: print/tex-luatex: Fails to link after switch to internal libpoppler
Product: Ports & Packages Reporter: John Hein <jcfyecrayz>
Component: Individual Port(s)Assignee: Hiroki Sato <hrs>
Status: Closed FIXED    
Severity: Affects Only Me CC: diizzy, dim, frankenbox, hrs, jcfyecrayz, ohartmann, rhurlin, rkoberman, tcberner
Priority: --- Keywords: regression
Version: LatestFlags: tcberner: maintainer-feedback-
Hardware: Any   
OS: Any   
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=239608
Attachments:
Description Flags
[log] manual link invocation (with -v)
none
[build log] log of build failure with gcc
none
[patch] fix for mixed clang/gcc mismatch triggering link failure
jcfyecrayz: maintainer-approval? (hrs)
Patch to fix mixing libc++/libstdc++ and -fcommon issues
none
Patch to fix mixing libc++/libstdc++ in print/tex-xetex
none
Patch to fix mixing libc++/libstdc++ in print/tex-xetex, also pet portlint none

Description John Hein 2018-12-20 16:32:47 UTC
After r487226, building print/tex-luatex is failing with a linker error on 11-stable/amd64.

 .
 .
 .
c++ -Wimplicit -Wreturn-type -Wno-unknown-pragmas -Wno-write-strings -O2 -pipe -fstack-protector -fno-strict-aliasing -fstack-protector -o luatex luatexdir/luatex-luatex.o mplibdir/luatex-lmplib.o -fstack-protector -Wl,--export-dynamic libluatex.a libff.a libluamisc.a libluasocket.a -L/usr/local/lib -ltexlua52 libmplib.a -lmpfr -lgmp -lcairo -lpthread -lpixman-1 -lzzip -lpng16 -lz /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a lib/lib.a -lkpathsea libmputil.a libunilib.a libmd5.a -lm
/usr/bin/ld: Dwarf Error: found dwarf version '4', this reader only handles version 2 information.
/usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a(Form.o): In function `_ZNSt8_Rb_treeIiiSt9_IdentityIiESt4lessIiESaIiEE16_M_insert_uniqueIRKiEESt4pairISt17_Rb_tree_iteratorIiEbEOT_':
Form.cc:(.text._ZNSt8_Rb_treeIiiSt9_IdentityIiESt4lessIiESaIiEE16_M_insert_uniqueIRKiEESt4pairISt17_Rb_tree_iteratorIiEbEOT_[_ZNSt8_Rb_treeIiiSt9_IdentityIiESt4lessIiESaIiEE16_M_insert_uniqueIRKiEESt4pairISt17_Rb_tree_iteratorIiEbEOT_]+0x90): undefined reference to `std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'
Form.cc:(.text._ZNSt8_Rb_treeIiiSt9_IdentityIiESt4lessIiESaIiEE16_M_insert_uniqueIRKiEESt4pairISt17_Rb_tree_iteratorIiEbEOT_[_ZNSt8_Rb_treeIiiSt9_IdentityIiESt4lessIiESaIiEE16_M_insert_uniqueIRKiEESt4pairISt17_Rb_tree_iteratorIiEbEOT_]+0xcf): undefined reference to `std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
/usr/bin/ld: Dwarf Error: found dwarf version '4', this reader only handles version 2 information.
/usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a(Gfx.o): In function `Gfx::opXObject(Object*, int)':
Gfx.cc:(.text+0x12a99): undefined reference to `std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'
/usr/bin/ld: Dwarf Error: found dwarf version '4', this reader only handles version 2 information.
Comment 1 John Hein 2018-12-20 16:33:26 UTC
Adding committer.
Comment 2 John Hein 2018-12-20 16:47:58 UTC
Created attachment 200309 [details]
[log] manual link invocation (with -v)

Attached is a copy of the output of the c++ link command that is failing (with -v).
Comment 3 Tobias C. Berner freebsd_committer freebsd_triage 2018-12-20 18:38:08 UTC
Moin moin


I cannot reproduce this in my 11 jail.


mfg Tobias
Comment 4 Rainer Hurling freebsd_committer freebsd_triage 2018-12-20 18:48:03 UTC
Same here on HEADamd64 r342007:

/bin/sh ./libtool  --tag=CXX    --mode=link c++ -Wimplicit -Wreturn-type -Wno-unknown-pragmas -Wno-write-strings  -O2 -pipe -fstack-protector -fno-strict-aliasing -export-dynamic -fstack-protector -o luatex luatexdir/luatex-luatex.o  mplibdir/luatex-lmplib.o libluatex.a libff.a libluamisc.a libluasocket.a -L/usr/local/lib -ltexlua52 libmplib.a -L/usr/local/lib -lmpfr -L/usr/local/lib -lgmp -L/usr/local/lib -lcairo -lpthread  -L/usr/local/lib -lpixman-1 -L/usr/local/lib -fstack-protector -lzzip -lz -L/usr/local/lib -lpng16 -lz -lz  /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a lib/lib.a -L/usr/local/lib -lkpathsea libmputil.a libunilib.a libmd5.a   -lm
libtool: link: c++ -Wimplicit -Wreturn-type -Wno-unknown-pragmas -Wno-write-strings -O2 -pipe -fstack-protector -fno-strict-aliasing -fstack-protector -o luatex luatexdir/luatex-luatex.o mplibdir/luatex-lmplib.o -fstack-protector -Wl,--export-dynamic  libluatex.a libff.a libluamisc.a libluasocket.a -L/usr/local/lib -ltexlua52 libmplib.a -lmpfr -lgmp -lcairo -lpthread -lpixman-1 -lzzip -lpng16 -lz /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a lib/lib.a -lkpathsea libmputil.a libunilib.a libmd5.a -lm
ld: error: undefined symbol: std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)
>>> referenced by stl_tree.h:1771 (/usr/local/lib/gcc8/include/c++/bits/stl_tree.h:1771)
>>>               Form.o:(std::pair<std::_Rb_tree_iterator<int>, bool> std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_insert_unique<int const&>(int const&)) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::_Rb_tree_decrement(std::_Rb_tree_node_base*)
>>> referenced by stl_tree.h:302 (/usr/local/lib/gcc8/include/c++/bits/stl_tree.h:302)
>>>               Form.o:(std::pair<std::_Rb_tree_iterator<int>, bool> std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_insert_unique<int const&>(int const&)) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)
>>> referenced by stl_tree.h:2491 (/usr/local/lib/gcc8/include/c++/bits/stl_tree.h:2491)
>>>               Gfx.o:(Gfx::opXObject(Object*, int)) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::__throw_length_error(char const*)
>>> referenced by stl_vector.h:1643 (/usr/local/lib/gcc8/include/c++/bits/stl_vector.h:1643)
>>>               CachedFile.o:(std::vector<CachedFile::Chunk, std::allocator<CachedFile::Chunk> >::_M_default_append(unsigned long)) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::__throw_out_of_range_fmt(char const*, ...)
>>> referenced by stl_vector.h:960 (/usr/local/lib/gcc8/include/c++/bits/stl_vector.h:960)
>>>               StructElement.o:(StructElement::findAttribute(Attribute::Type, bool, Attribute::Owner) const) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::__throw_out_of_range_fmt(char const*, ...)
>>> referenced by stl_vector.h:960 (/usr/local/lib/gcc8/include/c++/bits/stl_vector.h:960)
>>>               StructElement.o:(StructElement::findAttribute(Attribute::Type, bool, Attribute::Owner) const) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::__throw_out_of_range_fmt(char const*, ...)
>>> referenced by stl_vector.h:960 (/usr/local/lib/gcc8/include/c++/bits/stl_vector.h:960)
>>>               StructElement.o:(StructElement::parseAttributes(Dict*, bool)) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::__throw_out_of_range_fmt(char const*, ...)
>>> referenced by stl_vector.h:960 (/usr/local/lib/gcc8/include/c++/bits/stl_vector.h:960)
>>>               StructElement.o:(StructElement::parse(Dict*)) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::__throw_out_of_range_fmt(char const*, ...)
>>> referenced by stl_vector.h:960 (/usr/local/lib/gcc8/include/c++/bits/stl_vector.h:960)
>>>               StructElement.o:(StructElement::appendSubTreeText(GooString*, bool) const) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)
>>> referenced by stl_tree.h:1771 (/usr/local/lib/gcc8/include/c++/bits/stl_tree.h:1771)
>>>               StructElement.o:(std::pair<std::_Rb_tree_iterator<int>, bool> std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_insert_unique<int>(int&&)) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::_Rb_tree_decrement(std::_Rb_tree_node_base*)
>>> referenced by stl_tree.h:302 (/usr/local/lib/gcc8/include/c++/bits/stl_tree.h:302)
>>>               StructElement.o:(std::pair<std::_Rb_tree_iterator<int>, bool> std::_Rb_tree<int, int, std::_Identity<int>, std::less<int>, std::allocator<int> >::_M_insert_unique<int>(int&&)) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::__throw_length_error(char const*)
>>> referenced by stl_vector.h:1643 (/usr/local/lib/gcc8/include/c++/bits/stl_vector.h:1643)
>>>               StructTreeRoot.o:(std::vector<std::vector<StructTreeRoot::Parent, std::allocator<StructTreeRoot::Parent> >, std::allocator<std::vector<StructTreeRoot::Parent, std::allocator<StructTreeRoot::Parent> > > >::_M_default_append(unsigned long)) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a

ld: error: undefined symbol: std::__throw_length_error(char const*)
>>> referenced by stl_vector.h:1643 (/usr/local/lib/gcc8/include/c++/bits/stl_vector.h:1643)
>>>               StructTreeRoot.o:(std::vector<StructTreeRoot::Parent, std::allocator<StructTreeRoot::Parent> >::_M_default_append(unsigned long)) in archive /usr/ports/print/tex-luatex/work/texlive-20150521-source/libs/poppler/libpoppler.a
c++: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make[3]: stopped in /usr/ports/print/tex-luatex/work/texlive-20150521-source/texk/web2c
*** Error code 1

Stop.
make[2]: stopped in /usr/ports/print/tex-luatex/work/texlive-20150521-source/texk/web2c
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/print/tex-luatex/work/texlive-20150521-source/texk/web2c
*** Error code 1

Stop.
make: stopped in /usr/ports/print/tex-luatex
Comment 5 Tobias C. Berner freebsd_committer freebsd_triage 2018-12-20 19:55:50 UTC
Moin moin


I reproduce this on neither

* Jail OSVERSION: 1102000 (11.2-RELEASE-p7 i386)
* Jail OSVERSION: 1300005 (13-CURRENT r342109)

Please, update your systems/packages and try again.


mfg Tobias
Comment 6 Rainer Hurling freebsd_committer freebsd_triage 2018-12-20 20:53:32 UTC
(In reply to Tobias C. Berner from comment #5)

Hi Tobias,

Thanks for your work and suggestion.

I just rebuilt the whole dependencies tree for print/tex-luatex with recent ports tree and unfortunately it fails like before:

portmaster pixman-0.34.0_1 texlive-texmf-20150523_4 tex-formats-20150521_2 mpfr-4.0.1_2 poppler-0.72.0 png-1.6.35 cairo-1.15.12,2 zziplib-0.13.69_1 tex-web2c-20150521_3 tex-libtexluajit-2.0.3 tex-libtexlua-5.2.4 tex-kpathsea-6.2.1_2 tex-luatex-0.80.0_9
Comment 7 Tobias C. Berner freebsd_committer freebsd_triage 2018-12-21 13:19:25 UTC
Hi Rainer

I now also tried it with a CURRENT jail at r42007. Still builds fine. So my guess still is, that your package are way out of sync with each other and the tree underlying it.

Please try to update your ports tree and *all* the installed packages to the latest version -- not selectively only the dependencies of tex-luatex. 

Then try again.



mfg Tobias
Comment 8 Rainer Hurling freebsd_committer freebsd_triage 2018-12-22 08:19:22 UTC
(In reply to Tobias C. Berner from comment #7)

Hi Tobias,

Thanks for testing also in a CURRENT jail.

Unfortunately, the boxes, where this happens on my side, are all in production use. The ports are all built via portmaster, with several non default options enabled, because they are needed by GIS software. Additionally, the rebuild does not work for several ports, because they have problems ATM (e.g math/libpgmath).

I haven't tried to do this via an own Poudriere repository until now. If I would change, this would take a long time (~ 2700 ports to build).
Comment 9 Tobias C. Berner freebsd_committer freebsd_triage 2018-12-22 18:18:11 UTC
Hi there

As I could not reproduce this with an up-to-date ports tree and the FreeBSD versions mentioned in the PR I have to assume that it is related to pkgs/ports being out of sync. 

Please reopen this issue if you updated everything and it still fails :)


mfg Tobias
Comment 10 John Hein 2018-12-24 15:47:04 UTC
It compiles with poudriere testport.

But still not outside that environment.  It's happening on another host (11/stable i386) as well.  Trying to determine the jail and out-of-jail differences.
Comment 11 John Hein 2018-12-24 15:47:41 UTC
(In reply to John Hein from comment #10)
print/tex-xetex has the same problem.
Comment 12 John Hein 2018-12-27 06:17:29 UTC
Re-opening.  The problem is reproduced (in poudriere jail or out) if lang/gcc (and thus also lang/gcc8) is installed.  The 'configure' stage looks for gcc and uses it (instead of /usr/bin/cc) if it finds it.
Comment 13 John Hein 2018-12-27 06:18:05 UTC
Workaround: make CC=/usr/bin/cc CXX=/usr/bin/c++
Comment 14 Tobias C. Berner freebsd_committer freebsd_triage 2018-12-30 00:55:41 UTC
(In reply to John Hein from comment #12)
I have lang/gcc8 installed, and it does not fail. 

* Do you have CC&Co overriden in your make.conf/environemnt? 
* Please upload a full build log.
Comment 15 John Hein 2018-12-31 23:58:01 UTC
Created attachment 200667 [details]
[build log] log of build failure with gcc

(In reply to Tobias C. Berner from comment #14)
Build log is attached.  There is no CC defined in make.conf

Compare to your build log (feel free to attach yours as well).  Pay particular attention to the configure phase where it tries to detect gcc.  You should see:

checking for gcc... gcc

If gcc is not detected, you will see:

checking for gcc... no

And then the build will use /usr/bin/cc (and /usr/bin/c++) and not fail.

If you are trying to use poudriere to reproduce, you may want to use 'bulk -i lang/gcc' or 'testport -i lang/gcc' and then run 'make -C /usr/ports/print/tex-luatex' manually inside the jail.  Or manually add 'BUILD_DEPENDS=gcc:lang/gcc' to tex-luatex/Makefile before 'testport print/tex-luatex'.  I don't know of another way currently to force poudriere to have a set of non-dependent packages (e.g., lang/gcc) installed before it tries to build a particular port (e.g., print/tex-luatex).
Comment 16 MikeH 2019-02-14 18:28:47 UTC
I can confirm I have the same problem as John on a fresh install with updated ports tree (FreeBSD 12.0-RELEASE-p3)
John's workaround in Comment 13 worked.
Comment 17 rkoberman 2019-05-15 03:00:53 UTC
*** Bug 237902 has been marked as a duplicate of this bug. ***
Comment 18 rkoberman 2019-05-15 03:41:01 UTC
I am seeing this with 12.0-STABLE r343501 GENERIC_4BSD  amd64.
Using make "CC=/usr/bin/cc CXX=/usr/bin/c++" fixes the issue.
Comment 19 John Hein 2019-05-24 14:11:42 UTC
Created attachment 204593 [details]
[patch] fix for mixed clang/gcc mismatch triggering link failure

Attached is a patch to tell configure which CC/CXX to use (rather than let it try to detect the compiler to use and have it pick something that results in a mix of clang & gcc built products that trigger the link failure).

Flagging maintainer-approval request, although it's been a long time since I've seen much ports interaction from the maintainer (none for this PR since it was opened).
Comment 20 John Hein 2019-05-24 14:28:32 UTC
p.s. It was probably not necessary to bump PORTREVISION on this port after the recent poppler update since tex-luatex was modified to use the internal bundled poppler code.
Comment 21 O. Hartmann 2019-08-03 18:05:10 UTC
*** Bug 239608 has been marked as a duplicate of this bug. ***
Comment 22 O. Hartmann 2019-08-03 18:11:03 UTC
*** Bug 236882 has been marked as a duplicate of this bug. ***
Comment 23 John Hein 2019-08-28 02:24:03 UTC
Maintainer timeout?

If a committer takes this simple patch to ensure consistent suite of compiler tools at each build stage, please also apply to print/tex-xetex.

Enough people have hit this problem, I think.  I hit this again on a machine after building due to the recent PORTREVISION bump.

QA:
 Both ports have been tested with poudriere with this change.
 No new portlint warnings.
Comment 24 Tobias C. Berner freebsd_committer freebsd_triage 2019-08-28 04:59:18 UTC
Maintainer Timout
Comment 25 Hiroki Sato freebsd_committer freebsd_triage 2019-08-28 07:41:58 UTC
(In reply to Tobias C. Berner from comment #24)

I am sorry for the delay getting back to this PR.  This issue was due to the mismatch between libc++ and libstdc++, not mismatch of clang and gcc themselves.  Putting CC and CXX into CONFIGURE_ARGS hides it but does not solve the root cause.
Comment 26 Dimitry Andric freebsd_committer freebsd_triage 2020-10-17 14:18:54 UTC
Created attachment 218841 [details]
Patch to fix mixing libc++/libstdc++ and -fcommon issues

Here's a patch that fixes both issues:
* Add CC and CXX to CONFIGURE_ARGS to force using system specified cc/c++
* Add patches to remove duplicated symbols
Comment 27 Rainer Hurling freebsd_committer freebsd_triage 2020-10-17 15:01:24 UTC
(In reply to Dimitry Andric from comment #26)

Many thanks for the patch! It works fine for me on Poudriere and even outside, build by Portmaster.


For me too, the problem also exists for print/tex-xetex, as mentioned by John Hein in comment #11.
Comment 28 Dimitry Andric freebsd_committer freebsd_triage 2020-10-18 10:16:39 UTC
Created attachment 218857 [details]
Patch to fix mixing libc++/libstdc++ in print/tex-xetex

Sure, here is a similar patch for print/tex-xetex. With that port, only adding CC and CXX to the configure arguments is enough.
Comment 29 Rainer Hurling freebsd_committer freebsd_triage 2020-10-18 10:57:55 UTC
(In reply to Dimitry Andric from comment #28)

Thanks for the patch for print/tex-xetex. This one also builds, installs and works fine for me within and outside of Poudriere.


However, with DEVELOPER=yes set in /etc/make.conf, I get some errors and a warning during stage-qa:

====> Running Q/A tests (stage-qa)
Error: '/usr/bin/env python' is an invalid shebang you need USES=shebangfix for 'share/texmf-dist/doc/xelatex/xepersian/undk-0.6.py'
Error: '/usr/bin/env python' is an invalid shebang you need USES=shebangfix for 'share/texmf-dist/doc/xelatex/xepersian/unldk-0.2.py'
Error: '/usr/bin/env python' is an invalid shebang you need USES=shebangfix for 'share/texmf-dist/doc/xelatex/xepersian/dkun-0.3.py'
Error: '/usr/bin/env python' is an invalid shebang you need USES=shebangfix for 'share/texmf-dist/doc/xelatex/xepersian/dkun-0.4.py'
Error: '/usr/bin/perl' is an invalid shebang you need USES=shebangfix for 'share/texmf-dist/source/xelatex/arabxetex/makemaps.pl'
Error: '/usr/bin/perl' is an invalid shebang you need USES=shebangfix for 'share/texmf-dist/scripts/xetex/perl/xdv2pdf_mergemarks'
Error: /usr/local/bin/xetex is linked to /usr/local/lib/libfontconfig.so.1 from x11-fonts/fontconfig but it is not declared as a dependency
Warning: you need LIB_DEPENDS+=libfontconfig.so:x11-fonts/fontconfig


Probably this is for another PR?
Comment 30 Dimitry Andric freebsd_committer freebsd_triage 2020-10-18 11:09:49 UTC
(In reply to Rainer Hurling from comment #29)
Yes, those are all not strictly necessary now for getting the port building successfully. It looks like they're are all most "lint-like" things, making the port more nicely behaved. 

That said, adding the LIB_DEPENDS+=libfontconfig.so:x11-fonts/fontconfig to the xetex port should not be too much hassle.
Comment 31 Rainer Hurling freebsd_committer freebsd_triage 2020-10-18 11:57:26 UTC
Created attachment 218859 [details]
Patch to fix mixing libc++/libstdc++ in print/tex-xetex, also pet portlint

Hi Dimitry,

Don't know, if I understand you right in comment #30. But here is a possible patch for print/tex-xetex, which includes the missing dependency, some SHEBANG fixes and some sorting in LIB_DEPENDS.

What I am unsure about is, if USES=python:env is really needed here?
Comment 32 John Hein 2020-10-18 16:47:12 UTC
(In reply to Rainer Hurling from comment #29)
Regarding the shebang issues, see the 3 1/2 year pr and patch, bug 218924.
Comment 33 John Hein 2020-10-18 16:53:54 UTC
(In reply to Rainer Hurling from comment #31)
And I think your patch doesn't work because the files are not available at "patch" time (which is some of what that old bug discusses).  The final patch in that bug uses post-install to fix the shebangs.
Comment 34 Rainer Hurling freebsd_committer freebsd_triage 2020-10-18 17:02:39 UTC
(In reply to John Hein from comment #33)

Thanks for the hint to bug #218924. Very much the same I tried to do ;)

And yes, you are right. What I forgot to add to my patch is something like:

post-install:
	cd ${STAGEDIR}${PREFIX} && \
		${FIND} ${SHEBANG_FILES} -type f \
		-exec ${SED} -i '' ${_SHEBANG_REINPLACE_ARGS} {} +


I personally would be also fine without this SHEBANG fix. But I think, it is a good opportunity to solve this problem.
Comment 35 John Hein 2021-05-04 20:22:21 UTC
Please commit the fix for the dwarf linker problem.  I keep hitting this on unpatched port trees.

We are well past maintainer timeout, and we have reports of this being helpful, both for print/tex-luatex and print/tex-xetex.  So we need a champion to commit this.
Comment 36 commit-hook freebsd_committer freebsd_triage 2021-05-06 21:30:45 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=b8aceeb60194bcd8f8caf6789193c46271d3480e

commit b8aceeb60194bcd8f8caf6789193c46271d3480e
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-05-06 21:29:24 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-05-06 21:29:24 +0000

    print/tex-luatex: Avoid mixing libc++ and libstdc++, and don't use -fcommon

    This port was not respecting the CC and CXX variables, thus it could
    pick up gcc and g++ instead, and that would cause mixups between
    libstdc++ (which is preferred by gcc) and libc++ (which is in base),
    ultimately leading to link errors.

    Also, the port uses a very old version of tex so it suffers from a few
    -fno-common issues, mostly variables that have been declared without an
    'extern' specifier. Add a few patches to fix these.

    Appproved by:   maintainer timeout
    PR:             234221
    MFH:            2021Q2

 print/tex-luatex/Makefile                                     |  8 +++-----
 .../tex-luatex/files/patch-luatexdir_font_luatexfont.h (new)  | 11 +++++++++++
 print/tex-luatex/files/patch-luatexdir_image_writeimg.h (new) | 11 +++++++++++
 print/tex-luatex/files/patch-luatexdir_image_writeimg.w (new) | 11 +++++++++++
 print/tex-luatex/files/patch-luatexdir_pdf_pdftables.h (new)  | 11 +++++++++++
 print/tex-luatex/files/patch-luatexdir_tex_textoken.w (new)   | 11 +++++++++++
 6 files changed, 58 insertions(+), 5 deletions(-)
Comment 37 commit-hook freebsd_committer freebsd_triage 2021-05-06 21:33:47 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=c42622b6afc5b4fcf32552dbdc1a2d07433ae24d

commit c42622b6afc5b4fcf32552dbdc1a2d07433ae24d
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-05-06 21:32:00 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-05-06 21:32:24 +0000

    print/tex-xetex: Avoid mixing libc++ and libstdc++

    This port was not respecting the CC and CXX variables, thus it could
    pick up gcc and g++ instead, and that would cause mixups between
    libstdc++ (which is preferred by gcc) and libc++ (which is in base),
    ultimately leading to link errors.

    Appproved by:   maintainer timeout
    PR:             234221
    MFH:            2021Q2

 print/tex-xetex/Makefile | 2 ++
 1 file changed, 2 insertions(+)
Comment 38 Daniel Engberg freebsd_committer freebsd_triage 2021-09-15 22:41:16 UTC
Can anyone confirm if it works as intended now?
Comment 39 rkoberman 2021-09-15 23:11:18 UTC
(In reply to Daniel Engberg from comment #38)
I can confirm that tex-luatex nw builds correctly without any hack to force the proper library. 13-STABLE-n246941-20f96f21556

I have not tried tex-xetex as I don't use it.
Comment 40 Daniel Engberg freebsd_committer freebsd_triage 2021-09-15 23:21:19 UTC
(In reply to rkoberman from comment #39)

Thanks, I'll close this bug report. If anyone still are having issues please open a new one.

Fixed by commit b8aceeb60194bcd8f8caf6789193c46271d3480e