I have the following C code:
char* ptr1;
char* ptr2;
memcpy(ptr1,ptr2,32);
This is code I didn't write, but inherited and I'm trying to make it run on ARM bare-metal rather than Linux (works fine on Linux).
I'm wondering what the implementation of memcpy is? Is there a way to get GCC to include its code (I assume it's all userspace code) with the resulting binary (static link)? Right now, if I compile (even using -static) I see the following disassembly:
memcpy (ptr1, ptr2, 32);
800e37fc: d0000a14 adrp x20, 80225000 <mode_wider_mode+0x20>
800e3800: 9113c294 add x20, x20, #0x4f0
800e3804: aa1403e0 mov x0, x20
800e3808: d2800802 mov x2, #0x40 // #64
800e380c: 90000ae1 adrp x1, 8023f000 <reg_class_subclasses+0xa0>
800e3810: 91138021 add x1, x1, #0x4e0
800e3814: 9402ee4f bl 8019f150 <__dl_iterate_phdr+0x158>
Which jumps to the dl_iterate_phdr table (looks up pointer in shared library I believe?).
Which seems to indicate memcpy is still dynamically linked. Obviously the above ASM code wouldn't work in a bare-metal system.
I could implement my own memcpy but I was wondering if (on Linux host) I could just get the code for it to be included in my binary. After all it's probably just iterating a loop right?