Support ARM_V4BX relocation
authorFangrui Song <maskray@google.com>
Fri, 16 Nov 2018 19:24:45 +0000 (19:24 +0000)
committerFangrui Song <maskray@google.com>
Fri, 16 Nov 2018 19:24:45 +0000 (19:24 +0000)
Summary: This patch implementation the handler for ARM_V4BX. This relocation is used by GNU runtime files and other armv4 applications.

Patch by Yin Ma

Reviewers: espindola, MaskRay, ruiu, peter.smith, pcc

Reviewed By: ruiu

Subscribers: yinma, pcc, peter.smith, MaskRay, rovka, efriedma, emaste, javed.absar, arichardson, kristof.beyls, chrib, llvm-commits

Differential Revision: https://reviews.llvm.org/D53444

llvm-svn: 347077

lld/ELF/Arch/ARM.cpp
lld/test/ELF/v4bx.yaml [new file with mode: 0644]

index ab0b8f8..1d1dd31 100644 (file)
@@ -514,6 +514,12 @@ void ARM::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
                   ((Val << 4) & 0x7000) |    // imm3
                   (Val & 0x00ff));           // imm8
     break;
+  case R_ARM_V4BX:
+    // V4BX is just a marker to indicate there's a "bx rN" instruction at the
+    // given address. It can be used to implement a special linker mode which
+    // rewrites ARMv4T inputs to ARMv4. Since we support only ARMv4 input and
+    // not ARMv4 output, we can just ignore it.
+    break;
   default:
     error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
   }
diff --git a/lld/test/ELF/v4bx.yaml b/lld/test/ELF/v4bx.yaml
new file mode 100644 (file)
index 0000000..8dd619f
--- /dev/null
@@ -0,0 +1,38 @@
+# REQUIRES: arm
+# RUN: yaml2obj %s -o %t.o
+# RUN: ld.lld %t.o -o %t
+# RUN: llvm-readelf -sections %t | FileCheck %s
+
+# CHECK: .text
+
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS32
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_ARM
+  Flags:           [ EF_ARM_EABI_VER5 ]
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x0000000000000004
+    Content:         1EFF2F01
+  - Name:            .rel.text
+    Type:            SHT_REL
+    Link:            .symtab
+    AddressAlign:    0x0000000000000004
+    Info:            .text
+    Relocations:
+      - Offset:          0x0000000000000000
+        Symbol:          ''
+        Type:            R_ARM_V4BX
+Symbols:
+  Global:
+    - Name:            _start
+      Section:         .text
+  Local:
+    - Name:            .text
+      Type:            STT_SECTION
+      Section:         .text
+DynamicSymbols: