public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: "Yihan Dang" <qcloud1223@qq.com>
To: libc-help <libc-help@sourceware.org>
Subject: Can I use printf in dl-load.c?
Date: Thu, 14 Jan 2021 15:04:25 +0800	[thread overview]
Message-ID: <tencent_0008048C8FA3778CDB0614183CC1FF04D506@qq.com> (raw)

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:


&nbsp; &nbsp; /* 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

             reply	other threads:[~2021-01-14  7:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-14  7:04 Yihan Dang [this message]
2021-01-14  8:19 ` Florian Weimer
2021-01-14  8:31   ` Yihan Dang
2021-01-14  9:08     ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_0008048C8FA3778CDB0614183CC1FF04D506@qq.com \
    --to=qcloud1223@qq.com \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).