Description of problem: if ldd fails for any reason including limited memory, the error message printed is "not a dynamic executable" which is not necessarily the real problem Version-Release number of selected component (if applicable): 6.4 but appears to be all How reproducible: always with the right setup Steps to Reproduce: severely limit memory and try to run ldd on a big executable Actual results: not a dynamic executable Expected results: it prints out that the reason it can't complete is lack of memory Additional info: ldd is just a script and the failing executable is actually ld-linux. When you look at ld-linux it is exiting with EXIT_FAILURE (1) which causes that message to be in error. in the case where it is out of memory, we might want to return something other than 1 like 3 and use that in the ldd script. 2 is already taken. the challenge seems to be reporting what the actual error is from the kernel to glibc. That is down in the __dl_catch_error code. It seems to be called when something goes wrong in the dl linking by the elf handler in the kernel. I don't see where it sets any value that could be gleaned to figure out the actual source of the error.
(In reply to Ben Woodard from comment #0) > I don't see where it sets any value that could be gleaned to figure out the > actual source of the error. We need a reduced test case that shows the problem. On glibc 2.17 or newer I see the following: [carlos@koi ~]$ ulimit -v 5000 [carlos@koi ~]$ /usr/bin/ldd /lib64/libc.so.6 /usr/bin/bash: error while loading shared libraries: libdl.so.2: failed to map segment from shared object: Cannot allocate memory Which looks exactly like what I would expect. Thus this will get fixed as our users upgrade to the next version of RHEL. To answer your technical question, glibc uses setjmp/longjmp around dlopen to handle errors and the error code returned is the error returned by the kernel and reported to the user. We are already propagating this errors for ENOMEM and passing that up via _dl_signal_error. There might be a case we missed?
Oh, hrm, I wonder if the latter failure was not in ldd, but in ld.so getting reach to run itself...
(In reply to Carlos O'Donell from comment #3) > Oh, hrm, I wonder if the latter failure was not in ldd, but in ld.so getting > reach to run itself... Either way, we need a test case.
Created attachment 884276 [details] bz1085549.diff
I like your patch, I think it will solve the problem. I was looking in the same location but got misled by the "continuable error" part in the comment preceding _dl_signal_error and didn't recognize it as the entry point which stashed away the error code. I was looking for some other "non-continuable" error that could also jump into _dl_catch_error and kind of got lost. I don't know how to make a test that would be reproducible across all possible platforms. The original bug report wasn't with ulimit: "A user on aztec3 had a process which top(1) showed to be consuming 91.8% of memory. Meanwhile another user was trying to run a simple dynamically built serial code and file(1) on the executable said: <executable>: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped but ldd(1) said in the same 10-second period: not a dynamic executable which was false information, and there was no error message such as, "Could not load the executable to review its shared objects", or some such. can we please get some [useful] error messages out of this? ---- I could probably reproduce it in virtual machine or maybe with a cgroup container but I don't know exactly how to make a very linux specific platform.
err garbled my last comment: I could probably reproduce it in virtual machine or maybe with a cgroup container but I don't know exactly how to make a general reproducer like what is in the test suite both virtual machines and containers are very specific to the RHEL platform.
(In reply to Ben Woodard from comment #7) > err garbled my last comment: > I could probably reproduce it in virtual machine or maybe with a cgroup > container but I don't know exactly how to make a general reproducer like > what is in the test suite both virtual machines and containers are very > specific to the RHEL platform. Use systemtap and inject a NULL return for mmmap. See: https://sourceware.org/glibc/wiki/Testing/WhiteBox
I've moved this to rhel-7.2. While it's possible we could have tackled this in rhel-6, I just don't see the customer demand for the change. The tricky part is that ld.so has to return new error codes, and we want to be conservative about that in rhel-6, thus the move to rhel-7.2.
Upstream commit: commit e7c8ffe4ec059da1523c093d6a240cd87d154df2 Author: Florian Weimer <fweimer> Date: Tue Oct 15 16:41:51 2019 +0200 ldd: Print "not a dynamic executable" on standard error [BZ #24150] Tested with the testsuite on x86_64-linux-gnu, and manually.
*** Bug 1817111 has been marked as a duplicate of this bug. ***
We are actively tracking this issue upstream here: Bug 25991 - ldd should print "insufficient memory" in certain cases https://sourceware.org/bugzilla/show_bug.cgi?id=25991 When we make upstream progress on the bug we can review the CLOSED/UPSTREAM bugs and reopen for backport consideration.