Reputation: 2526
Recently I've got interested in learning the heap management of C (the malloc module). I want to break the malloc source files(e.g., malloc.c, arena.c) into smaller files so it's easier to read and study for me. I'm using the glibc 2.23
and have successfully built it locally (in a separate "build" folder) on Ubuntu 14.04
following the instructions on wiki.
As my initial attempt, I put the __malloc_assert
into the files massert.h
and massert.c
but then realized I have no idea how to add them to the makefiles so they can get compiled and linked.
Since I moved __malloc_assert
out of malloc.c
, I got the link errors when running make
again, which was expected:
/home/mvs/git/glibc/build/libc_pic.os: In function `detach_arena':
/home/mvs/git/glibc/malloc/arena.c:629: undefined reference to `__malloc_assert'
/home/mvs/git/glibc/build/libc_pic.os: In function `mremap_chunk':
/home/mvs/git/glibc/malloc/malloc.c:2832: undefined reference to `__malloc_assert'
/home/mvs/git/glibc/malloc/malloc.c:2813: undefined reference to `__malloc_assert'
/home/mvs/git/glibc/malloc/malloc.c:2812: undefined reference to `__malloc_assert'
/home/mvs/git/glibc/malloc/malloc.c:2830: undefined reference to `__malloc_assert'
/home/mvs/git/glibc/build/libc_pic.os:/home/mvs/git/glibc/malloc/malloc.c:2776: more undefined references to `__malloc_assert' follow
I thought I should look at how the malloc/malloc.c
is used in the makefiles, but I couldn't find where it is used. I'm mainly looking at the following files:
Alternatively, I've searched the makefile
on libc-help
mailing list and looked at all the results but didn't find one that matches what I want. Two of the threads, "glibc + add new function" and "Adding a function to glibc?", were talking about adding a new function to the library, which is not my case (I'm not adding new function but merely restructuring the code).
I'm kind of new to the makefile system and still reading the GNU makefile manual, but thought shooting an email here may get me out of the struggle more quickly.
Thanks!
Upvotes: 0
Views: 486
Reputation: 33694
You need to add massert
(not massert.c
) to the routines
variable in malloc/Makefile
.
There are several such variables: routines
is for libc
it self, but there is also libm-routines
for libm
, and so on.
By default, these source files are built for all variants: static (.o
), shared (.os
), profiling (.op
, profiling builds are disabled by default though). Some special functions are only intended for static builds (.oS
, they go into libc_nonshared.a
) and are listed in static-only-routines
as well. Specific build targets can be excluded using the elide-routines.os
variable.
Upvotes: 3