[PATCH] D55311: Add support for OUTPUT_ARCH linker script command

Bill Wendling via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 5 00:27:47 PST 2018


void created this revision.
void added a reviewer: MaskRay.
Herald added subscribers: llvm-commits, arichardson, emaste, dschuff.
Herald added a reviewer: espindola.

The OUTPUT_ARCH linker script command overrides the "-m <arch>"
command line flag.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D55311

Files:
  ELF/ScriptParser.cpp
  test/ELF/linkerscript/outputarch.test


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)
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<ELFKind, uint16_t> readBfdArch();
   std::tuple<ELFKind, uint16_t, bool> readBfdName();
   void readSort();
   Expr readAssert();
@@ -378,11 +379,33 @@
   expect(")");
 }
 
+std::pair<ELFKind, uint16_t> ScriptParser::readBfdArch() {
+  StringRef S = next();
+
+  std::pair<ELFKind, uint16_t> Arch =
+      StringSwitch<std::pair<ELFKind, uint16_t>>(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 <arch>" flag.
   expect("(");
-  while (!errorCount() && !consume(")"))
-    skip();
+  std::tie(Config->EKind, Config->EMachine) = readBfdArch();
+  expect(")");
 }
 
 std::tuple<ELFKind, uint16_t, bool> ScriptParser::readBfdName() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55311.176768.patch
Type: text/x-patch
Size: 2117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181205/b7f3ce18/attachment.bin>


More information about the llvm-commits mailing list