Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lld] Add emulation support for hexagon #98857

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

androm3da
Copy link
Member

No description provided.

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 15, 2024

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-elf

Author: Brian Cain (androm3da)

Changes

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 --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:

@androm3da
Copy link
Member Author

androm3da commented Jul 15, 2024

This is just a draft for discussion - I'd like to strive for maximum compatibility with eld here, not sure about the right behavior wrt big endian. Should we emit an error w/BE, for example?

@androm3da androm3da requested a review from MaskRay July 15, 2024 21:08
@androm3da androm3da changed the title draft: [lld] Add emulation support for hexagon [lld] Add emulation support for hexagon Jul 15, 2024
@@ -0,0 +1,39 @@
# REQUIRES: hexagon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emulation-systemz.s is the latest emulation-* test. We use llvm-readelf there for better readability.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, updated to use llvm-readelf.

@androm3da androm3da merged commit 9078036 into llvm:main Jul 16, 2024
7 checks passed
sgundapa pushed a commit to sgundapa/upstream_effort that referenced this pull request Jul 23, 2024
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary: 

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251650
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants