Bug 68384 - global register variables and LTO don't mix
Summary: global register variables and LTO don't mix
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: lto, rejects-valid
: 86442 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-11-17 13:56 UTC by acsawdey
Modified: 2024-10-06 13:48 UTC (History)
7 users (show)

See Also:
Host:
Target: powerpc64le-*-linux*, x86_64
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-11-03 00:00:00


Attachments
zend.i from reduced test case (4.09 KB, text/plain)
2015-11-17 13:56 UTC, acsawdey
Details
zend_execute.i (2.92 KB, text/plain)
2015-11-17 13:57 UTC, acsawdey
Details
php_cli.i (6.76 KB, text/plain)
2015-11-17 13:57 UTC, acsawdey
Details
main.i (8.63 KB, text/plain)
2015-11-17 13:58 UTC, acsawdey
Details

Note You need to log in before you can comment on or make changes to this bug.
Description acsawdey 2015-11-17 13:56:47 UTC
Created attachment 36734 [details]
zend.i from reduced test case

If you attempt to build PHP 7 with -flto, you encounter errors for the 2 register global variables it uses:

zend_execute.i:81:32: error: global register variable follows a function definition
        register const zend_op *opline __asm__("r29");
                                ^

zend_execute.i:80:36: error: global register variable follows a function definition
        register zend_execute_data *execute_data __asm__("r28");
                                    ^

I've reduced this with multidelta and the preprocessed files are attached.

Reproduce with:

gcc -flto -O3 main.i php_cli.i zend_execute.i zend.i

Of course this test case won't link or do anything useful, but it hits the LTO issue before getting to the link phase.

I did my testing with trunk 230270, but older gcc 4.8.x also has the same problem.
Comment 1 acsawdey 2015-11-17 13:57:26 UTC
Created attachment 36735 [details]
zend_execute.i
Comment 2 acsawdey 2015-11-17 13:57:45 UTC
Created attachment 36736 [details]
php_cli.i
Comment 3 acsawdey 2015-11-17 13:58:05 UTC
Created attachment 36737 [details]
main.i
Comment 4 Andrew Pinski 2015-11-17 15:35:37 UTC
First off it seems wrong PHP is using global registers.

But anyways the problem looks related to partitioning.
Comment 5 acsawdey 2015-11-17 18:05:35 UTC
The partitioning seems to be involved. If you add -flto-partition=max, you can get past the global register error. However 230270 that I've been using for testing then hits a recursive inlining error that looks a lot like 59626 when trying to compile all of PHP 7. However gcc 5.2 is able to compile the whole thing using -flto-partition=max.

I think I need to update my trunk build and then see if the recursive inlining error persists.
Comment 6 Richard Biener 2015-11-18 08:57:56 UTC
The proper partitioning algorithm to use would be 1to1, not max (which is for debugging only).

Note that global register vars shouldn't be used with LTO and if they are
restricted to just a few compilation units the recommended fix is to build
those CUs without -flto.

For the particular emitted error the issue is that we fail to materialize
global reg vars before other functions.  But that's likely not the only
issue you might hit with global reg vars.

Honza, that's probably caused by "lazy" initializer stuff or so?  That is
shouldn't materialize_cgraph process those somehow before symtab->compile ()
gets run?
Comment 7 acsawdey 2015-11-18 16:10:33 UTC
Testing with 270468, -flto-partition=max does work and the code runs. However -flto-partition=1to1 gets the register global error.
Comment 8 David Edelsohn 2016-01-21 16:18:57 UTC
Confirmed.
Comment 9 Tiziano Müller 2016-03-02 14:08:06 UTC
not really target-dependant since I can reproduce on x86_64 with 5.3.0
Comment 10 Romain Lalaut 2017-01-18 12:11:29 UTC
I can also reproduce it on x86_64 with 6.3.0
Comment 11 Georg-Johann Lay 2017-07-05 11:48:34 UTC
I am also seeing this on current trunk, even with -fno-toplevel-reorder.  Bit annoying as this also comes up when testing GCC itself, at least if -flto is part of the torture-options.
Comment 12 Andrew Pinski 2021-12-20 01:56:29 UTC
*** Bug 86442 has been marked as a duplicate of this bug. ***