$ readelf -l /dev/null; echo $? readelf: elf_begin() failed: Invalid argument 0 This prevents error handling in shell scripts.
Experimenting with GNU readelf, I see: - rv = 1 if one or more files failed, regardless of where in the argument list it appears - files specified after a failure are still processed - specifying a non-ELF file results in failure (/dev/null, shell script, etc.) - unsure of behaviour for a malformed ELF file
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=ea444392bb5b351c930f28a02a4e68f51b25ba69 commit ea444392bb5b351c930f28a02a4e68f51b25ba69 Author: Ed Maste <emaste@FreeBSD.org> AuthorDate: 2021-04-05 01:01:28 +0000 Commit: Ed Maste <emaste@FreeBSD.org> CommitDate: 2021-04-05 01:01:28 +0000 readelf: return error in case of invalid file GNU readelf exits with an error for a number of invalid file cases. Previously ELF Tool Chain readelf always exited with 0. Now we exit 1 upon detecting an error with one or more input files, but in any case all of them are processed. This should catch common failure cases. We still do not report an error for some types of malformed ELF files, but this is consistent with GNU readelf. PR: 252727 Reviewed by: jkoshy, markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29377 contrib/elftoolchain/readelf/readelf.c | 36 +++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-)
A commit in branch stable/12 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=14b0c8e7687e0f5917b4d272bd16a6816cab3d12 commit 14b0c8e7687e0f5917b4d272bd16a6816cab3d12 Author: Ed Maste <emaste@FreeBSD.org> AuthorDate: 2021-04-05 01:01:28 +0000 Commit: Ed Maste <emaste@FreeBSD.org> CommitDate: 2021-04-13 18:44:59 +0000 readelf: return error in case of invalid file GNU readelf exits with an error for a number of invalid file cases. Previously ELF Tool Chain readelf always exited with 0. Now we exit 1 upon detecting an error with one or more input files, but in any case all of them are processed. This should catch common failure cases. We still do not report an error for some types of malformed ELF files, but this is consistent with GNU readelf. PR: 252727 Reviewed by: jkoshy, markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29377 (cherry picked from commit ea444392bb5b351c930f28a02a4e68f51b25ba69) contrib/elftoolchain/readelf/readelf.c | 36 +++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=f4c3c0189f7ddc324643c843097247f6df316ec5 commit f4c3c0189f7ddc324643c843097247f6df316ec5 Author: Ed Maste <emaste@FreeBSD.org> AuthorDate: 2021-04-23 15:37:49 +0000 Commit: Ed Maste <emaste@FreeBSD.org> CommitDate: 2021-04-23 15:37:49 +0000 readelf: return error in case of invalid file GNU readelf exits with an error for a number of invalid file cases. Previously ELF Tool Chain readelf always exited with 0. Now we exit 1 upon detecting an error with one or more input files, but in any case all of them are processed. This should catch common failure cases. We still do not report an error for some types of malformed ELF files, but this is consistent with GNU readelf. PR: 252727 Reviewed by: jkoshy, markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D29377 (cherry picked from commit ea444392bb5b351c930f28a02a4e68f51b25ba69) contrib/elftoolchain/readelf/readelf.c | 36 +++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-)