[llvm-branch-commits] [lld] 92c6141 - lld/ELF: Parse MSP430 BFD/emulation names

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Dec 14 09:43:05 PST 2020


Author: LemonBoy
Date: 2020-12-14T09:38:12-08:00
New Revision: 92c6141ce6a954aa866bba8e53850e7dd9d9abb6

URL: https://github.com/llvm/llvm-project/commit/92c6141ce6a954aa866bba8e53850e7dd9d9abb6
DIFF: https://github.com/llvm/llvm-project/commit/92c6141ce6a954aa866bba8e53850e7dd9d9abb6.diff

LOG: lld/ELF: Parse MSP430 BFD/emulation names

Follow the naming set by TI's own GCC-based toolchain.
Also, force the `osabi` field to `ELFOSABI_STANDALONE`, this matches GNU LD's output (the patching is done in `elf32_msp430_post_process_headers`).

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D92931

Added: 
    lld/test/ELF/emulation-msp430.s

Modified: 
    lld/ELF/Driver.cpp
    lld/ELF/ScriptParser.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 0a399db02341..d7a6cd13ca11 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -161,10 +161,13 @@ static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef emul) {
           .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);
 }
 

diff  --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index c68d7f4f62e1..82b98e5ddebe 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -425,6 +425,7 @@ static std::pair<ELFKind, uint16_t> parseBfdName(StringRef s) {
       .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 @@ void ScriptParser::readOutputFormat() {
     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;

diff  --git a/lld/test/ELF/emulation-msp430.s b/lld/test/ELF/emulation-msp430.s
new file mode 100644
index 000000000000..c747889d798c
--- /dev/null
+++ b/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:


        


More information about the llvm-branch-commits mailing list