Bug 1693831 - ld --wrap and LTO fails
Summary: ld --wrap and LTO fails
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: binutils
Version: 31
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Nick Clifton
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-03-28 18:14 UTC by Tomasz Kłoczko
Modified: 2020-11-24 18:11 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-11-24 18:11:06 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Tomasz Kłoczko 2019-03-28 18:14:59 UTC
https://gitlab.com/cmocka/cmocka/issues/20

As long as LTO options are used cmocka build fails:

/usr/bin/gcc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -flto  -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -flto -fuse-linker-plugin  -Wl,--wrap=uptime CMakeFiles/test_uptime.dir/test_uptime.c.o  -o test_uptime -Wl,-rpath,/home/tkloczko/rpmbuild/BUILD/cmocka-1.1.5/x86_64-redhat-linux-gnu/src ../../../src/libcmocka.so.0.7.0 /usr/lib64/librt.so 
/usr/bin/ld: /tmp/test_uptime.FbzbXG.ltrans0.ltrans.o: in function `calc_uptime':
/home/tkloczko/rpmbuild/BUILD/cmocka-1.1.5/example/mock/uptime/uptime.c:35: undefined reference to `__wrap_uptime'
collect2: error: ld returned 1 exit status

Comment 1 Andreas Schneider 2019-03-28 18:19:12 UTC
Note that this uses the --wrap option in order to overwrite a function symbol. It looks like --wrap doesn't support linking with LTO.

Comment 2 Andreas Schneider 2019-03-28 18:22:08 UTC
https://gitlab.com/cmocka/cmocka/tree/master/example/mock/uptime the README.md explains the usecase ...

Comment 3 Tomasz Kłoczko 2019-03-28 18:26:13 UTC
Yes. And that documentation does not explains why it fails with LTO :P

Comment 4 Andreas Schneider 2019-03-28 18:32:38 UTC
Because of a linker bug?

Comment 5 Andreas Schneider 2019-03-28 18:35:41 UTC
See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88643

Comment 6 Tomasz Kłoczko 2019-03-28 18:37:29 UTC
OK.
Thank you :)

Comment 7 Nick Clifton 2019-03-29 09:31:28 UTC
Hi Guys,

  Yeah, sorry, but at this time --wrap and LTO are not guaranteed to work.  At least
  not when you are using --wrap to replace an existing symbol rather than providing
  a alternative implementation of an undefined symbol. :-(

  May I suggest omitting -flto from the build command line ?

Cheers
  Nick

Comment 8 Tomasz Kłoczko 2019-03-29 09:49:19 UTC
For now I've applied what disable build that faulting example binary using cmake option (suggested Andreas) so everything else can still be LTO optimised.
SO is it some bug which can be fixed relatively easy or it is some LTO design issue which it is not so easy to solve?
If solving that option could take longer IMO linker should report that -flto and --wrap cannot be used (for now) together. At least that should stop creating bug reports about that issue :)

Comment 9 Nick Clifton 2019-03-29 10:01:07 UTC
(In reply to Tomasz Kłoczko from comment #8)

> SO is it some bug which can be fixed relatively easy or it is some LTO
> design issue which it is not so easy to solve?

The latter. :-(

> If solving that option could take longer IMO linker should report that -flto
> and --wrap cannot be used (for now) together. At least that should stop
> creating bug reports about that issue :)

Except that --wrap will work with -flto if it is being used to provide a definition
for a symbol that does not exist.  So it would have to be a warning rather than an
error message.

Plus ... -flto is a compiler and compiler driver option but it is not actually
a linker option.  (It is never passed to the linker).  Whereas --wrap is a linker
option.  So the only place that a warning message could be generated is in the
compiler driver (ie the gcc program), or more likely, the spec file used by gcc
to construct the command lines that it generates.  All of which means that the
generation of a warning message is a gcc issue and not a binutils issue.  
(Tah dah!  I have ducked the responsibility :-).

Cheers
  Nick

Comment 10 Ben Cotton 2019-08-13 16:52:08 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to '31'.

Comment 11 Ben Cotton 2019-08-13 19:12:52 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 31 development cycle.
Changing version to 31.

Comment 12 Ben Cotton 2020-11-03 15:12:32 UTC
This message is a reminder that Fedora 31 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora 31 on 2020-11-24.
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 '31'.

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 31 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 13 Ben Cotton 2020-11-24 18:11:06 UTC
Fedora 31 changed to end-of-life (EOL) status on 2020-11-24. Fedora 31 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.


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