Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 876430 - media-sound/mup-6.9 fails to compile (lto): <artificial>:(.text+0xc7d): undefined reference to yywrap
Summary: media-sound/mup-6.9 fails to compile (lto): <artificial>:(.text+0xc7d): undef...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Sound Team
URL:
Whiteboard:
Keywords:
Depends on: 926120
Blocks: lto
  Show dependency tree
 
Reported: 2022-10-10 07:15 UTC by Agostino Sarubbo
Modified: 2024-03-14 21:26 UTC (History)
1 user (show)

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


Attachments
build.log (build.log,65.84 KB, text/plain)
2022-10-10 07:15 UTC, Agostino Sarubbo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Agostino Sarubbo gentoo-dev 2022-10-10 07:15:56 UTC
https://blogs.gentoo.org/ago/2020/07/04/gentoo-tinderbox/

Issue: media-sound/mup-6.9 fails to compile (lto).
Discovered on: amd64 (internal ref: lto_tinderbox)

NOTE:
This machine uses lto with CFLAGS=-flto -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing

Here is a bit of explanation:

-Werror=lto-type-mismatch:
User to find possible runtime issues in packages. It likely means the package is unsafe to build & use with LTO.
For projects using the same identifier but with different types across different files, they must be fixed to be consistent across the codebase.

-Werror=odr:
Used to find possible runtime issues in packages. These bugs are a problem anyway but may be even worse when combined with LTO. C++ code must comply with the One Definition Rule (ODR) - see https://en.cppreference.com/w/cpp/language/definition#One_Definition_Rule.

-Werror=strict-aliasing:
Used to find possible runtime issues in packages. These bugs are a problem anyway but may be even worse when combined with LTO.

Workarounds:
- If upstream is friendly and still active, file a bug upstream. For emulators, codecs, games, or multimedia packages, it may be worth just applying a workaround instead, as upstreams sometimes aren't receptive to these bugs (VALID FOR ALL).
- Use the new 'filter-lto' from flag-o-matic.eclass as it's likely to be unsafe with LTO (VALID FOR lto-type-mismatch - odr).
- Fix it yourself if interested, of course (VALID FOR ALL).
- Append-flags -fno-strict-aliasing (VALID FOR strict-aliasing).
- Use memcpy() but a union is sometimes suitable too (VALID FOR strict-aliasing).
- -fstrict-aliasing is implied by -O2, so this must be addressed in some form (VALID FOR strict-aliasing).

See also: https://marc.info/?l=gentoo-dev&m=165639574126280&w=2
Comment 1 Agostino Sarubbo gentoo-dev 2022-10-10 07:15:58 UTC
Created attachment 823369 [details]
build.log

build log and emerge --info
Comment 2 Agostino Sarubbo gentoo-dev 2022-10-10 07:16:00 UTC
Error(s) that match a know pattern in addition to what has been reported in the summary:


<artificial>:(.text+0xc7d): undefined reference to `yywrap'
<artificial>:(.text.startup+0x347f): undefined reference to `yywrap'
collect2: error: ld returned 1 exit status
Comment 3 Eli Schwartz gentoo-dev 2024-03-04 03:09:49 UTC
This only happens when flex is ALSO compiled with LTO.

configure:5745: checking for library containing yywrap
configure:5781: x86_64-pc-linux-gnu-gcc -o conftest -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types  -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 conftest.c -lfl   >&5
conftest.c:21:6: error: type of 'yywrap' does not match original declaration [-Werror=lto-type-mismatch]
   21 | char yywrap (void);
      |      ^
/var/tmp/portage/sys-devel/flex-2.6.4-r6/work/flex-2.6.4/src/libyywrap.c:26:9: note: return value type mismatch
/var/tmp/portage/sys-devel/flex-2.6.4-r6/work/flex-2.6.4/src/libyywrap.c:26:9: note: type 'int' should match type 'char'
/var/tmp/portage/sys-devel/flex-2.6.4-r6/work/flex-2.6.4/src/libyywrap.c:26:9: note: 'yywrap' was previously declared here
lto1: some warnings being treated as errors
lto-wrapper: fatal error: x86_64-pc-linux-gnu-gcc returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed


This seems like an autoconf bug given it owns the relevant macro...
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-03-04 03:12:48 UTC
See also https://github.com/westes/flex/issues/277 (but not yet sure if it's actually related).

(In reply to Eli Schwartz from comment #3)
> This only happens when flex is ALSO compiled with LTO.
> 

Bleh.

> configure:5745: checking for library containing yywrap
> configure:5781: x86_64-pc-linux-gnu-gcc -o conftest -march=native
> -fstack-protector-all -O2 -pipe -fdiagnostics-color=always
> -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3
> -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch
> -Werror=strict-aliasing  -Wformat -Werror=format-security
> -Werror=implicit-function-declaration -Werror=implicit-int
> -Werror=int-conversion -Werror=incompatible-pointer-types  -Wl,-O1
> -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch
> -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 conftest.c
> -lfl   >&5
> conftest.c:21:6: error: type of 'yywrap' does not match original declaration
> [-Werror=lto-type-mismatch]
>    21 | char yywrap (void);
>       |      ^

Yeah, this is the standard prototype it uses. What's interesting is that it manages to include the header for yywrap so the fallback prototype isn't needed, then they conflict.

> /var/tmp/portage/sys-devel/flex-2.6.4-r6/work/flex-2.6.4/src/libyywrap.c:26:
> 9: note: return value type mismatch
> /var/tmp/portage/sys-devel/flex-2.6.4-r6/work/flex-2.6.4/src/libyywrap.c:26:
> 9: note: type 'int' should match type 'char'
> /var/tmp/portage/sys-devel/flex-2.6.4-r6/work/flex-2.6.4/src/libyywrap.c:26:
> 9: note: 'yywrap' was previously declared here
> lto1: some warnings being treated as errors
> lto-wrapper: fatal error: x86_64-pc-linux-gnu-gcc returned 1 exit status
> compilation terminated.
> /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld:
> error: lto-wrapper failed
> 
> 
> This seems like an autoconf bug given it owns the relevant macro...

The autoconf people are generally not keen on when you tell them you built with -Werror=x, although really, I think in this case, it's justified. Just be prepred to have to explain why we're using it.
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-03-04 03:15:21 UTC
(In reply to Sam James from comment #4)
> Yeah, this is the standard prototype it uses. What's interesting is that it
> manages to include the header for yywrap so the fallback prototype isn't
> needed, then they conflict.

or, wait, is it that libfl is a static library, and it has the information encoded in there because LTO?
Comment 6 Eli Schwartz gentoo-dev 2024-03-04 03:20:02 UTC
Yes, flex distributes a static library and that is what is conflicting.
Comment 7 Eli Schwartz gentoo-dev 2024-03-04 03:21:26 UTC
Probably once again a "if we could strip out LTO bytecode from installed static archives and avoid compiler ICE after you update the compiler without recompiling all packages".

Just a slightly different reason this time...