Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

gcc option to override standard functions

345 views
Skip to first unread message

Durango2008

unread,
May 5, 2009, 10:54:18 PM5/5/09
to
Hello everyone.
I am looking for compiler option in gcc that overrides the standard library
function provided by ansi C.
For example if I create a function strcpy() in my program I would like the
program to use my strcpy function
rather than the standard one. Currently it seems to use the standard strcpy
function ignoring the one I wrote.
I know I can rename my function but that's not the point I remember there
was an option to allow this
but I cannot remember that option and looking up gcc on the man pages did
not bring back anything to my
memory.

Thanks for any help.
cheers.


Jan Seiffert

unread,
May 6, 2009, 2:28:30 PM5/6/09
to
Durango2008 wrote:
> Hello everyone.
> I am looking for compiler option in gcc that overrides the standard library
> function provided by ansi C.
> For example if I create a function strcpy() in my program I would like the
> program to use my strcpy function
> rather than the standard one. Currently it seems to use the standard strcpy
> function ignoring the one I wrote.

Hmmm.
I did this myself for some functions and i did nothing special to make it work.
At least all calls from my Program to those functions come up right. While
profiling (callgrind) i found that some calls still go to the libc version (like
if inet_ntop calls memcpy), but this is a matter of runtime linking, and AFAIK
the glibc actively tries to prevent calling other that it's on implementations.
I can live with that if not every call goes through my version.
You have to look out if the compiler exchanged your call with an inline version
of this function, gcc knows a lot of std-c string functions and places the right
rep movs & friends in place.

If you really want to "get everything" you have to play with linking
options/order and maybe go with a LD_PRELOAD thingie, but still libc internal
calls maybe out of your reach.

> I know I can rename my function but that's not the point I remember there
> was an option to allow this
> but I cannot remember that option and looking up gcc on the man pages did
> not bring back anything to my
> memory.
>

you mean something like:
-mstringop-strategy=libcall
-minline-stringops-dynamically
These are fairly new options.

You also have to look out for symbol visibility, maybe override any (command
line)setting with a explicit:
char __attribute__((visibility("default"))) strcpy(...)

And finally: Are your new functions in a DSO? Then they are probably last in the
linking order. Try to add them statically to your program, this way they are
much more "in front".

> Thanks for any help.
> cheers.
>
>

Greetings
Jan

--
Woo Hoo Woo Hoo Hoo

0 new messages