https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81803

            Bug ID: 81803
           Summary: Miscompilation at -O1 on mips64el
           Product: gcc
           Version: 7.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: aurelien at aurel32 dot net
  Target Milestone: ---
              Host: mips64el-unknown-linux-gnu
            Target: mips64el-unknown-linux-gnu
             Build: mips64el-unknown-linux-gnu

Created attachment 41965
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41965&action=edit
testcase

Since the switch to GCC 7 as the default compiler, Debian sees many
miscompilations on mips64el where variables which are stored on the stack and
smaller than 8 bytes long (e.g. uint16_t, bool) are wrongly reloaded with the
LD instruction.

I unfortunately haven't been able to get a self-contained reduced testcase, but
the attached testcase (from apparmor) should show the issue.

The aa_policy_cache_new function takes a uint16_t as the fourth argument. It
gets passed the max_caches, which also has a uint16_t type. When compiled with
g++  -Wfatal-errors -g -O2 -fstack-protector-strong -c -o testcase.o
testcase.ii the generated code contains:

 164:   dea50000        ld      a1,0(s5)
                        164: R_MIPS_GOT_OFST    .bss+0x38
                        164: R_MIPS_NONE        *ABS*+0x38
                        164: R_MIPS_NONE        *ABS*+0x38
 168:   dfa80000        ld      a4,0(sp)
 16c:   2406ff9c        li      a2,-100
 170:   0320f809        jalr    t9
                        170: R_MIPS_JALR        aa_policy_cache_new
                        170: R_MIPS_NONE        *ABS*


As you can see, a4 is loaded with the LD instruction, so the upper bytes are
just garbage and causes the aa_policy_cache_new to not function correctly.

Reply via email to