Bug 265516 - lang/perl5*: work around duplicate symbol errors with dtrace enabled
Summary: lang/perl5*: work around duplicate symbol errors with dtrace enabled
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Dimitry Andric
URL:
Keywords:
Depends on:
Blocks: 265425
  Show dependency treegraph
 
Reported: 2022-07-30 13:15 UTC by Dimitry Andric
Modified: 2023-04-04 14:37 UTC (History)
3 users (show)

See Also:
bugzilla: maintainer-feedback? (mat)


Attachments
lang/perl5*: work around duplicate symbol errors with dtrace enabled (5.73 KB, patch)
2022-07-30 13:15 UTC, Dimitry Andric
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric freebsd_committer freebsd_triage 2022-07-30 13:15:09 UTC
During an exp-run for llvm 15 (see bug 265425), it turned out that lang/perl5.32, lang/perl5.34, lang/perl5.36 and lang/perl5-devel fail to build with clang and lld 15:

cc -pthread -Wl,-E  -fstack-protector-strong -L/usr/local/lib -o miniperl  mpdtrace/opmini.o mpdtrace/perlmini.o mpdtrace/gv.o mpdtrace/toke.o mpdtrace/perly.o mpdtrace/pad.o mpdtrace/regcomp.o mpdtrace/dump.o mpdtrace/util.o mpdtrace/mg.o mpdtrace/reentr.o mpdtrace/mro_core.o mpdtrace/keywords.o mpdtrace/hv.o mpdtrace/av.o mpdtrace/run.o mpdtrace/pp_hot.o mpdtrace/sv.o mpdtrace/pp.o mpdtrace/scope.o mpdtrace/pp_ctl.o mpdtrace/pp_sys.o mpdtrace/doop.o mpdtrace/doio.o mpdtrace/regexec.o mpdtrace/utf8.o mpdtrace/taint.o mpdtrace/deb.o mpdtrace/universal.o mpdtrace/globals.o mpdtrace/perlio.o mpdtrace/perlapi.o mpdtrace/numeric.o mpdtrace/mathoms.o mpdtrace/locale.o mpdtrace/pp_pack.o mpdtrace/pp_sort.o mpdtrace/caretx.o mpdtrace/dquote.o mpdtrace/time64.o mpdtrace/miniperlmain.o dtrace_mini.o -lpthread -lm -lcrypt -lutil
ld: error: duplicate symbol: __dtraceenabled_perl___op__entry
>>> defined in mpdtrace/perlmini.o
>>> defined in mpdtrace/dump.o

ld: error: duplicate symbol: __dtraceenabled_perl___op__entry
>>> defined in mpdtrace/perlmini.o
>>> defined in mpdtrace/run.o

ld: error: duplicate symbol: __dtraceenabled_perl___sub__entry
>>> defined in mpdtrace/pp_hot.o
>>> defined in mpdtrace/pp_ctl.o

ld: error: duplicate symbol: __dtraceenabled_perl___sub__entry
>>> defined in mpdtrace/pp_hot.o
>>> defined in mpdtrace/regexec.o

ld: error: duplicate symbol: __dtraceenabled_perl___sub__entry
>>> defined in mpdtrace/pp_hot.o
>>> defined in mpdtrace/pp_sort.o
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

This error pops up in more bug reports, for instance bug 258872 and bug 260947.

It seems that dtrace does something to the object files produced during the build, if the DTRACE option is enabled (which it is by default). Whatever it does, it causes these multiply defined symbols, which only appear to occur in certain (as of yet) undetermined circumstances.

I would like to get the ports going again by working around these link errors, using the --allow-multiple-definition linker flag, which is supported by both GN ld and lld.
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2022-07-30 13:15:49 UTC
Created attachment 235556 [details]
lang/perl5*: work around duplicate symbol errors with dtrace enabled
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2022-07-30 13:17:05 UTC
Adding some people who might know more about what dtrace is doing to those object files.
Comment 3 Dimitry Andric freebsd_committer freebsd_triage 2022-07-30 13:22:15 UTC
See also bug 258872.
Comment 4 Mark Johnston freebsd_committer freebsd_triage 2022-07-30 14:31:20 UTC
What's the easiest way for me to reproduce this locally?  I don't see an llvm15 package available.
Comment 5 Dimitry Andric freebsd_committer freebsd_triage 2022-07-30 15:48:37 UTC
Probably the easiest is to rebuild world with WITH_LLVM_BINUTILS=yes, as in bug 258872? Otherwise, you could get the llvm-15-update branch:

git clone -b llvm-15-update https://github.com/DimitryAndric/freebsd-src.git
Comment 6 Dimitry Andric freebsd_committer freebsd_triage 2022-08-07 10:01:20 UTC
I got a similar sort of failure while building java/openjdk11, which apparently also has dtrace features enabled:

=== Output from failing command(s) repeated here ===
* For target hotspot_variant-server_libjvm_objs_BUILD_LIBJVM_link:
c++: warning: argument unused during compilation: '-static-libstdc++' [-Wunused-command-line-argument]
c++: warning: argument unused during compilation: '-static-libgcc' [-Wunused-command-line-argument]
ld: error: duplicate symbol: __dtrace_hotspot___monitor__notifyAll
>>> defined in hotspot/variant-server/libjvm/objs/objectMonitor.o
>>> defined in hotspot/variant-server/libjvm/objs/synchronizer.o

ld: error: duplicate symbol: __dtrace_hotspot___monitor__notify
>>> defined in hotspot/variant-server/libjvm/objs/objectMonitor.o
>>> defined in hotspot/variant-server/libjvm/objs/synchronizer.o
c++: error: linker command failed with exit code 1 (use -v to see invocation)

E.g. again dtrace is doing something with these symbols that makes lld think they're duplicated. It looks like the object files are OK *before* dtrace touches them, though.
Comment 7 Dimitry Andric freebsd_committer freebsd_triage 2022-09-19 17:12:04 UTC
So until a dtrace person can figure out what the root cause of the problem is, I'm going to commit the workarounds, to unblock bug 265425.
Comment 8 commit-hook freebsd_committer freebsd_triage 2022-09-19 18:58:57 UTC
A commit in branch main references this bug:

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

commit 4ae8ff941b29191641e22a06e39ea27aa38c7848
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2022-09-19 18:54:14 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2022-09-19 18:54:14 +0000

    lang/perl5*: work around duplicate symbol errors with lld 15 and dtrace enabled

    Building any of the lang/perl5* ports with clang and lld 15, and the
    DTRACE option enabled (which is default on) results in link errors
    similar to:

        cc -pthread -Wl,-E  -fstack-protector-strong -L/usr/local/lib -o miniperl  mpdtrace/opmini.o mpdtrace/perlmini.o mpdtrace/universalmini.o mpdtrace/gv.o mpdtrace/toke.o mpdtrace/perly.o mpdtrace/pad.o mpdtrace/regcomp.o mpdtrace/dump.o mpdtrace/util.o mpdtrace/mg.o mpdtrace/reentr.o mpdtrace/mro_core.o mpdtrace/keywords.o mpdtrace/builtin.o mpdtrace/hv.o mpdtrace/av.o mpdtrace/run.o mpdtrace/pp_hot.o mpdtrace/sv.o mpdtrace/pp.o mpdtrace/scope.o mpdtrace/pp_ctl.o mpdtrace/pp_sys.o mpdtrace/doop.o mpdtrace/doio.o mpdtrace/regexec.o mpdtrace/utf8.o mpdtrace/taint.o mpdtrace/deb.o mpdtrace/globals.o mpdtrace/perlio.o mpdtrace/numeric.o mpdtrace/mathoms.o mpdtrace/locale.o mpdtrace/pp_pack.o mpdtrace/pp_sort.o mpdtrace/caretx.o mpdtrace/dquote.o mpdtrace/time64.o mpdtrace/miniperlmain.o dtrace_mini.o -lpthread -lm -lcrypt -lutil
        ld: error: duplicate symbol: __dtraceenabled_perl___sub__entry
        >>> defined in mpdtrace/pp_hot.o
        >>> defined in mpdtrace/pp_sort.o

        ld: error: duplicate symbol: __dtraceenabled_perl___sub__entry
        >>> defined in mpdtrace/pp_hot.o
        >>> defined in mpdtrace/regexec.o

        ld: error: duplicate symbol: __dtraceenabled_perl___op__entry
        >>> defined in mpdtrace/perlmini.o
        >>> defined in mpdtrace/run.o

        ld: error: duplicate symbol: __dtraceenabled_perl___op__entry
        >>> defined in mpdtrace/perlmini.o
        >>> defined in mpdtrace/dump.o

        ld: error: duplicate symbol: __dtraceenabled_perl___sub__entry
        >>> defined in mpdtrace/pp_hot.o
        >>> defined in mpdtrace/pp_ctl.o
        cc: error: linker command failed with exit code 1 (use -v to see invocation)

    Work around these errors by allowing multiple definitions during
    linking, using the --allow-multiple-definition linker flag. (Note: this
    flag is also supported by GNU ld.)

    PR:             265516
    Approved by:    maintainer timeout (1 month)
    MFH:            2022Q3

 lang/perl5-devel/Makefile                     |  2 +-
 lang/perl5-devel/files/patch-hints_freebsd.sh | 13 ++++++++++++-
 lang/perl5.32/Makefile                        |  2 +-
 lang/perl5.32/files/patch-hints_freebsd.sh    | 13 ++++++++++++-
 lang/perl5.34/Makefile                        |  2 +-
 lang/perl5.34/files/patch-hints_freebsd.sh    | 13 ++++++++++++-
 lang/perl5.36/Makefile                        |  2 +-
 lang/perl5.36/files/patch-hints_freebsd.sh    | 13 ++++++++++++-
 8 files changed, 52 insertions(+), 8 deletions(-)
Comment 9 commit-hook freebsd_committer freebsd_triage 2022-09-21 20:27:55 UTC
A commit in branch main references this bug:

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

commit 8c69fc20e6c71c3c5e71c8c9fcfb08ea9d5eb48d
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2022-09-21 20:24:33 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2022-09-21 20:26:53 +0000

    lang/perl5*: alternative workaround for lld 15 and dtrace enabled

    Modify the workaround committed in 4ae8ff941b29 by only adding
    -Wl,--allow-multiple-definition to the two link command lines that
    require it, instead of adding it to hints/freebsd.sh

    Otherwise, that linker flag is emitted into perl's global configuration
    (/usr/local/lib/perl5/5.xx/mach/Config_heavy.pl), and might be used by
    other ports which link in libperl, such as www/mod_perl2, which cannot
    correctly handle any unexpected linker flags, leading to errors.

    PR:             265516
    Reported by:    lev
    Approved by:    maintainer timeout (1 month)
    Fixes:          4ae8ff941b29
    MFH:            2022Q3

 lang/perl5-devel/Makefile                     |  2 +-
 lang/perl5-devel/files/patch-Makefile.SH      | 22 ++++++++++++++++++++--
 lang/perl5-devel/files/patch-hints_freebsd.sh | 11 -----------
 lang/perl5.32/Makefile                        |  2 +-
 lang/perl5.32/files/patch-Makefile.SH         | 22 ++++++++++++++++++++--
 lang/perl5.32/files/patch-hints_freebsd.sh    | 11 -----------
 lang/perl5.34/Makefile                        |  2 +-
 lang/perl5.34/files/patch-Makefile.SH         | 22 ++++++++++++++++++++--
 lang/perl5.34/files/patch-hints_freebsd.sh    | 11 -----------
 lang/perl5.36/Makefile                        |  2 +-
 lang/perl5.36/files/patch-Makefile.SH         | 22 ++++++++++++++++++++--
 lang/perl5.36/files/patch-hints_freebsd.sh    | 11 -----------
 12 files changed, 84 insertions(+), 56 deletions(-)
Comment 10 Mark Johnston freebsd_committer freebsd_triage 2022-12-10 18:11:58 UTC
I believe we'll end up modifying dtrace to avoid annoying the linker, and then these patches can be revert.
Comment 11 commit-hook freebsd_committer freebsd_triage 2022-12-12 13:35:10 UTC
A commit in branch main references this bug:

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

commit 33b05a16fc0346ecdf0206438bd9efe995339bee
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2022-12-12 13:30:34 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2022-12-12 13:34:48 +0000

    lang/perl5*: remove workarounds for lld 15 and dtrace enabled

    After https://cgit.freebsd.org/src/commit/?id=be39466a1035, there is no
    need anymore to patch the perl5 Makefiles to add
    "-Wl,--allow-multiple-definition" to the linker flags. They should now
    link with lld 15 and later without any issues.

    PR:             265516
    Fixes:          8c69fc20e6c7
    MFH:            2022Q4

 lang/perl5-devel/files/patch-Makefile.SH | 18 ------------------
 lang/perl5.32/files/patch-Makefile.SH    | 18 ------------------
 lang/perl5.34/files/patch-Makefile.SH    | 18 ------------------
 lang/perl5.36/files/patch-Makefile.SH    | 18 ------------------
 4 files changed, 72 deletions(-)