1

I am modifying the malloc.c and hooks.c file in glibc library and my modification uses shm_open().

Now to build glibc, the Man page of shm_open() says that I need to link with -lrt.

The problem that I am facing is, as far as I know, librt is produced during the build process of glibc. How can I modify the makefile(s) to build glibc and also link librt?

Or is there any other way to achieve this?

dodobhoot
  • 493
  • 6
  • 15

1 Answers1

1

Please check if you have to recompile glibc at all. Usually, this is not necessary for replacing malloc. You can interposed glibc's malloc implementation from a DSO if you implement a certain set of functions:

This mechanism relies on ELF symbol interposition (perhaps via LD_PRELOAD).

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • I can't recompile all my applications to reflect the changes made in malloc modification. Can you suggest any other method? – dodobhoot Feb 12 '18 at 06:15
  • You can use `LD_PRELOAD` to injection your own `malloc`. – Florian Weimer Feb 12 '18 at 11:06
  • The command to run the applications will change in this case as I need to load my library prior running the application and unfortunately I can't do that as well. Is there any way to achieve this without doing any changes in the compilation or execution of applications. – dodobhoot Feb 13 '18 at 06:04