Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -94,7 +94,7 @@ SortSectionPolicy readSortKind(); SymbolAssignment *readProvideHidden(bool Provide, bool Hidden); SymbolAssignment *readAssignment(StringRef Tok); - std::pair readBfdName(); + std::tuple readBfdName(); void readSort(); Expr readAssert(); Expr readConstant(); @@ -385,27 +385,35 @@ skip(); } -std::pair ScriptParser::readBfdName() { +std::tuple ScriptParser::readBfdName() { StringRef S = unquote(next()); if (S == "elf32-i386") - return {ELF32LEKind, EM_386}; + return {ELF32LEKind, EM_386, S}; if (S == "elf32-iamcu") - return {ELF32LEKind, EM_IAMCU}; + return {ELF32LEKind, EM_IAMCU, S}; if (S == "elf32-littlearm") - return {ELF32LEKind, EM_ARM}; + return {ELF32LEKind, EM_ARM, S}; if (S == "elf32-x86-64") - return {ELF32LEKind, EM_X86_64}; + return {ELF32LEKind, EM_X86_64, S}; if (S == "elf64-littleaarch64") - return {ELF64LEKind, EM_AARCH64}; + return {ELF64LEKind, EM_AARCH64, S}; if (S == "elf64-powerpc") - return {ELF64BEKind, EM_PPC64}; + return {ELF64BEKind, EM_PPC64, S}; if (S == "elf64-powerpcle") - return {ELF64LEKind, EM_PPC64}; + return {ELF64LEKind, EM_PPC64, S}; if (S == "elf64-x86-64") - return {ELF64LEKind, EM_X86_64}; + return {ELF64LEKind, EM_X86_64, S}; + if (S == "elf32-tradbigmips" || S == "elf32-ntradbigmips") + return {ELF32BEKind, EM_MIPS, S}; + if (S == "elf32-tradlittlemips" || S == "elf32-ntradlittlemips") + return {ELF32LEKind, EM_MIPS, S}; + if (S == "elf64-tradbigmips") + return {ELF64BEKind, EM_MIPS, S}; + if (S == "elf64-tradlittlemips") + return {ELF64LEKind, EM_MIPS, S}; setError("unknown output format name: " + S); - return {ELFNoneKind, EM_NONE}; + return {ELFNoneKind, EM_NONE, S}; } // Parse OUTPUT_FORMAT(bfdname) or OUTPUT_FORMAT(bfdname, big, little). @@ -413,10 +421,15 @@ void ScriptParser::readOutputFormat() { expect("("); - std::pair P = readBfdName(); + ELFKind BfdEKind; + uint16_t BfdEMachine; + StringRef BfdName; + std::tie(BfdEKind, BfdEMachine, BfdName) = readBfdName(); if (Config->EKind == ELFNoneKind) { - Config->EKind = P.first; - Config->EMachine = P.second; + Config->EKind = BfdEKind; + Config->EMachine = BfdEMachine; + Config->MipsN32Abi = + (BfdName == "elf32-ntradbigmips" || BfdName == "elf32-ntradlittlemips"); } if (consume(")")) Index: test/ELF/emulation-mips.s =================================================================== --- test/ELF/emulation-mips.s +++ test/ELF/emulation-mips.s @@ -4,6 +4,9 @@ # RUN: llvm-readobj -file-headers %t2mips | FileCheck --check-prefix=MIPS %s # RUN: ld.lld %tmips -e _start -o %t3mips # RUN: llvm-readobj -file-headers %t3mips | FileCheck --check-prefix=MIPS %s +# RUN: echo 'OUTPUT_FORMAT(elf32-tradbigmips)' > %tmips.script +# RUN: ld.lld %tmips.script -e _start %tmips -o %t4mips +# RUN: llvm-readobj -file-headers %t4mips | FileCheck --check-prefix=MIPS %s # MIPS: ElfHeader { # MIPS-NEXT: Ident { # MIPS-NEXT: Magic: (7F 45 4C 46) @@ -33,6 +36,9 @@ # RUN: llvm-readobj -file-headers %t2mipsel | FileCheck --check-prefix=MIPSEL %s # RUN: ld.lld %tmipsel -e _start -o %t3mipsel # RUN: llvm-readobj -file-headers %t3mipsel | FileCheck --check-prefix=MIPSEL %s +# RUN: echo 'OUTPUT_FORMAT(elf32-tradlittlemips)' > %tmipsel.script +# RUN: ld.lld %tmipsel.script -e _start %tmipsel -o %t4mipsel +# RUN: llvm-readobj -file-headers %t4mipsel | FileCheck --check-prefix=MIPSEL %s # MIPSEL: ElfHeader { # MIPSEL-NEXT: Ident { # MIPSEL-NEXT: Magic: (7F 45 4C 46) @@ -55,12 +61,77 @@ # MIPSEL-NEXT: EF_MIPS_CPIC # MIPSEL-NEXT: ] +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux-gnuabin32 %s -o %tmipsn32 +# RUN: ld.lld -m elf32btsmipn32 -e _start %tmipsn32 -o %t2mipsn32 +# RUN: llvm-readobj -file-headers %t2mipsn32 | FileCheck --check-prefix=MIPSN32 %s +# RUN: ld.lld %tmipsn32 -e _start -o %t3mipsn32 +# RUN: llvm-readobj -file-headers %t3mipsn32 | FileCheck --check-prefix=MIPSN32 %s +# RUN: echo 'OUTPUT_FORMAT(elf32-ntradbigmips)' > %tmipsn32.script +# RUN: ld.lld %tmipsn32.script -e _start %tmipsn32 -o %t4mipsn32 +# RUN: llvm-readobj -file-headers %t4mipsn32 | FileCheck --check-prefix=MIPSN32 %s +# MIPSN32: ElfHeader { +# MIPSN32-NEXT: Ident { +# MIPSN32-NEXT: Magic: (7F 45 4C 46) +# MIPSN32-NEXT: Class: 32-bit (0x1) +# MIPSN32-NEXT: DataEncoding: BigEndian (0x2) +# MIPSN32-NEXT: FileVersion: 1 +# MIPSN32-NEXT: OS/ABI: SystemV (0x0) +# MIPSN32-NEXT: ABIVersion: 1 +# MIPSN32-NEXT: Unused: (00 00 00 00 00 00 00) +# MIPSN32-NEXT: } +# MIPSN32-NEXT: Type: Executable (0x2) +# MIPSN32-NEXT: Machine: EM_MIPS (0x8) +# MIPSN32-NEXT: Version: 1 +# MIPSN32-NEXT: Entry: +# MIPSN32-NEXT: ProgramHeaderOffset: 0x34 +# MIPSN32-NEXT: SectionHeaderOffset: +# MIPSN32-NEXT: Flags [ +# MIPSN32-NEXT: EF_MIPS_ABI2 +# MIPSN32-NEXT: EF_MIPS_ARCH_64 +# MIPSN32-NEXT: EF_MIPS_CPIC +# MIPSN32-NEXT: ] + +# RUN: llvm-mc -filetype=obj -triple=mips64el-unknown-linux-gnuabin32 %s -o %tmipsn32el +# RUN: ld.lld -m elf32ltsmipn32 -e _start %tmipsn32el -o %t2mipsn32el +# RUN: llvm-readobj -file-headers %t2mipsn32el | FileCheck --check-prefix=MIPSN32EL %s +# RUN: ld.lld -melf32ltsmipn32 -e _start %tmipsn32el -o %t2mipsn32el +# RUN: llvm-readobj -file-headers %t2mipsn32el | FileCheck --check-prefix=MIPSN32EL %s +# RUN: ld.lld %tmipsn32el -e _start -o %t3mipsn32el +# RUN: llvm-readobj -file-headers %t3mipsn32el | FileCheck --check-prefix=MIPSN32EL %s +# RUN: echo 'OUTPUT_FORMAT(elf32-ntradlittlemips)' > %tmipsn32el.script +# RUN: ld.lld %tmipsn32el.script -e _start %tmipsn32el -o %t4mipsn32el +# RUN: llvm-readobj -file-headers %t4mipsn32el | FileCheck --check-prefix=MIPSN32EL %s +# MIPSN32EL: ElfHeader { +# MIPSN32EL-NEXT: Ident { +# MIPSN32EL-NEXT: Magic: (7F 45 4C 46) +# MIPSN32EL-NEXT: Class: 32-bit (0x1) +# MIPSN32EL-NEXT: DataEncoding: LittleEndian (0x1) +# MIPSN32EL-NEXT: FileVersion: 1 +# MIPSN32EL-NEXT: OS/ABI: SystemV (0x0) +# MIPSN32EL-NEXT: ABIVersion: 1 +# MIPSN32EL-NEXT: Unused: (00 00 00 00 00 00 00) +# MIPSN32EL-NEXT: } +# MIPSN32EL-NEXT: Type: Executable (0x2) +# MIPSN32EL-NEXT: Machine: EM_MIPS (0x8) +# MIPSN32EL-NEXT: Version: 1 +# MIPSN32EL-NEXT: Entry: +# MIPSN32EL-NEXT: ProgramHeaderOffset: 0x34 +# MIPSN32EL-NEXT: SectionHeaderOffset: +# MIPSN32EL-NEXT: Flags [ +# MIPSN32EL-NEXT: EF_MIPS_ABI2 +# MIPSN32EL-NEXT: EF_MIPS_ARCH_64 +# MIPSN32EL-NEXT: EF_MIPS_CPIC +# MIPSN32EL-NEXT: ] + # RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux -position-independent \ # RUN: %s -o %tmips64 # RUN: ld.lld -m elf64btsmip -e _start %tmips64 -o %t2mips64 # RUN: llvm-readobj -file-headers %t2mips64 | FileCheck --check-prefix=MIPS64 %s # RUN: ld.lld %tmips64 -e _start -o %t3mips64 # RUN: llvm-readobj -file-headers %t3mips64 | FileCheck --check-prefix=MIPS64 %s +# RUN: echo 'OUTPUT_FORMAT(elf64-tradbigmips)' > %tmips64.script +# RUN: ld.lld %tmips64.script -e _start %tmips64 -o %t4mips64 +# RUN: llvm-readobj -file-headers %t4mips64 | FileCheck --check-prefix=MIPS64 %s # MIPS64: ElfHeader { # MIPS64-NEXT: Ident { # MIPS64-NEXT: Magic: (7F 45 4C 46) @@ -89,6 +160,9 @@ # RUN: llvm-readobj -file-headers %t2mips64el | FileCheck --check-prefix=MIPS64EL %s # RUN: ld.lld %tmips64el -e _start -o %t3mips64el # RUN: llvm-readobj -file-headers %t3mips64el | FileCheck --check-prefix=MIPS64EL %s +# RUN: echo 'OUTPUT_FORMAT(elf64-tradlittlemips)' > %tmips64el.script +# RUN: ld.lld %tmips64el.script -e _start %tmips64el -o %t4mips64el +# RUN: llvm-readobj -file-headers %t4mips64el | FileCheck --check-prefix=MIPS64EL %s # MIPS64EL: ElfHeader { # MIPS64EL-NEXT: Ident { # MIPS64EL-NEXT: Magic: (7F 45 4C 46)