Bug 89012 - SH2 (FDPIC) duplicate symbols in generated assembly.
Summary: SH2 (FDPIC) duplicate symbols in generated assembly.
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 8.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-23 14:49 UTC by Zach van Rijn
Modified: 2019-01-29 05:12 UTC (History)
4 users (show)

See Also:
Host: x86_64-linux-musl
Target: sh2[,eb]-linux-musl (FDPIC)
Build: x86_64-linux-musl
Known to work: 6.4.0
Known to fail: 8.2.0
Last reconfirmed:


Attachments
Tarball containing intermediate asm (with -dp) for each of 5 cases. (1.98 KB, application/x-compressed-tar)
2019-01-29 04:44 UTC, Zach van Rijn
Details
All files produced by -O2 -da (77.11 KB, application/x-compressed-tar)
2019-01-29 05:12 UTC, Zach van Rijn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zach van Rijn 2019-01-23 14:49:39 UTC
Code generated by gcc targeting `sh2eb-linux-musl` occasionally
contains duplicate symbols with optimization level `O2` or above
and produces the following errors during assembly:

    $ gcc -c -mfdpic -O2 -Wno-int-conversion mintest.c
    mintest.s: Assembler messages:
    mintest.s:44: Error: symbol `.LPCS0' is already defined

This also occurs when the target is `sh2-linux-musl` but when it
specifically does not target `sh4` (even FDPIC). It does not
occur at optimization levels `O0` or `O1`.

I am using GCC with the following configuration, however, this
may also occur with 7.3.0 (unverified):

    GCC      : 8.2.0
    binutils : 2.31.1
    musl     : git-39ef61 (2018-11-19)

a minimal test case:

/* mintest.c */
int a, b, c, d;
int *e = (void *)0;
void f ()
{
    for (; d;)
    {
        if (b) c = a;
        e = e[0] = 1 << c;
    }
}

the assembly contains:

.LPCS0:
        mov.l   @r2,r0
        mov.l   r0,@r1
        mov.l   @r3,r2
        tst     r2,r2
        bt.s    .L5
        mov     r0,r1
.LPCS0:
        mov.l   r0,@r2
        mov.l   r0,@r1
        mov.l   @r3,r2
        tst     r2,r2
        bf.s    .L2
        mov     r0,r1

I could not reproduce this under 6.4.0 or 7.3.0 with binutils of
2.30 (the .LPCS0 sections are not present in the assembly).
Comment 1 Rich Felker 2019-01-23 15:55:55 UTC
Binutils version should not be relevant; the bug here is before anything even gets to binutils. It looks like one of the RTL patterns used for calling libgcc bitshift functions from FDPIC was inteded to be non-duplicable but isn't. This bug goes undetected on J2 (-mj2) target because the J2 has the SH3 barrel shift instructions and does not need libgcc for variable shifts, but affects baseline SH2 ISA. I'll look back at the source and see if I can figure out what's happenning.
Comment 2 Oleg Endo 2019-01-25 13:06:41 UTC
You can compile the code with the '-dp' option to see which insn patterns make up the asm code.  The pattern names will be emitted as comments in the asm output.
Comment 3 Zach van Rijn 2019-01-29 04:44:43 UTC
Created attachment 45545 [details]
Tarball containing intermediate asm (with -dp) for each of 5 cases.
Comment 4 Zach van Rijn 2019-01-29 04:45:15 UTC
The error can be reproduced at `O1` optimization level with both
(strictly both) of the following options:

./cc -c mintest.c -O1 -freorder-blocks-algorithm=stc -ftree-pre

Changing to `-freorder-blocks-algorithm=simple` will not reveal
the issue at `O1`, `O2` or `O3`.

In summary, the only known ways to reproduce this issue are:

(0) `-O2` as described in original bug report;

(1) `-O1 -freorder-blocks-algorithm=stc -ftree-pre`, exclusively
    not at any other optimization level;

and the only known ways ot mitigate this issue using either of
the above configurations are:

(2) `-O2 -freorder-blocks-algorithm=simple`;

(3) `-O1` without specifically both of the aforementioned flags.

The attached tarball contains 5 files named by letters 'A' - 'E'
containing the generated assembly, each with -dp` as suggested:

(A) FAIL: `-O2 -freorder-blocks-algorithm=stc`

(B) PASS: `-O2 -freorder-blocks-algorithm=simple`

(C) FAIL: `-O1 -freorder-blocks-algorithm=stc -ftree-pre`

(D) PASS: `-O1 -freorder-blocks-algorithm=simple -ftree-pre`

(E) PASS: `-O1 -freorder-blocks-algorithm=stc`
Comment 5 Zach van Rijn 2019-01-29 05:12:06 UTC
Created attachment 45546 [details]
All files produced by -O2 -da