Bug 94602 - Tests fail to build when build with LTO on gcc 5.3.0
Summary: Tests fail to build when build with LTO on gcc 5.3.0
Status: RESOLVED FIXED
Alias: None
Product: Wayland
Classification: Unclassified
Component: weston (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Wayland bug list
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-17 19:43 UTC by Link Mauve
Modified: 2017-12-01 17:01 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Link Mauve 2016-03-17 19:43:27 UTC
weston-test-runner complains about undefined reference to __start_test_section and __stop_test_section when Weston is built with -flto.

Disabling all tests allows it to build fine, and the LTO build gains 0.7 MiB of installed size compared to the non-LTO build.
Comment 1 Pekka Paalanen 2016-03-18 08:57:47 UTC
I'd guess -flto is throwing away the special section where we collect the test headers. The section is used to avoid having to create a master list of all tests in addition to writing the tests.

Is there a way to mark that section to not be deleted by LTO?

We rely on the compiler to automatically generate __start_test_section and __stop_test_section when putting things into the section.

Gains size? You mean it's bigger with LTO?
Comment 2 octoploid 2017-04-12 06:22:11 UTC
Sure:

diff --git a/tests/test-runner.h b/tests/test-runner.h
index 64f8d4c6aa4f..600d77c93833 100644
--- a/tests/test-runner.h
+++ b/tests/test-runner.h
@@ -41,7 +41,7 @@ struct test {
        static void name(void);                                 \
                                                                \
        const struct test test##name                            \
-                __attribute__ ((section ("test_section"))) = { \
+                __attribute__ ((used, section ("test_section"))) = {   \
                #name, name, 0                                  \
        };                                                      \
                                                                \
@@ -51,7 +51,7 @@ struct test {
        static void name(void);                                 \
                                                                \
        const struct test test##name                            \
-                __attribute__ ((section ("test_section"))) = { \
+                __attribute__ ((used, section ("test_section"))) = {   \
                #name, name, 1                                  \
        };                                                      \
                                                                \
Comment 3 Quentin Minster 2017-10-17 20:44:59 UTC
Same error here. I've created a bug on the Gentoo tracker, with a patch for Weston 3.0.0:
* bug: https://bugs.gentoo.org/634572
* patch: https://634572.bugs.gentoo.org/attachment.cgi?id=499022

Please consider applying this if it's suitable. :)
Comment 4 Quentin Minster 2017-10-17 20:50:43 UTC
Oh and btw this is with GCC 7.2.0.
Comment 5 Link Mauve 2017-10-17 21:00:23 UTC
Hi, thanks for your patch, I also sent one to the mailing list back in April, see https://patchwork.freedesktop.org/series/23087/
Comment 6 Daniel Stone 2017-12-01 17:01:48 UTC
Pushed to the list now; __attribute__((used)) seems to DTRT on both GCC and clang. Thanks!


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.