Using Libraries within Libraries

Programming, for all ages and all languages.
Post Reply
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Using Libraries within Libraries

Post by Alboin »

I have library x. x uses functions from library y. Library x is used in program z.

y is linked to x at compile time, and likewise with program z and x.

z uses x through the dl interface.

Yet, when z uses x (leading to x calling y.), z crashes claiming: "free(): invalid next size (fast)".

Do I have to do something other than link x to y and x to z? Any knowledge as to why it's broken?

Thanks.

(I'm using Gentoo Linux, GCC 4.1.1, and LD 2.16.1)
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post by mystran »

The error message you get sounds like there's a bug somewhere. I guess it's from glibc malloc, but I can't seem to find that error message from the version I happen to have sources for, and don't feel like digging for the specific version so I'm just going to claim, based on the structure of the malloc used (derivative of dlmalloc) that there's a buffer overflow somewhere, and it detected a heap corruption.

You don't need to do anything special. If you just link a library, it'll drag all of it's own libraries with it. If you dlopen it, the same should happen, as per dlopen manpage:
If the library has dependencies on other shared libraries, then these are also automatically loaded by the dynamic linker using the same rules. (This process may occur recursively, if those libraries in turn have dependencies, and so on.)
As for the error message, there are sizes of blocks recorded before each block in dlmalloc. So when you free a block, it looks backward to see the size of the free'd block. It can also then the free'd block based on that size, and land just after that block, where it should find the size and status of the next block. It sounds like it found something that failed a sanity check..

But I could be wrong. Since you have Gentoo, you'll probably find all the relevant sources in /usr/portage/distfiles, so you could just unpack those somewhere, and grep for "invalid next size" or something like that to find where you got the error from...
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
Post Reply