Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 782364 - app-emulation/qemu-5.2.0-r50 with gcc10 and CFLAGS=-Og: undefined reference to `unknown_lock_type'
Summary: app-emulation/qemu-5.2.0-r50 with gcc10 and CFLAGS=-Og: undefined reference t...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Matthias Maier
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: gcc-10
  Show dependency tree
 
Reported: 2021-04-11 22:39 UTC by Luke-Jr
Modified: 2021-04-12 19:39 UTC (History)
3 users (show)

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


Attachments
build log (build.log.xz,75.27 KB, application/x-xz)
2021-04-11 22:41 UTC, Luke-Jr
Details
emerge --info (emerge--info,20.58 KB, text/plain)
2021-04-12 04:11 UTC, Luke-Jr
Details
alternate amd64 -Og build.log + emerge --info (build.log-emerge-info.txt.xz,43.74 KB, application/x-xz)
2021-04-12 08:14 UTC, Ionen Wolkens
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Luke-Jr 2021-04-11 22:39:41 UTC
5.2.0-r3 built/runs fine. Not sure why -r50 is failing.
Comment 1 Luke-Jr 2021-04-11 22:41:45 UTC
Created attachment 699321 [details]
build log
Comment 2 Luke-Jr 2021-04-12 02:32:38 UTC
Building with GCC 9.3.0 succeeded, so this appears to be a GCC 10.2.0 related issue.
Comment 3 Ionen Wolkens gentoo-dev 2021-04-12 03:08:31 UTC
Could you attach emerge --info for completeness?

Haven't tried gcc9 but I can reproduce only if I use CFLAGS="-Og"

I'd guess the latter got used in the following and isn't being found:

    #if defined(__OPTIMIZE__) && !defined(__SANITIZE_ADDRESS__)
    void unknown_lock_type(void *);
    #else
    static inline void unknown_lock_type(void *unused)
    [...]
Comment 4 Luke-Jr 2021-04-12 04:11:58 UTC
Created attachment 699324 [details]
emerge --info

Indeed, I do use -Og for everything.
Comment 5 Sergei Trofimovich (RETIRED) gentoo-dev 2021-04-12 07:13:24 UTC
Your build.log suggests you are using '-Og -pipe -fomit-frame-pointer -mcpu=power9 -mno-isel -ggdb3' and not just '-Og'.

1. Does it fail with '-Og'?
2. Does ot fail with '-Og' on amd64?

Both build.logs might be useful to compare against one another.
Comment 6 Ionen Wolkens gentoo-dev 2021-04-12 08:05:29 UTC
(In reply to Sergei Trofimovich from comment #5)
> 1. Does it fail with '-Og'?
> 2. Does ot fail with '-Og' on amd64?
As I mentioned in comment #3 I was able to reproduce with just CFLAGS=-Og, and to answer #2, this was on ~amd64
Comment 7 Ionen Wolkens gentoo-dev 2021-04-12 08:14:51 UTC
Created attachment 699357 [details]
alternate amd64 -Og build.log + emerge --info

(In reply to Ionen Wolkens from comment #6)
> As I mentioned in comment #3 I was able to reproduce with just CFLAGS=-Og,
> and to answer #2, this was on ~amd64
Attaching my own logs as well for reference.
Comment 8 Sergei Trofimovich (RETIRED) gentoo-dev 2021-04-12 17:05:22 UTC
Thank you! That's useful. The code relies on dead code elimination to get rid of references.

Looks like -O1 is fine while -Og is not.

$ diff -U0 <(gcc -dM -E - </dev/null) <(gcc -Og -dM -E - </dev/null)
--- /dev/fd/63  2021-04-12 17:57:27.614567285 +0100
+++ /dev/fd/62  2021-04-12 17:57:27.614567285 +0100
@@ -53,0 +54 @@
+#define __OPTIMIZE__ 1
@@ -65,0 +67 @@
+#define _FORTIFY_SOURCE 2
@@ -161 +162,0 @@
-#define __NO_INLINE__ 1

$ diff -U0 <(gcc -Og -Q --help=optimizers) <(gcc -O1 -Q --help=optimizers)
--- /dev/fd/63  2021-04-12 18:00:19.097007226 +0100
+++ /dev/fd/62  2021-04-12 18:00:19.097007226 +0100
@@ -22 +22 @@
-  -fbranch-count-reg                   [disabled]
+  -fbranch-count-reg                   [enabled]
@@ -41 +41 @@
-  -fdse                                [disabled]
+  -fdse                                [enabled]
@@ -64,2 +64,2 @@
-  -fif-conversion                      [disabled]
-  -fif-conversion2                     [disabled]
+  -fif-conversion                      [enabled]
+  -fif-conversion2                     [enabled]
@@ -70 +70 @@
-  -finline-functions-called-once       [disabled]
+  -finline-functions-called-once       [enabled]
@@ -78 +78 @@
-  -fipa-modref                         [disabled]
+  -fipa-modref                         [enabled]
@@ -113 +113 @@
-  -fmove-loop-invariants               [disabled]
+  -fmove-loop-invariants               [enabled]
@@ -185 +185 @@
-  -fssa-phiopt                         [disabled]
+  -fssa-phiopt                         [enabled]
@@ -204 +204 @@
-  -ftree-bit-ccp                       [disabled]
+  -ftree-bit-ccp                       [enabled]
@@ -213 +213 @@
-  -ftree-dse                           [disabled]
+  -ftree-dse                           [enabled]
@@ -228 +228 @@
-  -ftree-pta                           [disabled]
+  -ftree-pta                           [enabled]
@@ -234 +234 @@
-  -ftree-sra                           [disabled]
+  -ftree-sra                           [enabled]

Note that -ftree-dse is disabled for -Og and that retains external references.

We can turn original code to always be a runtime switch from include/qemu/lockable.h:

/* This function gives an error if an invalid, non-NULL pointer type is passed
 * to QEMU_MAKE_LOCKABLE.  For optimized builds, we can rely on dead-code elimination
 * from the compiler, and give the errors already at link time.
 */
#if defined(__OPTIMIZE__) && !defined(__SANITIZE_ADDRESS__)
void unknown_lock_type(void *);
#else
static inline void unknown_lock_type(void *unused)
{
    abort();
}
#endif
Comment 9 Larry the Git Cow gentoo-dev 2021-04-12 19:39:44 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=957314a3054fd202618a5a44c076cbcda8c711d5

commit 957314a3054fd202618a5a44c076cbcda8c711d5
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2021-04-12 19:37:55 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2021-04-12 19:39:33 +0000

    app-emulation/qemu: Do not rely on DCE for lock type test
    
    Fix CFLAGS=-Og build break. -Og fails because gcc does not enable dead
    code elimination (but does set __OPTIMIZE__ define).
    
    The fix avoids DCE reliance downstream entirely.
    
    Reported-by: Luke-Jr
    Closes: https://bugs.gentoo.org/782364
    Package-Manager: Portage-3.0.18, Repoman-3.0.3
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 app-emulation/qemu/files/qemu-5.2.0-dce-locks.patch | 18 ++++++++++++++++++
 app-emulation/qemu/qemu-5.2.0-r50.ebuild            |  1 +
 app-emulation/qemu/qemu-9999.ebuild                 |  1 +
 3 files changed, 20 insertions(+)