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

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 14 22:17:31 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-elf

Author: Brian Cain (androm3da)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/98857.diff


3 Files Affected:

- (modified) lld/ELF/Driver.cpp (+2) 
- (modified) lld/ELF/ScriptParser.cpp (+2) 
- (added) lld/test/ELF/emulation-hexagon.s (+35) 


``````````diff
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index a94cb3a7cfef7..de223547880c5 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -202,6 +202,8 @@ 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})
+          .Cases("elf32_littlehexagon", "elf32_hexagon",
+                 {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..ef4d06e47b0e3 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -452,6 +452,8 @@ 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})
+      .Case("elf32-bighexagon", {ELF32BEKind, 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..195976aebafc9
--- /dev/null
+++ b/lld/test/ELF/emulation-hexagon.s
@@ -0,0 +1,35 @@
+# 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-prefixes=HEXAGON,LE %s
+# RUN: ld.lld -m elf32_littlehexagon %t.o -o %t
+# RUN: llvm-readobj --file-headers %t | FileCheck --check-prefixes=HEXAGON,LE %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-prefixes=HEXAGON,LE %s
+
+# HEXAGON:       ElfHeader {
+# HEXAGON-NEXT:    Ident {
+# HEXAGON-NEXT:      Magic: (7F 45 4C 46)
+# HEXAGON-NEXT:      Class: 32-bit (0x1)
+# LE-NEXT:           DataEncoding: LittleEndian (0x1)
+# BE-NEXT:           DataEncoding: BigEndian (0x2)
+# 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:

``````````

</details>


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


More information about the llvm-commits mailing list