public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* 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 */
&nbsp; &nbsp; #include <stdio.h&gt;
&nbsp; &nbsp; ......
&nbsp; &nbsp; /* Length of the sections to be loaded.&nbsp; */
&nbsp; &nbsp; maplength = loadcmds[nloadcmds - 1].allocend - loadcmds[0].mapstart;


&nbsp; &nbsp; /* code added */
&nbsp; &nbsp; printf("The maplength of shared library %s is %ld\n", name, maplength);


&nbsp; &nbsp; /* Now process the load commands and map segments into memory.
&nbsp; &nbsp; &nbsp; &nbsp;This is responsible for filling in:
&nbsp; &nbsp; &nbsp; &nbsp;l_map_start, l_map_end, l_addr, l_contiguous, l_text_end, l_phdr
&nbsp; &nbsp; &nbsp;*/

&nbsp; &nbsp; errstring = _dl_map_segments (l, fd, header, type, loadcmds, nloadcmds,
				&nbsp; maplength, has_holes, loader);



And this is the error message I got:
gcc&nbsp; &nbsp;-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&gt; can be used in this file, but printf in <stdio.h&gt; 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

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).