-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Conversation
@llvm/pr-subscribers-lld @llvm/pr-subscribers-lld-elf Author: Brian Cain (androm3da) ChangesFull diff: https://github.com/llvm/llvm-project/pull/98857.diff 3 Files Affected:
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:
|
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? |
5342030
to
eceb315
Compare
@@ -0,0 +1,39 @@ | |||
# REQUIRES: hexagon |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
eceb315
to
b6b6b41
Compare
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251650
No description provided.