如何向 glibc makefile 添加新的源文件?

How to add new source files to the glibc makefile?

最近有兴趣学习C的堆管理(malloc模块)。我想将 malloc 源文件(例如,malloc.c、arena.c)分解成更小的文件,以便于我阅读和学习。我正在使用 glibc 2.23 并按照 wiki 上的说明在 Ubuntu 14.04 上成功地在本地(在单独的 "build" 文件夹中)构建了它。

作为我最初的尝试,我将 __malloc_assert 放入文件 massert.hmassert.c 但后来意识到 我不知道如何将它们添加到makefile 以便它们可以被编译和 linked.

自从我将 __malloc_assert 移出 malloc.c 后,我在再次 运行 make 时遇到了 link 错误,这是预期的:

/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

我想我应该看看 malloc/malloc.c 在 makefile 中是如何使用的,但我找不到它的使用位置。我主要查看以下文件:

或者,我在 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?" 上搜索了 makefile,正在谈论向库中添加一个新函数,这不是我的情况(我不是在添加新函数,而只是重构代码)。

我是 makefile 系统的新手,仍在阅读 GNU makefile 手册,但认为在这里发送电子邮件可能会让我更快地摆脱困境。

谢谢!

您需要将 massert(不是 massert.c)添加到 malloc/Makefile 中的 routines 变量。

有几个这样的变量:routines是为了libc它自己,但也有libm-routines是为了libm,等等。

默认情况下,这些源文件是为所有变体构建的:静态(.o)、共享(.os)、分析(.op,但默认情况下禁用分析构建).一些特殊函数仅用于静态构建(.oS,它们进入 libc_nonshared.a)并且也在 static-only-routines 中列出。可以使用 elide-routines.os 变量排除特定的构建目标。