Hi Jeroen / sage-devel,

Here is a demo of how I think we should go about to override malloc(), and 
perhaps others, on OSX. As a quick background reminder, due to the two-level 
namespace on OSX it is not as easy as LD_PRELOAD'ing a shared library on 
Linux and other unices. 

On OSX, we need to specify the preloaded library at link time. The GCC 
wrapper does most of the annoying stuff. Tested on bsd.math, and a virtual 
OSX 10.6. First, obtain and install the gcc wrapper:

wget http://www.stp.dias.ie/~vbraun/Sage/gccwrapper-1.0.tar.gz
tar xzf gccwrapper-1.0.tar.gz 
cd gccwrapper-1.0
./configure --prefix=`pwd`/build
make
make install
PATH=`pwd`/build/bin:$PATH
export PATH

Then make a simple executable / dylib, an example is packaged in the "test" 
directory:

cd test
make
./local/bin/example

Note that "example" finds its library "libexample.1.dylib" in the 
./local/lib directory since the gcc wrapper set its rpath (via the 
install_name mechanism on OSX). Now build the same program with a preloaded 
libpreload.1.dylib:

make clean
make libpreload.dylib
GCCWRAP_LDFLAGS=-L.,-lpreload make 
./local/bin/example

Note that libpreload intercepts malloc and printf calls from main.c 
(example) and library.c (libexample.1.dylib)

-Volker

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to