From owner-svn-src-head@freebsd.org Thu Nov 14 15:10:01 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CA2251AA963; Thu, 14 Nov 2019 15:10:01 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47DPzY4hXnz4TNW; Thu, 14 Nov 2019 15:10:01 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 85C9E21CD; Thu, 14 Nov 2019 15:10:01 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xAEFA1hN002153; Thu, 14 Nov 2019 15:10:01 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xAEFA1xS002152; Thu, 14 Nov 2019 15:10:01 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201911141510.xAEFA1xS002152@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Thu, 14 Nov 2019 15:10:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354707 - head/contrib/llvm/lib/Support/Unix X-SVN-Group: head X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: head/contrib/llvm/lib/Support/Unix X-SVN-Commit-Revision: 354707 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Nov 2019 15:10:01 -0000 Author: emaste Date: Thu Nov 14 15:10:01 2019 New Revision: 354707 URL: https://svnweb.freebsd.org/changeset/base/354707 Log: llvm: use elf_aux_info to get executable's path, if available Obtained from: LLVM a0a38b81ea MFC with: r354692 Sponsored by: The FreeBSD Foundation Modified: head/contrib/llvm/lib/Support/Unix/Path.inc Modified: head/contrib/llvm/lib/Support/Unix/Path.inc ============================================================================== --- head/contrib/llvm/lib/Support/Unix/Path.inc Thu Nov 14 12:14:55 2019 (r354706) +++ head/contrib/llvm/lib/Support/Unix/Path.inc Thu Nov 14 15:10:01 2019 (r354707) @@ -39,8 +39,13 @@ #include #include #elif defined(__FreeBSD__) +#include +#if __FreeBSD_version >= 1300057 +#include +#else #include extern char **environ; +#endif #elif defined(__DragonFly__) #include #endif @@ -192,10 +197,17 @@ std::string getMainExecutable(const char *argv0, void // sysctl may not return the desired path if there are multiple hardlinks // to the file. char exe_path[PATH_MAX]; +#if __FreeBSD_version >= 1300057 + if (elf_aux_info(AT_EXECPATH, exe_path, sizeof(exe_path)) == 0) + return exe_path; +#else + // elf_aux_info(AT_EXECPATH, ... is not available on older FreeBSD. Fall + // back to finding the ELF auxiliary vectors after the processes's + // environment. char **p = ::environ; while (*p++ != 0) ; - // ELF auxiliary vectors immediately follow the process's environment. + // Iterate through auxiliary vectors for AT_EXECPATH. for (;;) { switch (*(uintptr_t *)p++) { case AT_EXECPATH: @@ -205,6 +217,7 @@ std::string getMainExecutable(const char *argv0, void } p++; } +#endif // Fall back to argv[0] if auxiliary vectors are not available. if (getprogpath(exe_path, argv0) != NULL) return exe_path;