elf: clearer error message when ELF machine mismatches

Message ID 20220115052237.50170-1-r.xu.1@research.gla.ac.uk
State New
Series elf: clearer error message when ELF machine mismatches |


Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Cocoa Jan. 15, 2022, 5:22 a.m. UTC
  The misleading error message happens when trying to load 64-bit/32-bit
elf file but on a different machine(architecture). For example,
load an aarch64 elf file on a x86_64 host will give the error message
"No such file or directory" while the file exists.

Lastly, sorry that I am not a native English speaker, therefore,
please let me know if the error message needs to be phrased better, or
please suggest a proper one.

Many thanks.


Set the error message to "ELF file machine does not match the host"
if elf machine does not match the host. The previous code jumps
to close_and_out and set errno to ENOENT, which results in a
misleading error message, "No such file or directory", while the
file acutally exists.
 elf/dl-load.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)


diff --git a/elf/dl-load.c b/elf/dl-load.c
index 12744caf..818a15e1 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1729,7 +1729,10 @@  open_verify (const char *name, int fd,
 	  goto lose;
       if (! __glibc_likely (elf_machine_matches_host (ehdr)))
-	goto close_and_out;
+        {
+          errstring = N_("ELF file machine does not match the host");
+          goto lose;
+        }
       else if (__glibc_unlikely (ehdr->e_type != ET_DYN
 				 && ehdr->e_type != ET_EXEC))