Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 455232 - sys-apps/portage: update LDFLAGS QA check
Summary: sys-apps/portage: update LDFLAGS QA check
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
Keywords: InVCS
Depends on:
Blocks: 631448
  Show dependency tree
Reported: 2013-02-03 06:33 UTC by SpanKY
Modified: 2019-05-20 04:06 UTC (History)
4 users (show)

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

example.patch (file_455232.txt,835 bytes, patch)
2014-04-03 18:06 UTC, Tom Wijsman (TomWij) (RETIRED)
Details | Diff
Proposed patch (ldflags.patch,790 bytes, patch)
2017-10-15 19:06 UTC, Felix Janda
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description SpanKY gentoo-dev 2013-02-03 06:33:12 UTC
binutils- is now defaulting to hash-style=gnu for ld.{bfd,gold} so the existing QA check won't work.  might have to do something with gcc's record switches flag ...
Comment 1 Tom Wijsman (TomWij) (RETIRED) gentoo-dev 2014-04-03 18:06:40 UTC
Created attachment 374182 [details, diff]

Was writing a new bug, bug I figured out there's this duplicate; so, copy/paste:

The 77_all_generate-gnu-hash.patch patch from Gentoo patchset binutils-2.24-patches-1.3.tar.xz enables GNU_HASH by default for Linux (non-mips) targets; because of this change, the QA check for missing LDFLAGS no longer works.

One way to get it the QA check to work again is to switch to the old hash style instead of the new one; that way, checking for the absence will make the check work. Attached is an example of this idea.

However, I'm thinking we would need to write a patch that bases itself on the binutils versions in order to properly support the old and the new approach; after everyone has migrated to the newer binutils in the near future, we can then drop the old clause.

There are possibly other solutions, the idea / example is a temporary fix to me.

(Thanks to Zero_Chaos and ssuominen for helping debug this.)
Comment 2 Arfrever Frehtes Taifersar Arahesis 2014-04-03 18:24:28 UTC
Maybe better to patch binutils to default to --hash-style=both (i.e. generate both .hash and .gnu.hash).
Comment 3 SpanKY gentoo-dev 2014-05-04 15:17:19 UTC
(In reply to Arfrever Frehtes Taifersar Arahesis from comment #2)

the binutils default makes more sense.  generating sysv is a waste of disk/memory at runtime.
Comment 4 Tom Wijsman (TomWij) (RETIRED) gentoo-dev 2014-05-04 15:30:13 UTC
Hmm, is there perhaps some other low profile flag (upstream almost never uses it + no drawbacks) that we can use to check this instead of changing the hash style?

Problem with above question is that would be a search for a needle in a haystack.
Comment 5 Sergei Trofimovich (RETIRED) gentoo-dev 2017-10-12 11:01:54 UTC
Popped up again in -dev ML recently:
Comment 6 Felix Janda 2017-10-13 21:40:15 UTC
Maybe the --build-id flag of ld could be used. It produces a lightweight
"" section.
Comment 7 Arfrever Frehtes Taifersar Arahesis 2017-10-14 08:24:35 UTC
(In reply to Felix Janda from comment #6)
> Maybe the --build-id flag of ld could be used. It produces a lightweight
> "" section.

If I understand your suggestion correctly, it would re-introduce bug #526144 (e.g. collisions between many packages).
Comment 8 Felix Janda 2017-10-14 11:29:08 UTC
You are probably right (maybe this has been fixed in portage since
then). Anyway, it seems that --build-id is also used for other purposes
in gentoo.

Next try:

Adding something like '--defsym=__gentoo_check_ldflags=0' would produce
a dummy symbol in the binary, which could then be detected via
'scanelf -q -s __gentoo_check_ldflags'.

This should cause only a very slight size and performance impact on the
resulting binaries, however I'm not sure whether this would interact
badly with other gentoo tools.
Comment 9 Arfrever Frehtes Taifersar Arahesis 2017-10-14 17:00:27 UTC
(In reply to Felix Janda from comment #8)

> Adding something like '--defsym=__gentoo_check_ldflags=0' would produce
> a dummy symbol in the binary, which could then be detected via
> 'scanelf -q -s __gentoo_check_ldflags'.
> This should cause only a very slight size ... impact on the
> resulting binaries

strip tool from sys-devel/binutils probably can remove a specified symbol:

$ strip --help | grep -- strip-symbol
  -N --strip-symbol=<name>         Do not copy symbol <name>

(Portage also supports strip tool from dev-libs/elfutils which does not have this ability.)
Comment 10 Felix Janda 2017-10-15 19:06:25 UTC
Created attachment 498786 [details, diff]
Proposed patch

To test, add "-Wl,--defsym=__gentoo_check_ldflags__=0" to your LDFLAGS
(and try emerging e.g. media-gfx/jpeg2ps).

Note that the symbol added via the ldflags test will be automatically
removed when (or if) the binary is stripped.
Comment 11 Zac Medico gentoo-dev 2017-10-15 21:46:38 UTC
(In reply to Felix Janda from comment #10)
> Created attachment 498786 [details, diff] [details, diff]
> Proposed patch

Note that comm requires sorted input, so maybe it should be something like this:

f=$(comm -3 <(scanelf -qyRF '#k%p' -k .dynsym "${ED}" | LC_ALL=C sort) \
<(scanelf -qyRF '#s%p' -s __gentoo_check_ldflags__ "${ED}"| LC_ALL=C sort))
Comment 13 Felix Janda 2017-10-16 11:19:33 UTC
Thanks for fixing and posting the patch!

If only scanelf provided a way to match binaries not matching a symbol...
Comment 14 Larry the Git Cow gentoo-dev 2017-10-16 17:21:11 UTC
The bug has been referenced in the following commit(s):

commit 730a867c1050937c82c775d7678a616c7b9546e6
Author:     Felix Janda <>
AuthorDate: 2017-10-16 03:51:37 +0000
Commit:     Zac Medico <>
CommitDate: 2017-10-16 17:20:04 +0000

    install-qa-check.d/10ignored-flags: fix LDFLAGS check (bug 455232)
    Since binutils- defaults to hash-style=gnu, use
    a __gentoo_check_ldflags__ symbol instead. The check is now
    enabled by adding "-Wl,--defsym=__gentoo_check_ldflags__=0"
    to LDFLAGS. The symbol will be automatically removed when
    the binary is stripped.
    Acked-by: Brian Dolbec <>

 bin/install-qa-check.d/10ignored-flags | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)}
Comment 15 Felix Janda 2017-10-16 21:56:01 UTC
At some point, the documentation (that is, the devmanual and the wiki pages [1][2][3][4]) should be updated.