Subject: bug#47800: [native-comp] could not resolve realpath of "emacs"

From: Eli Zaretskii <[email-masked]>
Date: Thu, 15 Apr 2021 18:08:01 +0300

> From: Dario Gjorgjevski <[email-masked]>
> Date: Thu, 15 Apr 2021 16:26:43 +0200
> Cc: [email-masked]
> 
> > Hi Dario.  See also:
> >
> > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=44128
> 
> Thanks Phil.  What Eli wrote in message#28 there describes the issue
> very well.

Does the untested patch below fix the problem?

diff --git a/src/emacs.c b/src/emacs.c
index a256564..7eaaa28 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -846,7 +846,11 @@ load_pdump_find_executable (char const *argv0, ptrdiff_t *candidate_size)
       struct stat st;
       if (file_access_p (candidate, X_OK)
 	  && stat (candidate, &st) == 0 && S_ISREG (st.st_mode))
-	return candidate;
+	{
+	  if (lstat (candidate, &st) == 0 && S_ISLNK (st.st_mode))
+	    return realpath (candidate, NULL);
+	  return candidate;
+	}
       *candidate = '\0';
     }
   while (*path++ != '\0');