How do I force gcc to call memcpy under -Os
12:08 24 May 2024

Under -Os, gcc likes to inline memcpy into rep movsb (x86-64). How can I make it actually call memcpy while keeping the -Os compiler option?

Is there anything more local than -fno-builtin-memcpy that makes it do that? I would prefer something I could do from inside a C file and something which generates a direct call (calling memcpy through a volatile pointer also succeeds in preventing inlining, but it does not generate a direct call).

https://godbolt.org/z/EjYbPaGzf

c gcc x86-64 compiler-optimization built-in