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

            Bug ID: 71216
           Summary: Incorrect PPC assembly due to inserted .machine
                    pseudo-op
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at jbirnbaum dot com
  Target Milestone: ---

This report concerns rs6000_file_start() in config/rs6000/rs6000.c as modified
by r219854

I'm working with the PowerPC 405 but I believe this affects a number of
different chips.

GCC version info:
Target: powerpc-softfloat-linux
Configured with: ../gcc-6.1.0/configure --prefix=/toolchains/gcc-6.1.0-powerpc
--build=i386-pc-linux-gnu --host=i386-pc-linux-gnu
--target=powerpc-softfloat-linux --enable-languages=c,c++ --disable-nls
--without-headers --disable-__cxa_atexit
Thread model: posix
gcc version 6.1.0 (GCC)

Simple C file used for testing:
int main ()
{
    unsigned tcr = 5;
           __asm__ volatile (
                "       mttcr   %0  \n"
                : /* no output */
                : "r"( tcr )
                );


    return 0;
}

Compiled using powerpc-softfloat-linux-gcc -mcpu=405 -mregnames -nostdlib
-nodefaultlibs filename.c

objdump -d yields:
a.out:     file format elf32-powerpc


Disassembly of section .text:

10000074 <main>:
10000074:       94 21 ff e0     stwu    r1,-32(r1)
10000078:       93 e1 00 1c     stw     r31,28(r1)
1000007c:       7c 3f 0b 78     mr      r31,r1
10000080:       39 20 00 05     li      r9,5
10000084:       91 3f 00 08     stw     r9,8(r31)
10000088:       81 3f 00 08     lwz     r9,8(r31)
1000008c:       7d 3a f3 a6     mtspr   340,r9
10000090:       39 20 00 00     li      r9,0
10000094:       7d 23 4b 78     mr      r3,r9
10000098:       39 7f 00 20     addi    r11,r31,32
1000009c:       83 eb ff fc     lwz     r31,-4(r11)
100000a0:       7d 61 5b 78     mr      r1,r11
100000a4:       4e 80 00 20     blr

The "mtspr 340" part should be "mtspr 986" since the PowerPC 405 does not use
the PowerPC Book E SPRN register numbers.

Using -save-temps I see the following assembly
        .file   "filename.c"
        .machine ppc
        .section        ".text"
        .align 2
        .globl main
        .type   main, @function
main:
        stwu 1,-32(1)
        stw 31,28(1)
        mr 31,1
        li 9,5
        stw 9,8(31)
        lwz 9,8(31)
#APP
 # 4 "filename.c" 1
               mttcr   9

 # 0 "" 2
#NO_APP
        li 9,0
        mr 3,9
        addi 11,31,32
        lwz 31,-4(11)
        mr 1,11
        blr
        .size   main, .-main
        .ident  "GCC: (GNU) 6.1.0"
        .section        .note.GNU-stack,"",@progbits

Note the ".machine ppc" part which overrides the parameters provided at the as
command line.  In this case using "gcc -v" I saw:
powerpc-softfloat-linux/bin/as -v -m405 -many -mbig -o filename.o filename.s

So instead of -m405 the assember uses the setting of -mppc.  Per
https://sourceware.org/binutils/docs/as/PowerPC_002dOpts.html#PowerPC_002dOpts
this is PowerPC 603/604 assembly and not the requested PowerPC 403/405
assembly.

It appears this would happen for a number of the -m options, since the code in
rs6000.c has .machine ppc as the default if none of the powerN or ppc64
selections apply.

Searching the Internet for related info on this issue for PowerPC 4xx I did
find a related patch:
https://github.com/sba1/adtools/blob/master/gcc/5/patches/0003-Disable-.machine-directive-generation.patch

Reply via email to