-uint64_t RuntimeDyldMachO::decodeAddend(uint8_t *LocalAddress, unsigned NumBytes,
- uint32_t RelType) const {
- uint64_t Addend = 0;
- memcpy(&Addend, LocalAddress, NumBytes);
+int64_t RuntimeDyldMachO::memcpyAddend(const RelocationEntry &RE) const {
+ const SectionEntry &Section = Sections[RE.SectionID];
+ unsigned NumBytes = 1 << RE.Size;
+ int64_t Addend = 0;
+ uint8_t *LocalAddress = Section.Address + RE.Offset;
+ uint8_t *Dst = reinterpret_cast<uint8_t*>(&Addend);
+
+ if (IsTargetLittleEndian == sys::IsLittleEndianHost) {
+ if (!sys::IsLittleEndianHost)
+ Dst += sizeof(Addend) - NumBytes;
+ memcpy(Dst, LocalAddress, NumBytes);
+ } else {
+ Dst += NumBytes - 1;
+ for (unsigned i = 0; i < NumBytes; ++i)
+ *Dst-- = *LocalAddress++;
+ }
+