Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -161,10 +161,13 @@ .Case("elf_i386", {ELF32LEKind, EM_386}) .Case("elf_iamcu", {ELF32LEKind, EM_IAMCU}) .Case("elf64_sparc", {ELF64BEKind, EM_SPARCV9}) + .Case("msp430elf", {ELF32LEKind, EM_MSP430}) .Default({ELFNoneKind, EM_NONE}); if (ret.first == ELFNoneKind) error("unknown emulation: " + emul); + if (ret.second == EM_MSP430) + osabi = ELFOSABI_STANDALONE; return std::make_tuple(ret.first, ret.second, osabi); } Index: lld/ELF/ScriptParser.cpp =================================================================== --- lld/ELF/ScriptParser.cpp +++ lld/ELF/ScriptParser.cpp @@ -425,6 +425,7 @@ .Case("elf32-littleriscv", {ELF32LEKind, EM_RISCV}) .Case("elf64-littleriscv", {ELF64LEKind, EM_RISCV}) .Case("elf64-sparc", {ELF64BEKind, EM_SPARCV9}) + .Case("elf32-msp430", {ELF32LEKind, EM_MSP430}) .Default({ELFNoneKind, EM_NONE}); } @@ -443,6 +444,8 @@ setError("unknown output format name: " + config->bfdname); if (s == "elf32-ntradlittlemips" || s == "elf32-ntradbigmips") config->mipsN32Abi = true; + if (config->emachine == EM_MSP430) + config->osabi = ELFOSABI_STANDALONE; if (consume(")")) return; Index: lld/test/ELF/emulation-msp430.s =================================================================== --- /dev/null +++ lld/test/ELF/emulation-msp430.s @@ -0,0 +1,26 @@ +# REQUIRES: msp430 +# RUN: llvm-mc -filetype=obj -triple=msp430 %s -o %t.o +# RUN: ld.lld %t.o -o %t1 +# RUN: llvm-readobj --file-headers %t1 | FileCheck %s +# RUN: ld.lld -m msp430elf %t.o -o %t2 +# RUN: cmp %t1 %t2 +# RUN: echo 'OUTPUT_FORMAT(elf32-msp430)' > %t.lds +# RUN: ld.lld -T %t.lds %t.o -o %t3 +# RUN: llvm-readobj --file-headers %t3 | FileCheck %s + +# CHECK: ElfHeader { +# CHECK-NEXT: Ident { +# CHECK-NEXT: Magic: (7F 45 4C 46) +# CHECK-NEXT: Class: 32-bit (0x1) +# CHECK-NEXT: DataEncoding: LittleEndian (0x1) +# CHECK-NEXT: FileVersion: 1 +# CHECK-NEXT: OS/ABI: Standalone (0xFF) +# CHECK-NEXT: ABIVersion: 0 +# CHECK-NEXT: Unused: (00 00 00 00 00 00 00) +# CHECK-NEXT: } +# CHECK-NEXT: Type: Executable (0x2) +# CHECK-NEXT: Machine: EM_MSP430 (0x69) +# CHECK-NEXT: Version: 1 + +.globl _start +_start: