Index: ELF/ScriptParser.cpp =================================================================== --- ELF/ScriptParser.cpp +++ ELF/ScriptParser.cpp @@ -94,6 +94,7 @@ SortSectionPolicy readSortKind(); SymbolAssignment *readProvideHidden(bool Provide, bool Hidden); SymbolAssignment *readAssignment(StringRef Tok); + std::pair readBfdArch(); std::tuple readBfdName(); void readSort(); Expr readAssert(); @@ -378,11 +379,33 @@ expect(")"); } +std::pair ScriptParser::readBfdArch() { + StringRef S = next(); + + std::pair Arch = + StringSwitch>(S) + .Cases("aarch64", "aarch64:ilp32", {ELF64LEKind, EM_AARCH64}) + .Case("arm", {ELF32LEKind, EM_ARM}) + .Cases("i386", "i386:intel", "i386:x64-32:intel", "i8086", + "i386:x64-32", "i386:x64-32:nacl", "i386:nacl", + {ELF32LEKind, EM_386}) + .Cases("i386:x86-64", "i386:x64-64:intel", "i386:x86-64:nacl", + {ELF64LEKind, EM_X86_64}) + .Case("powerpc:common", {ELF32BEKind, EM_PPC}) + .Case("powerpc:common64", {ELF64BEKind, EM_PPC64}) + .Default({ELFNoneKind, EM_NONE}); + + if (Arch.first == ELFNoneKind) + setError("unknown output arch name: " + S); + + return Arch; +} + void ScriptParser::readOutputArch() { - // OUTPUT_ARCH is ignored for now. + // This overrides the "-m " flag. expect("("); - while (!errorCount() && !consume(")")) - skip(); + std::tie(Config->EKind, Config->EMachine) = readBfdArch(); + expect(")"); } std::tuple ScriptParser::readBfdName() { Index: test/ELF/linkerscript/outputarch.test =================================================================== --- test/ELF/linkerscript/outputarch.test +++ test/ELF/linkerscript/outputarch.test @@ -2,4 +2,4 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-freebsd /dev/null -o %t1 # RUN: ld.lld -shared -o %t2 %t1 %s -OUTPUT_ARCH(All data written here is ignored) +OUTPUT_ARCH(i386:x86-64)