Bug 1716324 - Module::Build lists the object files after the linker flags, causing underlinking with -Wl,--as-needed
Summary: Module::Build lists the object files after the linker flags, causing underlin...
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: perl-ExtUtils-CBuilder
Version: 31
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Petr Pisar
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2019-06-03 08:40 UTC by Petr Pisar
Modified: 2020-05-14 19:49 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed:
Type: Bug

Attachments (Terms of Use)

Description Petr Pisar 2019-06-03 08:40:53 UTC
perl-Text-Xslate-3.5.6-5.fc30 lost a dependency on libperl.so since -Wl,--as-needed was added to distribution-wide linker flags:

$ scanelf -n blib/arch/auto/Text/Xslate/Xslate.so 
ET_DYN libc.so.6 blib/arch/auto/Text/Xslate/Xslate.so 

$ ldd -r  blib/arch/auto/Text/Xslate/Xslate.so
        linux-vdso.so.1 (0x00007fff0d5cb000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f948b9a1000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f948bb8f000)
undefined symbol: Perl_sv_cmp   (blib/arch/auto/Text/Xslate/Xslate.so)
undefined symbol: PL_ppaddr     (blib/arch/auto/Text/Xslate/Xslate.so)

Xslate.so is built like this:

gcc -lpthread -shared -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -L/usr/local/lib -fstack-protector-strong -lperl -o blib/arch/auto/Text/Xslate/Xslate.so lib/Text/Xslate.o src/xslate_methods.o

The cause is that -Wl,--as-needed takes effect when library is supplied and considering only preceding object files and ignoring and following object files. A correct linker command must list all object files before -l flags. Like this:

gcc lib/Text/Xslate.o src/xslate_methods.o -lpthread -shared -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -L/usr/local/lib -fstack-protector-strong -lperl -o blib/arch/auto/Text/Xslate/Xslate.so

Either there is bug in perl-Text-Xslate build script or in Module::Build::XSUtil that it uses.

Comment 1 Ben Cotton 2020-04-30 21:51:59 UTC
This message is a reminder that Fedora 30 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 30 on 2020-05-26.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
Fedora 'version' of '30'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 30 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 2 Petr Pisar 2020-05-01 06:53:03 UTC
Still issue in F33.

Comment 3 Petr Pisar 2020-05-01 07:04:37 UTC
I read Module::Build::XSUtil, and it does not do anything special regarding the order of object files and linker flags. Module::Build::XSUtil inherits from Module::Build. I checked perl-RPM2 that also uses Module::Build, and the issue manifests there either:

  gcc -lpthread -shared -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -L/usr/local/lib -fstack-protector-strong -lperl -o blib/arch/auto/RPM2/RPM2.so lib/RPM2.o -lrpm -lrpmio

I conclude this is a bug in perl-Module-Build.

Comment 4 Paul Howarth 2020-05-14 19:49:10 UTC
I think the problem may actually lie within ExtUtils::CBuilder (which Module::Build delegates the processes of compiling and linking to), and more specifically to the patch we added to get the linking to libperl to happen in the first place. In that patch, $cf->{lddlflags} has "-lperl" appended to it, and that goes before the object files in the linker command. On the other hand, the ExtUtils::CBuilder::Platform::android module already has code to add libperl to the mix, and does it by fiddling with $args{extra_linker_flags} instead. Maybe our patch should do the same?

Note You need to log in before you can comment on or make changes to this bug.