public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Is writing a dynamic linker/loader to load glibc a bad idea?
@ 2021-01-05  3:25 Fengkai Sun
  2021-01-05  9:58 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: Fengkai Sun @ 2021-01-05  3:25 UTC (permalink / raw)
  To: libc-help

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

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

end of thread, other threads:[~2021-01-05  9:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05  3:25 Is writing a dynamic linker/loader to load glibc a bad idea? Fengkai Sun
2021-01-05  9:58 ` 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).