0

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.

  • Why the downvote? – Zach Boyd Jan 23 at 19:16
  • It's probably because you don't give an example; a possible cause could be a mismatch between a program and the dynamic libraries it's using, maybe caused by some clever fix like creating a link from libfoo.so.4 to libfoo.so.3 to get the foo program requiring libfoo.so.4 to run. – mosvy Jan 24 at 2:24
  • Thanks. Not including a specific example was kind of the point of the question, but I know there are lots of people at SE to love to hate on more general questions. – Zach Boyd Jan 24 at 14:41
1

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 (with MAP_FIXED).

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

  • Thank you very much for the explanation. I will spend some time looking through the links. I have never been through glibc source code or anything that low level, so it will be an adventure. It sounds like the eventual answer is that something must be stopping the mmap operation that is required for dynamic linking. Would it be possible to add a bit about what entities control whether mmap-ing is possible? (Assuming it is not already answered in the links.) This seems like the purview of the file system/operating system/SELinux, etc.? Presumably what address is mapped to is in the links. – Zach Boyd Jan 24 at 14:49
  • 1
    First of all, _dl_map_segments() is calling mmap with MAP_FIXED which directs it to return an error if the pages could not me mapped at the address required (because something is already mapped at that address). But there are a thousand other ways that mmap could fail -- people usually use a debugger like gdb or strace in cases like this instead of trying to do dry deductions from the source code or documentation. – mosvy Jan 24 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.