What does a “failed to map segment from shared object” error mean?

Many answers to other questions help resolve an error of the form “failed to map segment from shared object,” but they usually have very specific answers that I find difficult to apply to other problems. On the other hand, I can’t find anything about this error in general.

Can anyone give a basic description of this error and (ideally) some common causes?

It would be nice to know, for example, which entity raises the error (the kernel, the process, the program?) and common reasons why (e.g. almost every library is marked readable, so why can’t I map from it?).

I am currently running Ubuntu, although I suspect this is applies to many distributions.

Answer

That message is generated by the dynamic linker (ld.so(8)) or the dynamic loading facilities (dlopen(3)).

To answer your questions directly: a) it’s not from the kernel b) it’s from a process in user mode c) it’s usually not generated by a program’s main code, but by the dynamic linker which is loading it or a dynamic library it’s using (libdl.so) and d) the fact that a segment could be read from a file doesn’t mean it could be mmaped with the right protection (eg. executable) or that it could be be mmaped at the address required (if using MAP_FIXED with a bogus address, instead of that of a known mapping which should be replaced).

If you want more detail, you’ll see that it’s defined in the glibc source code in elf/dl-load.h as DL_MAP_SEGMENTS_ERROR_MAP_SEGMENT, and could be returned by the _dl_map_segments() static function, which is itself called via _dl_map_object() => _dl_map_object_from_fd(), and _dl_map_object() is called either directly from the dynamic linker, or via its .dl_open callback ultimately called by dlopen(3).

Attribution
Source : Link , Question Author : Zach Boyd , Answer Author : mosvy

Leave a Comment