[PATCH] D32991: [ELF] Initial migration of AVR target
Leslie Zhai via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 12 02:11:39 PDT 2017
xiangzhai updated this revision to Diff 98738.
xiangzhai added a comment.
Dear George,
Thanks for your reply!
> This needs testcase.
I haven't written it under test and unittests directories, but instead use bare-bones <https://coding.net/u/xiangzhai/p/lld.coding.me/git/tree/master/tests/AVR>:
#include <math.h>
#include "Bar.h"
#include "Foo.h"
void setup() {
// put your setup code here, to run once:
bar();
foo();
double s = sin(M_PI);
}
void loop() {
// put your main code here, to run repeatedly:
}
#if __GNUC__
int main(int argc, char *argv[]) {
return 0;
}
#endif
To test the relocation R_AVR_13_PCREL (haven't been implemented yet) by avr-ld (from the AVR-GCC RPM packages available for Fedora) and NewLLD, please see the diff:
readelf -r avr-gcc-BareMinimum.o
Relocation section '.rela.text' at offset 0x1d0 contains 2 entries:
Offset Info Type Sym.Value Sym. Name + Addend
00000000 00000d03 R_AVR_13_PCREL 00000000 bar + 0
00000002 00000e03 R_AVR_13_PCREL 00000000 foo + 0
with
readelf -r clang-BareMinimum.o
Relocation section '.rela.text' at offset 0xb8 contains 2 entries:
Offset Info Type Sym.Value Sym. Name + Addend
00000000 00000212 R_AVR_CALL 00000000 bar + 0
00000004 00000312 R_AVR_CALL 00000000 foo + 0
> I doubt that I might drove in the wrong direction? it should not be simple as my illusion?
The relocation of R_AVR_32 in my patch might be wrong! so I am reading the source code of binutils <https://sourceware.org/git/?p=binutils.git;a=blob;f=bfd/elf32-avr.c;h=43100cd20fc0f48e26bdbd8c841c661f9c37c33f;hb=HEAD#l116> and also Dylan's fork <https://github.com/avr-llvm/lld/blob/avr-support/lib/ReaderWriter/ELF/AVR/AVRRelocationHandler.cpp#L51>. but I have to look after my little kid in the weekend :) miss you, see you next week.
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");
}
@@ -2411,5 +2422,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_ABS;
+}
+
+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.98738.patch
Type: text/x-patch
Size: 2253 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170512/d597f3a1/attachment.bin>
More information about the llvm-commits
mailing list