[PATCH] D125544: [lld][ELF] Support linking 'elf32-avr' with linker scripts
Ben Shi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat May 14 19:10:05 PDT 2022
benshi001 updated this revision to Diff 429502.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125544/new/
https://reviews.llvm.org/D125544
Files:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/avr5.test
Index: lld/test/ELF/linkerscript/avr5.test
===================================================================
--- /dev/null
+++ lld/test/ELF/linkerscript/avr5.test
@@ -0,0 +1,52 @@
+# REQUIRES: avr
+
+# Test ld.lld can link avr obj files to an executble with a linker script.
+
+# RUN: split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=avr -mcpu=atmega328 %t/avr5.s -o %t/avr5.o
+# RUN: ld.lld %t/avr5.o -T %t/avr5.lds -o %t/avr5a.out
+# RUN: llvm-objdump --mcpu=atmega328 -d %t/avr5a.out | FileCheck %s --check-prefix=RELOC
+# RUN: ld.lld %t/avr5.o -Ttext=0 -Tdata=0x800 -e _start -o %t/avr5b.out
+# RUN: llvm-objdump --mcpu=atmega328 -d %t/avr5b.out | FileCheck %s --check-prefix=RELOC
+
+# RELOC: ldi r24, 2
+# RELOC-NEXT: ldi r25, 8
+
+# RUN: llvm-readelf --headers %t/avr5a.out | FileCheck %s --check-prefix=HEAD
+# RUN: llvm-readelf --headers %t/avr5b.out | FileCheck %s --check-prefix=HEAD
+
+# HEAD: Atmel AVR 8-bit microcontroller
+# HEAD: 0x5, EF_AVR_ARCH_AVR5
+
+# HEAD: Name Type Address Off Size
+# HEAD-NEXT: NULL 00000000 000000 000000
+# HEAD-NEXT: .text PROGBITS 00000000 001000 000006
+# HEAD-NEXT: .data PROGBITS 00000800 001800 000004
+
+#--- avr5.s
+ .text
+ .globl _start
+ .p2align 1
+_start:
+ ldi r24, lo8(def) ; Load lower byte of variable def 16-bit address to r24
+ ldi r25, hi8(def) ; Load higher byte of variable def 16-bit address to r25
+ rjmp _start
+
+ .section .data
+ .type abc, @object
+ .type def, @object
+ .globl abc
+ .globl def
+abc:
+ .short 100
+def:
+ .short 200
+
+#--- avr5.lds
+OUTPUT_FORMAT("elf32-avr", "elf32-avr", "elf32-avr")
+OUTPUT_ARCH(avr:5)
+ENTRY(_start)
+SECTIONS {
+ .text 0x000: { *(.text*) }
+ .data 0x800: { *(.data*) }
+}
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -415,6 +415,7 @@
static std::pair<ELFKind, uint16_t> parseBfdName(StringRef s) {
return StringSwitch<std::pair<ELFKind, uint16_t>>(s)
.Case("elf32-i386", {ELF32LEKind, EM_386})
+ .Case("elf32-avr", {ELF32LEKind, EM_AVR})
.Case("elf32-iamcu", {ELF32LEKind, EM_IAMCU})
.Case("elf32-littlearm", {ELF32LEKind, EM_ARM})
.Case("elf32-x86-64", {ELF32LEKind, EM_X86_64})
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125544.429502.patch
Type: text/x-patch
Size: 2314 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220515/f1598c17/attachment.bin>
More information about the llvm-commits
mailing list