* Can I use printf in dl-load.c?
@ 2021-01-14 7:04 Yihan Dang
2021-01-14 8:19 ` Florian Weimer
0 siblings, 1 reply; 4+ messages in thread
From: Yihan Dang @ 2021-01-14 7:04 UTC (permalink / raw)
To: libc-help
Hello,
I'm trying to use printf to get maplength in dl-load.c:_dl_map_object_from_fd, and this is how the code looks like:
/* add stdio at the very beginning */
#include <stdio.h>
......
/* Length of the sections to be loaded. */
maplength = loadcmds[nloadcmds - 1].allocend - loadcmds[0].mapstart;
/* code added */
printf("The maplength of shared library %s is %ld\n", name, maplength);
/* Now process the load commands and map segments into memory.
This is responsible for filling in:
l_map_start, l_map_end, l_addr, l_contiguous, l_text_end, l_phdr
*/
errstring = _dl_map_segments (l, fd, header, type, loadcmds, nloadcmds,
maplength, has_holes, loader);
And this is the error message I got:
gcc -nostdlib -nostartfiles -r -o /home/dyh/expr/glibc/build/elf/librtld.map.o -Wl,--defsym='__stack_chk_fail=0' -Wl,--defsym='__stack_chk_fail_local=0' \
'-Wl,-(' /home/dyh/expr/glibc/build/elf/dl-allobjs.os /home/dyh/expr/glibc/build/libc_pic.a -lgcc '-Wl,-)' -Wl,-Map,/home/dyh/expr/glibc/build/elf/librtld.mapT
/home/dyh/expr/glibc/build/libc_pic.a(dl-error.os): In function `__GI__dl_signal_exception':
/home/dyh/expr/glibc/elf/dl-error-skeleton.c:91: multiple definition of `_dl_signal_exception'
/home/dyh/expr/glibc/build/elf/dl-allobjs.os:/home/dyh/expr/glibc/elf/dl-error-skeleton.c:91: first defined here
/home/dyh/expr/glibc/build/libc_pic.a(dl-error.os): In function `__GI__dl_signal_error':
/home/dyh/expr/glibc/elf/dl-error-skeleton.c:109: multiple definition of `_dl_signal_error'
/home/dyh/expr/glibc/build/elf/dl-allobjs.os:/home/dyh/expr/glibc/elf/dl-error-skeleton.c:109: first defined here
/home/dyh/expr/glibc/build/libc_pic.a(dl-error.os): In function `__GI__dl_catch_exception':
/home/dyh/expr/glibc/elf/dl-error-skeleton.c:175: multiple definition of `_dl_catch_exception'
/home/dyh/expr/glibc/build/elf/dl-allobjs.os:/home/dyh/expr/glibc/elf/dl-error-skeleton.c:175: first defined here
/home/dyh/expr/glibc/build/libc_pic.a(dl-error.os): In function `__GI__dl_catch_error':
/home/dyh/expr/glibc/elf/dl-error-skeleton.c:213: multiple definition of `_dl_catch_error'
/home/dyh/expr/glibc/build/elf/dl-allobjs.os:/home/dyh/expr/glibc/elf/dl-error-skeleton.c:213: first defined here
/home/dyh/expr/glibc/build/libc_pic.a(init-first.os):(.data+0x0): multiple definition of `__libc_multiple_libcs'
/home/dyh/expr/glibc/build/elf/dl-allobjs.os:(.bss+0xe0): first defined here
collect2: error: ld returned 1 exit status
Makefile:437: recipe for target '/home/dyh/expr/glibc/build/elf/librtld.map' failed
make[2]: *** [/home/dyh/expr/glibc/build/elf/librtld.map] Error 1
make[2]: Leaving directory '/home/dyh/expr/glibc/elf'
Makefile:215: recipe for target 'elf/subdir_lib' failed
make[1]: *** [elf/subdir_lib] Error 2
make[1]: Leaving directory '/home/dyh/expr/glibc'
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 2
I had a hard time understanding the messages. Why strcmp in <string.h> can be used in this file, but printf in <stdio.h> can't?
I know that I can use readelf to calculate the virtual space a shared library takes up, but I'm really confused about this error.
Thanks in advance,
Yihan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can I use printf in dl-load.c?
2021-01-14 7:04 Can I use printf in dl-load.c? Yihan Dang
@ 2021-01-14 8:19 ` Florian Weimer
2021-01-14 8:31 ` Yihan Dang
0 siblings, 1 reply; 4+ messages in thread
From: Florian Weimer @ 2021-01-14 8:19 UTC (permalink / raw)
To: Yihan Dang via Libc-help; +Cc: Yihan Dang
* Yihan Dang via Libc-help:
> I'm trying to use printf to get maplength in
> dl-load.c:_dl_map_object_from_fd, and this is how the code looks like:
You need to use _dl_printf. Please note that it does not support all
formatting directives.
Thanks,
Florian
--
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can I use printf in dl-load.c?
2021-01-14 8:19 ` Florian Weimer
@ 2021-01-14 8:31 ` Yihan Dang
2021-01-14 9:08 ` Florian Weimer
0 siblings, 1 reply; 4+ messages in thread
From: Yihan Dang @ 2021-01-14 8:31 UTC (permalink / raw)
To: Florian Weimer; +Cc: libc-help
Hi Florian,
Thank you very much for your reply!
I've checked ldsodefs.h and found _dl_printf there. I guess using functions in stdio.h may cause some problems so there is a seperate printf here.
Also, I did not find any function related to scanf in ldsodefs.h, does that mean there is no way to achieve the similar functionality?
Thank you in advance,
Yihan
---Original---
From: "Florian Weimer"<fweimer@redhat.com>
Date: Thu, Jan 14, 2021 16:19 PM
To: "Yihan Dang via Libc-help"<libc-help@sourceware.org>;
Cc: "Yihan Dang"<qcloud1223@qq.com>;
Subject: Re: Can I use printf in dl-load.c?
* Yihan Dang via Libc-help:
> I'm trying to use printf to get maplength in
> dl-load.c:_dl_map_object_from_fd, and this is how the code looks like:
You need to use _dl_printf. Please note that it does not support all
formatting directives.
Thanks,
Florian
--
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can I use printf in dl-load.c?
2021-01-14 8:31 ` Yihan Dang
@ 2021-01-14 9:08 ` Florian Weimer
0 siblings, 0 replies; 4+ messages in thread
From: Florian Weimer @ 2021-01-14 9:08 UTC (permalink / raw)
To: Yihan Dang; +Cc: libc-help
* Yihan Dang:
> Also, I did not find any function related to scanf in ldsodefs.h, does
> that mean there is no way to achieve the similar functionality?
Yes, there is no scanf in ld.so. Perhaps you can use _dl_strtoul
instead.
Thanks,
Florian
--
Red Hat GmbH, https://de.redhat.com/ , Registered seat: Grasbrunn,
Commercial register: Amtsgericht Muenchen, HRB 153243,
Managing Directors: Charles Cachera, Brian Klemm, Laurie Krebs, Michael O'Neill
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-01-14 9:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 7:04 Can I use printf in dl-load.c? Yihan Dang
2021-01-14 8:19 ` Florian Weimer
2021-01-14 8:31 ` Yihan Dang
2021-01-14 9:08 ` 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).