[PATCH] [lld][ELF][ARM] Add veneer generation to branch instructions

Shankar Kalpathi Easwaran shankarke at gmail.com
Mon Feb 9 09:24:20 PST 2015


Other than the below comment, it LGTM.


================
Comment at: lib/ReaderWriter/ELF/ARM/ARMRelocationPass.cpp:33-113
@@ -32,1 +32,83 @@
 
+// ARM B/BL instructions of static relocation veneer.
+// TODO: consider different instruction set for archs below ARMv5
+// (one as for Thumb may be used though it's less optimal).
+const uint8_t Veneer_ARM_B_BL_StaticAtomContent[8] = {
+    0x04, 0xf0, 0x1f,
+    0xe5,             // ldr pc, [pc, #-4]
+    0x00, 0x00, 0x00,
+    0x00              // <target_symbol_address>
+};
+
+// Thumb B/BL instructions of static relocation veneer.
+// TODO: consider different instruction set for archs above ARMv5
+// (one as for ARM may be used since it's more optimal).
+const uint8_t Veneer_THM_B_BL_StaticAtomContent[8] = {
+    0x78, 0x47,       // bx pc
+    0x00, 0x00,       // nop
+    0xfe, 0xff, 0xff,
+    0xea              // b <target_symbol_address>
+};
+
+/// \brief Atoms that hold veneer code.
+class VeneerAtom : public SimpleELFDefinedAtom {
+  StringRef _section;
+
+public:
+  VeneerAtom(const File &f, StringRef secName)
+      : SimpleELFDefinedAtom(f), _section(secName) {}
+
+  Scope scope() const override { return DefinedAtom::scopeTranslationUnit; }
+
+  SectionChoice sectionChoice() const override {
+    return DefinedAtom::sectionBasedOnContent;
+  }
+
+  StringRef customSectionName() const override { return _section; }
+
+  ContentType contentType() const override {
+    return DefinedAtom::typeCode;
+  }
+
+  uint64_t size() const override { return rawContent().size(); }
+
+  ContentPermissions permissions() const override { return permR_X; }
+
+  Alignment alignment() const override { return Alignment(2); }
+
+#ifndef NDEBUG
+  StringRef name() const override { return _name; }
+  std::string _name;
+#else
+  StringRef name() const override { return ""; }
+#endif
+};
+
+/// \brief Atoms that hold veneer for statically relocated
+/// ARM B/BL instructions.
+class Veneer_ARM_B_BL_StaticAtom : public VeneerAtom {
+public:
+  Veneer_ARM_B_BL_StaticAtom(const File &f, StringRef secName)
+      : VeneerAtom(f, secName) {}
+
+  ArrayRef<uint8_t> rawContent() const override {
+    return llvm::makeArrayRef(Veneer_ARM_B_BL_StaticAtomContent);
+  }
+};
+
+/// \brief Atoms that hold veneer for statically relocated
+/// Thumb B/BL instructions.
+class Veneer_THM_B_BL_StaticAtom : public VeneerAtom {
+public:
+  Veneer_THM_B_BL_StaticAtom(const File &f, StringRef secName)
+      : VeneerAtom(f, secName) {}
+
+  DefinedAtom::CodeModel codeModel() const override {
+    return DefinedAtom::codeARMThumb;
+  }
+
+  ArrayRef<uint8_t> rawContent() const override {
+    return llvm::makeArrayRef(Veneer_THM_B_BL_StaticAtomContent);
+  }
+};
+
----------------
Can you move this into an anonymous namespace.

http://reviews.llvm.org/D7502

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list