From: Fengkai Sun <qcloud1014@gmail.com>
To: libc-help@sourceware.org
Subject: Is writing a dynamic linker/loader to load glibc a bad idea?
Date: Tue, 5 Jan 2021 11:25:04 +0800 [thread overview]
Message-ID: <CAF6YOcO1WHNrhrmzfsHiNzRNdc7soMSUpQQd0jYXE8mLU_vH9Q@mail.gmail.com> (raw)
Hi list,
Sorry in advance if this question is a bit unclear and confusing.
Recently I want to implement an ld.so myself, that is, a DSO that allows me
to load other DSOs into memory.
I've tried my best to finish all the steps that I discovered: loading
PT_LOAD segments with mmap, loading dependencies, relocating, and calling
DT_INIT and DT_INITARRAY in the right order.
It works all right when the DSO is simple, e.g. using a few printfs and
other libc functions. But it fails when I'm using some(not all) DSOs in the
real world.
Through some debugging, I found that the problem might be caused by some
initialized variables. So I tried this when doing relocation:
IF FIND_SYMBOL_IN_LIBC:
void* handle = dlopen("libc.so.6", RTLD_LAZY);
void* symbol_address = dlsym(handle, symbol_name);
if(symbol_address)
return symbol_address;
And it works fine.
So I think the bug is obvious: I missed out some parts when trying to load
libc as a dependency. But libc is huge, I'm not sure if it is a great idea
to do that all by myself -- currently I cannot find what is overlooked.
Any intuitive advice will be greatly appreciated.
Best,
Fengkai
next reply other threads:[~2021-01-05 3:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-05 3:25 Fengkai Sun [this message]
2021-01-05 9:58 ` 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=CAF6YOcO1WHNrhrmzfsHiNzRNdc7soMSUpQQd0jYXE8mLU_vH9Q@mail.gmail.com \
--to=qcloud1014@gmail.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).