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
This commit is contained in:
LemonBoy 2020-12-14 09:38:12 -08:00 committed by Fangrui Song
parent bfdc19e778
commit 92c6141ce6
3 changed files with 32 additions and 0 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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: