[LLVMdev] MIPS & GP register

Carl Norum carl at lytro.com
Thu Aug 16 10:37:13 PDT 2012


On Aug 15, 2012, at 11:56 PM, Eli Friedman wrote:

> On Wed, Aug 15, 2012 at 10:17 PM, Carl Norum <carl at lytro.com> wrote:
>>>    -march=mips32r2
>>>    -mtune=4kem
>>>    -msoft-float
>>>    -EL
>>> 
>>>    -Xclang -triple -Xclang mipsel-sde-elf
>>>    -Xclang -mrelocation-model -Xclang static
>>> 
>>>    -Xclang -mllvm -Xclang -mips-ssection-threshold=0
>>>    -Xclang -mllvm -Xclang -enable-mips-delay-filler
> 
> We generally try to discourage people from using -Xclang flags
> wherever possible; they're really implementation details, and
> considered an unstable interface.
> 
> For the triple and relocation model, the flags you're looking for are
> "-target mipsel-sde-elf" and "-static".

"-static" I think is OK.  "-target mipsel-sde-elf" doesn't work at all - it seems like it tries to pass that flag along to GCC, which then complains "error: unrecognized command line option ‘-triple’".  I changed it to "-ccc-host-triple" and that seemed to fix that problem, but the assembler seems to freak out something fierce.  At first, it said "FATAL:/usr/bin/../libexec/as/x86_64/as: I don't understand 'G' flag!", and when I removed the offending "-Xassembler" flags, it generates hundreds of errors, I think because it's calling "/usr/bin/gcc" and then getting an x86_64 assembler instead of the MIPS cross-assembler.  Adding a -v flag seems to confirm this thinking.  With "-ccc-host-triple mips-sde-elf" and the -v flag, I get this invocation to the assembler (-D, -W and -I flags removed):

     "/usr/bin/gcc" -funsigned-char -msoft-float -Oz -static
        -v -Xassembler -G -Xassembler 0 -ffunction-sections
        -fdata-sections -MD -march=mips32r2 -mtune=4kem -EL
        -fshort-wchar -fno-zero-initialized-in-bss
        -fasynchronous-unwind-tables -c
        -o Coach12p/RfiUiAssetsCompiled1.o -G 0 -x assembler
        /var/folders/mk/0mblc5810cjgs0nylrkjxqbm0000gq/T/RfiUiAssetsCompiled1-cNtWix.s

This GCC invocation gives the error message "i686-apple-darwin11-llvm-gcc-4.2: 0: No such file or directory", I think because of the -G 0 flag.  Here's the matching assembler invocation:

     /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/as 
        -arch x86_64 -force_cpusubtype_ALL -G 0
        -o Coach12p/RfiUiAssetsCompiled1.o
        /var/folders/mk/0mblc5810cjgs0nylrkjxqbm0000gq/T/RfiUiAssetsCompiled1-cNtWix.s

This is the invocation that says:

     FATAL:/usr/bin/../libexec/as/x86_64/as: I don't understand 'G' flag!

As I mentioned above, I tried taking out the "-Xassembler -G -Xassembler 0" flags to shut that error up and see if anything useful happened.  Instead I got a bunch of errors about bad opcodes, which makes sense if it's trying to assemble MIPS assembly with an Intel assembler.  Here are the invocations for reference:

     "/usr/bin/gcc" -funsigned-char -msoft-float -Oz -static
        -v -ffunction-sections -fdata-sections -MD
        -march=mips32r2 -mtune=4kem -EL -fshort-wchar
        -fno-zero-initialized-in-bss -fasynchronous-unwind-tables
        -c -o Coach12p/RfiUiAssetsCompiled1.o -x assembler
        /var/folders/mk/0mblc5810cjgs0nylrkjxqbm0000gq/T/RfiUiAssetsCompiled1-kTss18.s

     /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/as -arch x86_64
        -force_cpusubtype_ALL -o Coach12p/RfiUiAssetsCompiled1.o
        /var/folders/mk/0mblc5810cjgs0nylrkjxqbm0000gq/T/RfiUiAssetsCompiled1-kTss18.s

whereas when I do it with the "-Xclang -triple -Xclang mipsel-sde-elf" style it seems to call the cross-assembler correctly:

     "/usr/local/lytro/bin/mips-sde-elf-gcc" -funsigned-char 
       -msoft-float -Oz -static -v -Xassembler -G -Xassembler 0
       -ffunction-sections -fdata-sections -MD -march=mips32r2
       -mtune=4kem -EL -fshort-wchar -fno-zero-initialized-in-bss
       -fasynchronous-unwind-tables -c -o Coach12p/RfiUiAssetsCompiled1.o
       -G 0 -x assembler
       /var/folders/mk/0mblc5810cjgs0nylrkjxqbm0000gq/T/RfiUiAssetsCompiled1-BmjBFI.s

      /usr/local/lytro/lib/gcc/mips-sde-elf/4.7.1/../../../../mips-sde-elf/bin/as
          -G 0 -EL -mips32r2 -O2 -no-mdebug -mabi=32 -march=mips32r2 -mtune=4kem
          --trap -G 0 -o Coach12p/RfiUiAssetsCompiled1.o
          /var/folders/mk/0mblc5810cjgs0nylrkjxqbm0000gq/T/RfiUiAssetsCompiled1-BmjBFI.s


> For the MIPS-specific flags, I don't think there's an equivalent;
> please file bugs if it's actually useful functionality we should
> be exposing with regular flags.

Both of those flags are critical, I think.  It's possible the delay slot filler isn't believed to be "ready for prime time" and so it's hidden?  It does seem to work fine for us.  Setting the SDATA section threshold is very important for us - our program is much too large and has far too many globals to fit in the 64 KB SDATA section.  I'll file bugs and see what turns up.  I can make the patches myself if you can give me the 30-second pointer in the right direction.

>> I also see in the LLVM 3.1 release notes that "MIPS32 little-endian direct object code emission is functional" - does that mean we don't need a supporting GCC installation anymore?  What do we do to enable this feature?  Would our flags above need to change if we do that?
> 
> "-integrated-as" will force it on.  Not a MIPS expert, so no clue if
> it actually works there.  By itself, it's probably not particularly
> useful in terms of eliminating other tools from your toolchain; like
> the name of flag says, it's basically just an integrated version of
> "as".

I tried turning it on and it seemed to work - it died on some inline assembly, but I think I can fix that and then try again.  Thanks for the tip on the flag.

-- Carl





More information about the llvm-dev mailing list