public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Add a new function to dlfcn.h?
@ 2020-08-16 12:52 Y.D.
  2020-08-16 12:59 ` Florian Weimer
  0 siblings, 1 reply; 4+ messages in thread
From: Y.D. @ 2020-08-16 12:52 UTC (permalink / raw)
  To: libc-help

Hi all,
I'm trying to add a new function to glibc-2.32, and I'm working on getting
the memory size allocated to a shared object.
To achieve this, I want to use the private fields(l_map_start and
l_map_end) in struct link_map, which is said to be internal to dynamic
linker, so I want to add a function to dlfcn.h, just like dlopen() and
dlclose().

The question is, when I want to imitate the way dlopen works, I find that
the dlopen first calls functions in dlfcn/dlopen.c, and then functions in
elf/dl-open.c, which makes me very confused.
If I want to add a new function in dlfcn.h, what should I do? Do I have to
write a new file under dlfcn/ called dlusage.c, and another called
dl-usage.c under elf/? If this is the case, how should I modify the
Makefile in both directories?
Or can I just append one function in a few existing c files and headers?

Any help will be highly appreciated.

Best,
Fengkai

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Add a new function to dlfcn.h?
  2020-08-16 12:52 Add a new function to dlfcn.h? Y.D.
@ 2020-08-16 12:59 ` Florian Weimer
  2020-08-17  2:15   ` Y.D.
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2020-08-16 12:59 UTC (permalink / raw)
  To: Y.D. via Libc-help

* Y. D. via Libc-help:

> The question is, when I want to imitate the way dlopen works, I find that
> the dlopen first calls functions in dlfcn/dlopen.c, and then functions in
> elf/dl-open.c, which makes me very confused.
> If I want to add a new function in dlfcn.h, what should I do?

New dynamic linker functions should probably go into libc.so.6, and
implemented under elf/.

There is not much value in maintaining a separate libdl (but it's less
problematic than libpthread).  I expect that libdl will eventually go
away.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Add a new function to dlfcn.h?
  2020-08-16 12:59 ` Florian Weimer
@ 2020-08-17  2:15   ` Y.D.
  2020-08-25 12:46     ` Florian Weimer
  0 siblings, 1 reply; 4+ messages in thread
From: Y.D. @ 2020-08-17  2:15 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-help

Hi Florian,
Thanks for your quick reply!

Now I've created a new file called dl-usage.c under elf/. And I've added
dl-usage to routines in Makefile under elf/, just in case, I've added it to
dl-routines, too.
But when I create a new file, including dlfcn.h and refer to the function,
the error message is "undefined reference to `dlusage'  collect2: error: ld
returned 1 exit status".

I can make sure that:
I've declared the function in dlfcn/dlfcn.h and implemented it in
elf/dl-usage.c
There are dl-usage.o, dl-usage.os files under build/elf
I use the modified version of dynamic library by "-Wl, -rpath=" command

Can you tell me where the problem is?

Sorry I didn't cc the list last time.

Fengkai

Florian Weimer <fw@deneb.enyo.de> 于2020年8月16日周日 下午8:59写道:

> * Y. D. via Libc-help:
>
> > The question is, when I want to imitate the way dlopen works, I find that
> > the dlopen first calls functions in dlfcn/dlopen.c, and then functions in
> > elf/dl-open.c, which makes me very confused.
> > If I want to add a new function in dlfcn.h, what should I do?
>
> New dynamic linker functions should probably go into libc.so.6, and
> implemented under elf/.
>
> There is not much value in maintaining a separate libdl (but it's less
> problematic than libpthread).  I expect that libdl will eventually go
> away.
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Add a new function to dlfcn.h?
  2020-08-17  2:15   ` Y.D.
@ 2020-08-25 12:46     ` Florian Weimer
  0 siblings, 0 replies; 4+ messages in thread
From: Florian Weimer @ 2020-08-25 12:46 UTC (permalink / raw)
  To: Y.D. via Libc-help

* Y. D. via Libc-help:

> Now I've created a new file called dl-usage.c under elf/. And I've added
> dl-usage to routines in Makefile under elf/, just in case, I've added it to
> dl-routines, too.

One of my in-flight patches already uses elf/dl-usage.c, so you might
want to use something else:

  <https://sourceware.org/pipermail/libc-alpha/2020-June/115258.html>

> But when I create a new file, including dlfcn.h and refer to the function,
> the error message is "undefined reference to `dlusage'  collect2: error: ld
> returned 1 exit status".

You need to add it to elf/Versions under a new GLIBC_2.33 section,
otherwise the linker will treat it as a hidden symbol.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-08-25 12:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-16 12:52 Add a new function to dlfcn.h? Y.D.
2020-08-16 12:59 ` Florian Weimer
2020-08-17  2:15   ` Y.D.
2020-08-25 12:46     ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).