This seems strange to me as I don't get this issue. Could this be related to a newer version of Apple cctools/Xcode?, could you give an example of what you attempt to run and get an issue with not finding ntdll.so?


The following make sense to keep for general usage on macOS, this would save the macOS specific step of fixing the libraries install_name.

diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c
index 426336e4536..0a72e6fbe49 100644
--- a/tools/winegcc/winegcc.c
+++ b/tools/winegcc/winegcc.c
@@ -492,6 +492,11 @@ static strarray *get_link_args( struct options *opts, const char *output_name )
             strarray_add( flags, opts->image_base );
         }
         if (opts->strip) strarray_add( flags, "-Wl,-x" );
+        if (opts->unix_lib)
+        {
+            strarray_add( flags, "-install_name" );
+            strarray_add( flags, strmake( "@rpath/%s.so", output_name ) );
+        }
         strarray_addall( link_args, flags );
         return link_args;

For the injecting LDFLAGS it would be better to add for example UNIX_LDFLAGS so any specific linker flags can be passed only for the unix libraries.

On Fri, Aug 20, 2021 at 8:23 AM Huw Davies <huw@codeweavers.com> wrote:
On macOS unixlibs that link to ntdll.so currently fail to load.
It appears the macOS loader needs to be able to locate the file
even if the library is already loaded.

This patch changes the LC_ID_DYLIB name of ntdll.so to
"@rpath/ntdll.so" so that when other unixlibs link against this they
will insert that name into their LC_LOAD_DYLIB entry for ntdll.so.

The patch also adds LC_RPATH entries for both @loader_path/ (running
from installed tree) and @loader_path/../ntdll/ (running from build
tree).

Although it's only required to explicitly change ntdll.so's
LC_ID_DYLIB and to only add LC_RPATHs to unixlibs that load ntdll.so,
it seems simpler to do the same for all unixlibs, which is what this
patch does.

Signed-off-by: Huw Davies <huw@codeweavers.com>
---
I'm not exactly happy with this patch, so any other ideas would be appreciated.
 tools/winegcc/winegcc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/winegcc/winegcc.c b/tools/winegcc/winegcc.c
index 426336e4536..0a72e6fbe49 100644
--- a/tools/winegcc/winegcc.c
+++ b/tools/winegcc/winegcc.c
@@ -492,6 +492,13 @@ static strarray *get_link_args( struct options *opts, const char *output_name )
             strarray_add( flags, opts->image_base );
         }
         if (opts->strip) strarray_add( flags, "-Wl,-x" );
+        if (opts->unix_lib)
+        {
+            strarray_add( flags, "-install_name" );
+            strarray_add( flags, strmake( "@rpath/%s.so", output_name ) );
+            strarray_add( flags, "-Wl,-rpath,@loader_path/" );
+            strarray_add( flags, "-Wl,-rpath,@loader_path/../ntdll/" );
+        }
         strarray_addall( link_args, flags );
         return link_args;

--
2.23.0