[lld] draft: [lld] Add emulation support for hexagon (PR #98857)

Brian Cain via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 15 13:53:40 PDT 2024


https://github.com/androm3da updated https://github.com/llvm/llvm-project/pull/98857

>From eceb315267d95220748bf4e928095e327ccd5c53 Mon Sep 17 00:00:00 2001
From: Brian Cain <bcain at quicinc.com>
Date: Sun, 14 Jul 2024 22:14:13 -0700
Subject: [PATCH] [lld] Add emulation support for hexagon

---
 lld/ELF/Driver.cpp               |  1 +
 lld/ELF/ScriptParser.cpp         |  1 +
 lld/test/ELF/emulation-hexagon.s | 39 ++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+)
 create mode 100644 lld/test/ELF/emulation-hexagon.s

diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index a94cb3a7cfef7..3a3070aea94f5 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -202,6 +202,7 @@ static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef emul) {
           .Case("elf64_amdgpu", {ELF64LEKind, EM_AMDGPU})
           .Case("elf64loongarch", {ELF64LEKind, EM_LOONGARCH})
           .Case("elf64_s390", {ELF64BEKind, EM_S390})
+          .Case("hexagonelf", {ELF32LEKind, EM_HEXAGON})
           .Default({ELFNoneKind, EM_NONE});
 
   if (ret.first == ELFNoneKind)
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 41bd9a95053f7..5d886a165ae32 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -452,6 +452,7 @@ static std::pair<ELFKind, uint16_t> parseBfdName(StringRef s) {
       .Case("elf32-loongarch", {ELF32LEKind, EM_LOONGARCH})
       .Case("elf64-loongarch", {ELF64LEKind, EM_LOONGARCH})
       .Case("elf64-s390", {ELF64BEKind, EM_S390})
+      .Cases("elf32-hexagon", "elf32-littlehexagon", {ELF32LEKind, EM_HEXAGON})
       .Default({ELFNoneKind, EM_NONE});
 }
 
diff --git a/lld/test/ELF/emulation-hexagon.s b/lld/test/ELF/emulation-hexagon.s
new file mode 100644
index 0000000000000..7dd8a13cdd13d
--- /dev/null
+++ b/lld/test/ELF/emulation-hexagon.s
@@ -0,0 +1,39 @@
+# REQUIRES: hexagon
+
+# RUN: llvm-mc -filetype=obj -triple=hexagon %s -o %t.o
+# RUN: ld.lld %t.o -o %t
+# RUN: llvm-readobj --file-headers %t | FileCheck --check-prefix=HEXAGON %s
+# RUN: ld.lld -m hexagonelf %t.o -o %t
+# RUN: llvm-readobj --file-headers %t | FileCheck --check-prefix=HEXAGON %s
+
+# RUN: echo 'OUTPUT_FORMAT(elf32-littlehexagon)' > %t.script
+# RUN: ld.lld %t.script %t.o -o %t
+# RUN: llvm-readobj --file-headers %t | FileCheck --check-prefix=HEXAGON %s
+
+# RUN: echo 'OUTPUT_FORMAT(elf32-hexagon)' > %t.script
+# RUN: ld.lld %t.script %t.o -o %t
+# RUN: llvm-readobj --file-headers %t | FileCheck --check-prefix=HEXAGON %s
+
+# HEXAGON:       ElfHeader {
+# HEXAGON-NEXT:    Ident {
+# HEXAGON-NEXT:      Magic: (7F 45 4C 46)
+# HEXAGON-NEXT:      Class: 32-bit (0x1)
+# HEXAGON-NEXT:      DataEncoding: LittleEndian (0x1)
+# HEXAGON-NEXT:      FileVersion: 1
+# HEXAGON-NEXT:      OS/ABI: SystemV (0x0)
+# HEXAGON-NEXT:      ABIVersion: 0
+# HEXAGON-NEXT:      Unused: (00 00 00 00 00 00 00)
+# HEXAGON-NEXT:    }
+# HEXAGON-NEXT:    Type: Executable (0x2)
+# HEXAGON-NEXT:    Machine: EM_HEXAGON (0xA4)
+# HEXAGON-NEXT:    Version: 1
+# HEXAGON-NEXT:    Entry: 0x200B4
+# HEXAGON-NEXT:    ProgramHeaderOffset: 0x34
+# HEXAGON-NEXT:    SectionHeaderOffset:
+# HEXAGON-NEXT:    Flags [ (0x60)
+# HEXAGON-NEXT:      0x20
+# HEXAGON-NEXT:      0x40
+# HEXAGON-NEXT:    ]
+
+.globl _start
+_start:



More information about the llvm-commits mailing list