0

I'm using memcpy on my ARM platform and I want to view the sourecode of memcpy. Viewing an objectdump from my sourcecode, I know this memcpy is used:

/usr/lib/gcc/arm-none-eabi/6.3.1/../../../arm-none-eabi/lib/thumb/v7e-m/libc.a(lib_a-memcpy.o)

How can I look at the .c source code of memcpy?

kilaz101
  • 11
  • 1
  • 1
    look at the sourcecode for libc if you are using libc or newlib if newlib, or if it is from gcclib then from gcc, etc.. dont be surprised if you find it is written in assembly. – old_timer Sep 06 '18 at 19:13
  • you can also just disassemble it. – old_timer Sep 06 '18 at 19:13
  • I am using arm gcc compile. Is there a sourcecode for libc for arm gcc, or is there only one sourcecode for libc working on multiple platforms? – kilaz101 Sep 06 '18 at 19:19
  • there is a c library that comes with the gcc sources, but that is not the only c library in the world and certainly not the only memcpy. – old_timer Sep 06 '18 at 21:03

1 Answers1

0

On some compilers (with some optimization flags), memcpy would use some __builtin_memcpy which is magically handled by the compiler (and could even not emit any function call, but always be inlined and specialized).

See this related question and the documentation of GCC builtins. Ultimately, dive into the source code of your GCC compiler.

Look also into the source code of your libc. It probably mentions __builtin_mempcy in some internal header.

Of course, use gcc -S -fverbose-asm -O and see the generated assembler file *.s

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547