status of msp430?

Hello,

I have a user asking about msp430 support for Zig. When they try to target msp430, this error is triggered:

if (target_machine->addPassesToEmitFile(MPM, dest, ft)) {
*error_message = strdup(“TargetMachine can’t emit a file of this type”);
return true;
}

I tried using clang alone: clang -c add.c -target msp430-unknown

int add(int a, int b) {
return a + b;
}

$ clang -c add.c -target msp430-unknown
/run/user/1000/add-91f569.s: Assembler messages:
/run/user/1000/add-91f569.s:7: Error: no such instruction: push.w r4' /run/user/1000/add-91f569.s:8: Error: no such instruction: mov.w r1,r4’
/run/user/1000/add-91f569.s:9: Error: no such instruction: sub.w ' /run/user/1000/add-91f569.s:10: Error: no such instruction: mov.w r13,r14’
/run/user/1000/add-91f569.s:11: Error: no such instruction: mov.w r12,r15' /run/user/1000/add-91f569.s:12: Error: no such instruction: mov.w r12,-2(r4)’
/run/user/1000/add-91f569.s:13: Error: no such instruction: mov.w r13,-4(r4)' /run/user/1000/add-91f569.s:14: Error: no such instruction: mov.w -2(r4),r12’
/run/user/1000/add-91f569.s:15: Error: no such instruction: mov.w -4(r4),r13' /run/user/1000/add-91f569.s:16: Error: no such instruction: add.w r13,r12’
/run/user/1000/add-91f569.s:17: Error: no such instruction: mov.w r14,-6(r4)' /run/user/1000/add-91f569.s:18: Error: no such instruction: mov.w r15,-8(r4)’
/run/user/1000/add-91f569.s:19: Error: no such instruction: add.w ' /run/user/1000/add-91f569.s:20: Error: no such instruction: pop.w r4’
clang-6.0: error: assembler command failed with exit code 1 (use -v to see invocation)

It looks like msp430 is in the non-experimental target list:

List of all targets to be built by default:

set(LLVM_ALL_TARGETS
AArch64
AMDGPU
ARM
BPF
Hexagon
Lanai
Mips
MSP430
NVPTX
PowerPC
Sparc
SystemZ
X86
XCore
)

Is msp430 supported?

Hi Andrew,

I have a user asking about msp430 support for Zig. When they try to target msp430, this error is triggered:

        if (target_machine->addPassesToEmitFile(MPM, dest, ft)) {
            *error_message = strdup("TargetMachine can't emit a file of this type");
            return true;
        }

It looks like there's no support for emitting object files in MSP430
(and so no JIT).

$ clang -c add.c -target msp430-unknown
/run/user/1000/add-91f569.s: Assembler messages:
/run/user/1000/add-91f569.s:7: Error: no such instruction: `push.w r4'

This is for the same reason as above. Because Clang can't emit an
object file it's emitting textual assembly and calling the host's
assembler on it. Obviously that doesn't go well when the host's
assembler is expecting x86 input.

Is msp430 supported?

I think it's a bit of a grey area. It's had about 2 patches in the
last year so it's not exactly active, and I don't know of anyone doing
runtime tests to make sure regressions don't creep in. But it's a
fairly simple backend so chances are it'll keep working anyway.

Cheers.

Tim.

Hello,

Tim is right, you need to have msp430-elf-gcc [1] installed in your /usr/bin
(don't ask me why it has to be /usr/bin, I don't know why clang can't just search your $PATH)
and you also need to set the target to `--target=msp430-elf` that way clang can find assembler
to produce the object files.

I can confirm that codegen in LLVM 6.0 release is working fine. There are some missing features
like low power modes support and there are some bugs, like [2] and [3] but you can work around them.

I am trying to keep this target running, but unfortunately I don't have much free time lately.

Regards,
Vadzim

[1] http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSPGCC/5_01_02_00/index_FDS.html
[2] http://lists.llvm.org/pipermail/llvm-dev/2018-May/123597.html
[3] https://bugs.llvm.org/show_bug.cgi?id=37618