Build gnumake, several fixes in virtual prefix implementation

This commit is contained in:
Lubos Dolezel 2016-01-18 22:30:31 +01:00
parent f8eae91db8
commit 15e4bb5946
11 changed files with 55 additions and 20 deletions

4
.gitmodules vendored
View File

@ -57,3 +57,7 @@
path = src/external/bash path = src/external/bash
url = ../darling-bash.git url = ../darling-bash.git
branch = darling branch = darling
[submodule "src/external/gnumake"]
path = src/external/gnumake
url = ../darling-gnumake.git
branch = darling

View File

@ -111,6 +111,7 @@ add_subdirectory(csu)
add_subdirectory(external/shell_cmds) add_subdirectory(external/shell_cmds)
add_subdirectory(external/file_cmds) add_subdirectory(external/file_cmds)
add_subdirectory(external/bash) add_subdirectory(external/bash)
add_subdirectory(external/gnumake)
###################### ######################
# libc++ & libc++abi # # libc++ & libc++abi #

View File

@ -24,7 +24,7 @@ DARLING_PREFIX=$(realpath "$SCRIPTPATH/..")
SYSTEM_ROOT_NAME="system-root" SYSTEM_ROOT_NAME="system-root"
BIND_DIRECTORIES="dev etc home tmp" BIND_DIRECTORIES="dev etc home tmp"
MAKE_DIRECTORIES="Applications Volumes" MAKE_DIRECTORIES="Applications Volumes usr"
setup_prefix() { setup_prefix() {
>&2 echo "Setting up prefix at $1" >&2 echo "Setting up prefix at $1"
@ -45,6 +45,7 @@ setup_prefix() {
# TODO: install bash and coreutils # TODO: install bash and coreutils
ln -s "${SYSTEM_ROOT_NAME}${DARLING_PREFIX}/libexec/darling/bin" "bin" ln -s "${SYSTEM_ROOT_NAME}${DARLING_PREFIX}/libexec/darling/bin" "bin"
ln -s "../${SYSTEM_ROOT_NAME}${DARLING_PREFIX}/libexec/darling/usr/bin" "usr/bin"
popd >/dev/null popd >/dev/null
} }

1
src/external/gnumake vendored Submodule

@ -0,0 +1 @@
Subproject commit 4d31af3a1956b36612625101ab760a0d0fcc90ec

View File

@ -75,7 +75,7 @@ long sys_fcntl_nocancel(int fd, int cmd, long arg)
if (len >= 0) if (len >= 0)
((char*) arg)[len] = '\0'; ((char*) arg)[len] = '\0';
return len; return 0;
} }
// TODO: implement remaining commands // TODO: implement remaining commands
default: default:

View File

@ -11,9 +11,9 @@ long sys_lstat(const char* path, struct stat* stat)
struct linux_stat lstat; struct linux_stat lstat;
#ifdef __NR_lstat64 #ifdef __NR_lstat64
ret = LINUX_SYSCALL(__NR_lstat64, __prefix_translate_path(path), &lstat); ret = LINUX_SYSCALL(__NR_lstat64, __prefix_translate_path_link(path), &lstat);
#else #else
ret = LINUX_SYSCALL(__NR_lstat, __prefix_translate_path(path), &lstat); ret = LINUX_SYSCALL(__NR_lstat, __prefix_translate_path_link(path), &lstat);
#endif #endif
if (ret < 0) if (ret < 0)
@ -32,9 +32,9 @@ long sys_lstat64(const char* path, struct stat64* stat)
struct linux_stat lstat; struct linux_stat lstat;
#ifdef __NR_lstat64 #ifdef __NR_lstat64
ret = LINUX_SYSCALL(__NR_lstat64, __prefix_translate_path(path), &lstat); ret = LINUX_SYSCALL(__NR_lstat64, __prefix_translate_path_link(path), &lstat);
#else #else
ret = LINUX_SYSCALL(__NR_lstat, __prefix_translate_path(path), &lstat); ret = LINUX_SYSCALL(__NR_lstat, __prefix_translate_path_link(path), &lstat);
#endif #endif
if (ret < 0) if (ret < 0)

View File

@ -4,16 +4,17 @@
#include <asm/unistd.h> #include <asm/unistd.h>
#include <libdyld/VirtualPrefix.h> #include <libdyld/VirtualPrefix.h>
long sys_chdir(const char* path) long sys_chdir(const char* in_path)
{ {
int ret; int ret;
const char* path;
path = __prefix_translate_path(path); path = __prefix_translate_path(in_path);
ret = LINUX_SYSCALL(__NR_chdir, path); ret = LINUX_SYSCALL(__NR_chdir, path);
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);
else else
__prefix_cwd(path); __prefix_cwd(in_path);
return ret; return ret;
} }

View File

@ -9,9 +9,9 @@ long sys_lchown(const char* path, int uid, int gid)
int ret; int ret;
#ifdef __NR_chown32 #ifdef __NR_chown32
ret = LINUX_SYSCALL(__NR_lchown32, __prefix_translate_path(path), uid, gid); ret = LINUX_SYSCALL(__NR_lchown32, __prefix_translate_path_link(path), uid, gid);
#else #else
ret = LINUX_SYSCALL(__NR_lchown, __prefix_translate_path(path), uid, gid); ret = LINUX_SYSCALL(__NR_lchown, __prefix_translate_path_link(path), uid, gid);
#endif #endif
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -10,7 +10,7 @@ long sys_readlink(const char* path, char* buf, int count)
{ {
int ret; int ret;
ret = LINUX_SYSCALL(__NR_readlink, __prefix_translate_path(path), ret = LINUX_SYSCALL(__NR_readlink, __prefix_translate_path_link(path),
buf, count); buf, count);
if (ret < 0) if (ret < 0)
ret = errno_linux_to_bsd(ret); ret = errno_linux_to_bsd(ret);

View File

@ -39,7 +39,8 @@ static std::list<std::string> explode_path(const std::string& path);
static std::string join_path(const std::list<std::string>& path_components); static std::string join_path(const std::list<std::string>& path_components);
static std::list<std::string>& canonicalize_path(std::list<std::string>& path_components); static std::list<std::string>& canonicalize_path(std::list<std::string>& path_components);
static std::string resolve_path(std::list<std::string>& path_components); static std::string resolve_path(std::list<std::string>& path_components, bool symlink);
static const char* translate_path_common(const char* path, bool symlink);
void __prefix_set(const char* path) void __prefix_set(const char* path)
{ {
@ -49,6 +50,7 @@ void __prefix_set(const char* path)
getcwd(cwd, sizeof(cwd)); getcwd(cwd, sizeof(cwd));
assert(path[0] == '/'); assert(path[0] == '/');
assert(g_prefix.empty());
g_prefix = path; g_prefix = path;
g_prefixComponents.clear(); g_prefixComponents.clear();
@ -68,9 +70,9 @@ void __prefix_set(const char* path)
if (strncmp(cwd, path, strlen(path)) == 0) if (strncmp(cwd, path, strlen(path)) == 0)
{ {
g_cwd = path + strlen(path); g_cwd = cwd + strlen(path);
if (g_cwd.empty()) if (g_cwd.empty() || g_cwd[g_cwd.length()-1] != '/')
g_cwd = "/"; g_cwd += "/";
} }
else else
{ {
@ -78,6 +80,8 @@ void __prefix_set(const char* path)
g_cwd += cwd; g_cwd += cwd;
g_cwd += '/'; g_cwd += '/';
} }
// std::cout << "### Prefix initialized with cwd " << g_cwd << " from " << cwd << std::endl;
} }
const char* __prefix_get(void) const char* __prefix_get(void)
@ -88,16 +92,17 @@ const char* __prefix_get(void)
return g_prefix.c_str(); return g_prefix.c_str();
} }
const char* __prefix_translate_path(const char* path) const char* translate_path_common(const char* path, bool symlink)
{ {
static thread_local char resolved_path[1024]; static thread_local char resolved_path[1024];
std::string str; std::string str;
std::list<std::string> path_components; std::list<std::string> path_components;
std::list<std::string>::iterator root;
if (g_prefix.empty()) if (g_prefix.empty())
return path; return path;
// std::cout << "\tCWD is " << g_cwd << std::endl;
if (path[0] != '/') if (path[0] != '/')
{ {
pthread_rwlock_rdlock(&g_cwdLock); pthread_rwlock_rdlock(&g_cwdLock);
@ -105,9 +110,10 @@ const char* __prefix_translate_path(const char* path)
pthread_rwlock_unlock(&g_cwdLock); pthread_rwlock_unlock(&g_cwdLock);
} }
str += path; str += path;
// std::cout << "*** Before explode: " << str << std::endl;
path_components = explode_path(str); path_components = explode_path(str);
str = resolve_path(path_components); str = resolve_path(path_components, symlink);
strncpy(resolved_path, str.c_str(), sizeof(resolved_path)-1); strncpy(resolved_path, str.c_str(), sizeof(resolved_path)-1);
resolved_path[sizeof(resolved_path)-1] = '\0'; resolved_path[sizeof(resolved_path)-1] = '\0';
@ -117,6 +123,16 @@ const char* __prefix_translate_path(const char* path)
return resolved_path; return resolved_path;
} }
const char* __prefix_translate_path(const char* path)
{
return translate_path_common(path, false);
}
const char* __prefix_translate_path_link(const char* path)
{
return translate_path_common(path, true);
}
const char* __prefix_untranslate_path(const char* path, unsigned long count) const char* __prefix_untranslate_path(const char* path, unsigned long count)
{ {
static thread_local char resolved_path[1024]; static thread_local char resolved_path[1024];
@ -156,6 +172,8 @@ const char* __prefix_untranslate_path(const char* path, unsigned long count)
resolved_path[len + sizeof(SYSTEM_ROOT)-1] = '\0'; resolved_path[len + sizeof(SYSTEM_ROOT)-1] = '\0';
} }
// std::cout << "*** UNTRANSLATE: " << path << " -> " << resolved_path << std::endl;
return resolved_path; return resolved_path;
} }
@ -184,6 +202,8 @@ void __prefix_cwd(const char* in_path)
if (g_cwd[g_cwd.length()-1] != '/') if (g_cwd[g_cwd.length()-1] != '/')
g_cwd += '/'; g_cwd += '/';
// std::cout << "\t+++ CWD In: " << in_path << "; out: " << g_cwd << std::endl;
pthread_rwlock_unlock(&g_cwdLock); pthread_rwlock_unlock(&g_cwdLock);
} }
@ -285,7 +305,7 @@ std::list<std::string>& canonicalize_path(std::list<std::string>& path_component
return path_components; return path_components;
} }
std::string resolve_path(std::list<std::string>& path_components) std::string resolve_path(std::list<std::string>& path_components, bool symlink)
{ {
std::string path, real_path; std::string path, real_path;
bool had_failure = false; bool had_failure = false;
@ -377,6 +397,9 @@ restart_process:
had_failure = true; had_failure = true;
} }
if (symlink && it == --path_components.end())
isLink = false;
// Perform symlink resolution // Perform symlink resolution
if (isLink && !is_system_root) if (isLink && !is_system_root)
{ {

View File

@ -38,6 +38,10 @@ const char* __prefix_get(void);
// Translate from path in prefix to physical path. // Translate from path in prefix to physical path.
const char* __prefix_translate_path(const char* path); const char* __prefix_translate_path(const char* path);
// Translate from path in prefix to physical path, treat the leaf node
// as a symlink.
const char* __prefix_translate_path_link(const char* path);
// Translate from physical path to path in prefix. // Translate from physical path to path in prefix.
// The path is expected to be canonical. // The path is expected to be canonical.
const char* __prefix_untranslate_path(const char* path, unsigned long count); const char* __prefix_untranslate_path(const char* path, unsigned long count);