0

My project links with some external libraries (including some libc) and has a lot of it's own code. I want to override memcpy with my own implementation. In case of project's code I want to always-inline my memcpy while I also want all external libraries to use my memcpy too.

If I define my function as inline void * memcpy(…) then it won't be exported as dynamic symbol, but if I skipped the inline keyword, then I can't guarantee that compiler will try to inline my function wherever possible.

What is a proper way to incline a compiler to inline my function while having it as dynamic symbol for other external libraries?

I link my project statically with -rdynamic flag to expose symbols for override in other dynamic libraries.

abyss.7
  • 13,882
  • 11
  • 56
  • 100
  • 1
    No, if you specify `inline`, but not `static`, a global symbol has to be created for this function. It just _may_ be inlined _additionally_ when it is in the same translation unit – Ctx Feb 18 '20 at 12:53
  • Does this answer your question? [Inline function linkage](https://stackoverflow.com/questions/4193639/inline-function-linkage) – Tarek Dakhran Feb 18 '20 at 12:53
  • C or C++? Choose *one*. Inline functions is one of the areas where it makes a difference. – John Bollinger Feb 18 '20 at 13:00
  • @Ctx Maybe it's crucial, but the memcpy has `extern "C"` linkage. I checked with `nm` that memcpy is exported as Undefined symbol – abyss.7 Feb 18 '20 at 13:02
  • @JohnBollinger it's defined in header (.h) which is included, compiled and linked depending on the including file. The resulting artifact is a single binary. – abyss.7 Feb 18 '20 at 13:03
  • 1
    Irrelevant, @abyss.7. You have tagged both [c] and [c++]. These are different languages with similar syntax and a shared lineage. Their rules about inline functions are different. **Choose *one***, and update the question's tags accordingly. – John Bollinger Feb 18 '20 at 13:06

0 Answers0