Re: Linux 2.5.60

Werner Almesberger (wa@almesberger.net)
Thu, 13 Feb 2003 20:25:58 -0300


Jeff Dike wrote:
>> Or it can use the linker to play games with symbol names to move the
>> kernel off into it's own separate name space.
>
> Maybe, I'm not expert enough with the linker to do that.

The basic trick is that -Wl,--wrap,foo renames the symbol "foo"
to "__real_foo", and resolves any reference to "foo" to "__wrap_foo".
So you can write wrappers that look like this:

whatever __wrap_foo(...)
{
/* do stuff */
blah = __real_foo(...);
/* do more stuff */
}

While this sounds pretty cool, it comes with a few gotchas:

- doesn't work for symbols that get resolved at compile time
(static, maybe also anything in the same compilation unit)
- when doing incremental linking, you need the -Wl,--wrap there,
too
- changing the set of -Wl,--wrap options means that you have to
rebuild from a make clean afterwards (okay, not such a nightmare
anymore, thanks to ccache)

I've used this pretty extensively in umlsim. It's okay if you
really want to avoid touching the source underneath. But you
spend a lot of time tracking down the occasional symbol that is
affected by one of the gotchas above ...

- Werner

-- 
  _________________________________________________________________________
 / Werner Almesberger, Buenos Aires, Argentina         wa@almesberger.net /
/_http://www.almesberger.net/____________________________________________/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/