Global allocator of software compiled with `cc`

#1

Hi Folks,

I got an interesting problem that you guys could help me with.

My software use SQLite and I use bindgen to build the binding at run time and the cc create to compile SQLite into an archive library that is then linked by rustc.

Now I want to change the global allocator doing something like it is show here: https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html

It seems to work up to a point, all the rust code is indeed working with the new allocator, unfortunately, SQLite is still using its own allocator.

I know this by tracing malloc call with GDB.

It actually makes sense, the cc crate compile SQLite before that cargo even know that I am changing the allocator.

Is there a way to force the use of the global allocator also in SQLite?

(Yes, I know that I can manually change the memory allocator of SQLite, but I would rather not.)

0 Likes

#2

No, sqlite doesn’t care about GlobalAlloc at all. It uses plain’ol malloc family, as every C libraries do.

4 Likes