[PATCH] D32991: [ELF] Initial migration of AVR target

Leslie Zhai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 10 23:44:30 PDT 2017


xiangzhai updated this revision to Diff 98585.
xiangzhai added a comment.

Dear Rui,

> link an executable as long as input object files contain nothing other than R_AVR_32 relocations.

I will try it on my UNO atmega328p in my apartment, but I can only play with LLVM's source code in my office :)

> By the way, you are saying that I'm a mentor. Are you a GSoC participant? I'm just wondering.

I respect you leading NewLLD <http://llvm.org/devmtg/2016-03/#presentation3>, so respectfully call you 先生! I am not a GSoC partcipant, to me, as a KDE developer, I started to use gcc when I was a university student in 2002 <https://dot.kde.org/2016/10/20/leslie-zhai-talks-20-years-kde-china> and only developed a toy-compiler in Assembly as my "Compile Principle" home assignment, but not deep into the internals of gcc. During 2014, at iSOFTLinux <https://reviews.llvm.org/D32269>, we tried to work on a GNU-free base system, so I switched to LLVM just for fun and learn, then tried to fix libclang segfault issue when parsing <https://bugs.llvm.org//show_bug.cgi?id=13619> and Sema's destructor relative issue <https://bugs.llvm.org//show_bug.cgi?id=21905> recently I am teaching the MallocChecker about Glib API <https://reviews.llvm.org/D30771> just simply use AST, PathSensitive and ADT, so basically I am only a LLVM "user". so it is a long jouney to be familiar with LLVM by reading source code directly to reduce the gap between other smarter LLVM developers.

Regards,
Leslie Zhai


Repository:
  rL LLVM

https://reviews.llvm.org/D32991

Files:
  ELF/InputFiles.cpp
  ELF/Target.cpp


Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -247,6 +247,15 @@
   void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
   bool usesOnlyLowPageBits(uint32_t Type) const override;
 };
+
+class AVRTargetInfo final : public TargetInfo {
+public:
+  AVRTargetInfo();
+  RelExpr getRelExpr(uint32_t Type, const SymbolBody &S,
+                     const uint8_t *Loc) const override;
+  int64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override;
+  void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
+};
 } // anonymous namespace
 
 TargetInfo *createTarget() {
@@ -281,6 +290,8 @@
     if (Config->EKind == ELF32LEKind)
       return make<X86_64TargetInfo<ELF32LE>>();
     return make<X86_64TargetInfo<ELF64LE>>();
+  case EM_AVR:
+    return make<AVRTargetInfo>();
   }
   fatal("unknown target machine");
 }
@@ -2400,5 +2411,34 @@
 bool MipsTargetInfo<ELFT>::usesOnlyLowPageBits(uint32_t Type) const {
   return Type == R_MIPS_LO16 || Type == R_MIPS_GOT_OFST;
 }
+
+AVRTargetInfo::AVRTargetInfo() {
+}
+
+RelExpr AVRTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S,
+                                  const uint8_t *Loc) const {
+  return R_NONE;
+}
+
+int64_t AVRTargetInfo::getImplicitAddend(const uint8_t *Buf,
+                                         uint32_t Type) const {
+  switch (Type) {
+  default:
+    return 0;
+  case R_AVR_32:
+    return SignExtend64<32>(read32le(Buf));
+  }
+}
+
+void AVRTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
+                                uint64_t Val) const {
+  switch (Type) {
+  case R_AVR_32:
+    write32le(Loc, Val);
+    break;
+  default:
+    error(getErrorLocation(Loc) + "unrecognized reloc " + Twine(Type));
+  }
+}
 }
 }
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -803,6 +803,8 @@
     return T.isOSIAMCU() ? EM_IAMCU : EM_386;
   case Triple::x86_64:
     return EM_X86_64;
+  case Triple::avr:
+    return EM_AVR;
   default:
     fatal(Path + ": could not infer e_machine from bitcode target triple " +
           T.str());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32991.98585.patch
Type: text/x-patch
Size: 2254 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170511/58f8a241/attachment.bin>


More information about the llvm-commits mailing list