Optimization question

Florian Weimer fw@deneb.enyo.de
Tue Sep 27 18:32:00 GMT 2016


* Nikolaus Dunn:

> std::ostringstream however does not call my new OR delete with no
> optimization. With -O2, it calls only my delete.
>
> If I do not attempt to wrap malloc and free, I get the same
> result. std::vector calls my new and delete, ostringstream calls
> neither.
>
> The command line I used to compile it is:
> g++ -g -O2 --std=c++14 -Wl,-wrap,malloc -Wl,-wrap,free Test.c -o test.exe

“-Wl,-wrap,malloc -Wl,-wrap,free” is only effective for newly-compiled
code.  Your example probably uses some template instantiations which
are supplied by libstdc++, and these will keep calling the unwrapped
malloc/free implementations.

I don't know if there are mechanisms on mingw which are comparable to
ELF symbol interposition.



More information about the Gcc-help mailing list