From 3fd6a05fff421db269e762bf6b989cd3f9623869 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Fri, 23 Dec 2022 19:48:39 +0100 Subject: [PATCH] Fix multiple rpath tccmacho If multiple rpaths are specified then output multiple LC_RPATH load commands instead of one with : seperator. --- tccmacho.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tccmacho.c b/tccmacho.c index 4f6d2a6c..1b730b0a 100644 --- a/tccmacho.c +++ b/tccmacho.c @@ -1771,11 +1771,19 @@ static void collect_sections(TCCState *s1, struct macho *mo, const char *filenam } if (s1->rpath) { - i = (sizeof(*rpath) + strlen(s1->rpath) + 1 + 7) &-8; - rpath = add_lc(mo, LC_RPATH, i); - rpath->path = sizeof(*rpath); - str = (char*)rpath + rpath->path; - strcpy(str, s1->rpath); + char *path = s1->rpath, *end; + do { + end = strchr(path, ':'); + if (!end) + end = strchr(path, 0); + i = (sizeof(*rpath) + (end - path) + 1 + 7) &-8; + rpath = add_lc(mo, LC_RPATH, i); + rpath->path = sizeof(*rpath); + str = (char*)rpath + rpath->path; + memcpy(str, path, end - path); + str[end - path] = 0; + path = end + 1; + } while (*end); } fileofs = 4096; /* leave space for mach-o headers */