From 2801d6341cda4f52fcc362da4629c576b859fbb7 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 28 Apr 2021 11:40:39 +0200 Subject: [PATCH] makefiles: Install Unix binaries into an architecture-specific directory. Signed-off-by: Alexandre Julliard --- dlls/ntdll/unix/loader.c | 33 ++++++++++++++++++++++++++++----- loader/main.c | 18 +++++++++++++++--- tools/makedep.c | 19 +++++++++++-------- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 154ab9a5234..a575fb21b76 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -91,6 +91,18 @@ WINE_DEFAULT_DEBUG_CHANNEL(module); +#ifdef __i386__ +static const char so_dir[] = "/i386-unix"; +#elif defined(__x86_64__) +static const char so_dir[] = "/x86_64-unix"; +#elif defined(__arm__) +static const char so_dir[] = "/arm-unix"; +#elif defined(__aarch64__) +static const char so_dir[] = "/aarch64-unix"; +#else +static const char so_dir[] = ""; +#endif + void (WINAPI *pDbgUiRemoteBreakin)( void *arg ) = NULL; NTSTATUS (WINAPI *pKiRaiseUserExceptionDispatcher)(void) = NULL; void (WINAPI *pKiUserApcDispatcher)(CONTEXT*,ULONG_PTR,ULONG_PTR,ULONG_PTR,PNTAPCFUNC) = NULL; @@ -114,6 +126,7 @@ static const BOOL use_preloader = FALSE; static char *argv0; static const char *bin_dir; static const char *dll_dir; +static const char *ntdll_dir; static SIZE_T dll_path_maxlen; static int *p___wine_main_argc; static char ***p___wine_main_argv; @@ -331,11 +344,12 @@ static void init_paths( char *argv[] ) argv0 = strdup( argv[0] ); - if (!dladdr( init_paths, &info ) || !(dll_dir = realpath_dirname( info.dli_fname ))) + if (!dladdr( init_paths, &info ) || !(ntdll_dir = realpath_dirname( info.dli_fname ))) fatal_error( "cannot get path to ntdll.so\n" ); - if (!(build_dir = remove_tail( dll_dir, "/dlls/ntdll" ))) + if (!(build_dir = remove_tail( ntdll_dir, "/dlls/ntdll" ))) { + if (!(dll_dir = remove_tail( ntdll_dir, so_dir ))) dll_dir = ntdll_dir; #if (defined(__linux__) && !defined(__ANDROID__)) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) bin_dir = realpath_dirname( "/proc/self/exe" ); #elif defined (__FreeBSD__) || defined(__DragonFly__) @@ -1349,6 +1363,14 @@ static NTSTATUS find_builtin_dll( UNICODE_STRING *nt_name, void **module, SIZE_T ptr = prepend( ptr, dll_paths[i], strlen(dll_paths[i]) ); status = open_builtin_pe_file( ptr, &attr, module, size_ptr, image_info, machine, prefer_native ); /* use so dir for unix lib */ + ptr = file + pos; + ptr = prepend( ptr, so_dir, strlen(so_dir) ); + ptr = prepend( ptr, dll_paths[i], strlen(dll_paths[i]) ); + if (status != STATUS_DLL_NOT_FOUND) goto done; + strcpy( file + pos + len + 1, ".so" ); + status = open_builtin_so_file( ptr, &attr, module, image_info, prefer_native ); + if (status != STATUS_DLL_NOT_FOUND) goto done; + file[pos + len + 1] = 0; ptr = prepend( file + pos, dll_paths[i], strlen(dll_paths[i]) ); if (status != STATUS_DLL_NOT_FOUND) goto done; status = open_builtin_pe_file( ptr, &attr, module, size_ptr, image_info, machine, prefer_native ); @@ -1725,12 +1747,13 @@ static void load_ntdll(void) init_unicode_string( &str, path ); InitializeObjectAttributes( &attr, &str, 0, 0, NULL ); - name = malloc( strlen( dll_dir ) + strlen( pe_dir ) + sizeof("/ntdll.dll.so") ); - sprintf( name, "%s%s/ntdll.dll", dll_dir, build_dir ? "" : pe_dir ); + name = malloc( strlen( ntdll_dir ) + strlen( pe_dir ) + sizeof("/ntdll.dll.so") ); + if (build_dir) sprintf( name, "%s/ntdll.dll", ntdll_dir ); + else sprintf( name, "%s%s/ntdll.dll", dll_dir, pe_dir ); status = open_builtin_pe_file( name, &attr, &module, &size, &info, current_machine, FALSE ); if (status == STATUS_DLL_NOT_FOUND) { - sprintf( name, "%s/ntdll.dll.so", dll_dir ); + sprintf( name, "%s/ntdll.dll.so", ntdll_dir ); status = open_builtin_so_file( name, &attr, &module, &info, FALSE ); } if (status == STATUS_IMAGE_NOT_AT_BASE) relocate_ntdll( module ); diff --git a/loader/main.c b/loader/main.c index fb40e90f977..86c2b28263e 100644 --- a/loader/main.c +++ b/loader/main.c @@ -112,6 +112,17 @@ static void *try_dlopen( const char *dir, const char *name ) static void *load_ntdll( char *argv0 ) { +#ifdef __i386__ +#define SO_DIR "i386-unix/" +#elif defined(__x86_64__) +#define SO_DIR "x86_64-unix/" +#elif defined(__arm__) +#define SO_DIR "arm-unix/" +#elif defined(__aarch64__) +#define SO_DIR "aarch64-unix/" +#else +#define SO_DIR "" +#endif const char *self = get_self_exe( argv0 ); char *path, *p; void *handle = NULL; @@ -123,7 +134,7 @@ static void *load_ntdll( char *argv0 ) handle = try_dlopen( p, "dlls/ntdll/ntdll.so" ); free( p ); } - else handle = try_dlopen( path, BIN_TO_DLLDIR "/ntdll.so" ); + else handle = try_dlopen( path, BIN_TO_DLLDIR "/" SO_DIR "ntdll.so" ); free( path ); } @@ -132,13 +143,14 @@ static void *load_ntdll( char *argv0 ) path = strdup( path ); for (p = strtok( path, ":" ); p; p = strtok( NULL, ":" )) { - handle = try_dlopen( p, "ntdll.so" ); + handle = try_dlopen( p, SO_DIR "ntdll.so" ); + if (!handle) handle = try_dlopen( p, "ntdll.so" ); if (handle) break; } free( path ); } - if (!handle && !self) handle = try_dlopen( DLLDIR, "ntdll.so" ); + if (!handle && !self) handle = try_dlopen( DLLDIR, SO_DIR "ntdll.so" ); return handle; } diff --git a/tools/makedep.c b/tools/makedep.c index 0092f22b3b0..638af2b6a44 100644 --- a/tools/makedep.c +++ b/tools/makedep.c @@ -159,6 +159,7 @@ static const char *dll_ext; static const char *man_ext; static const char *arch; static const char *pe_dir; +static const char *so_dir; static const char *crosstarget; static const char *crossdebug; static const char *fontforge; @@ -2613,7 +2614,7 @@ static int cmp_string_length( const char **a, const char **b ) static void output_uninstall_rules( struct makefile *make ) { static const char *dirs_order[] = - { "$(includedir)", "$(mandir)", "$(fontdir)", "$(datadir)", "$(dlldir)" }; + { "$(includedir)", "$(mandir)", "$(fontdir)", "$(nlsdir)", "$(datadir)", "$(dlldir)" }; struct strarray uninstall_dirs = empty_strarray; unsigned int i, j; @@ -3313,7 +3314,7 @@ static void output_module( struct makefile *make ) strarray_add( &make->all_targets, strmake( "%s%s", make->module, dll_ext )); strarray_add( &make->all_targets, strmake( "%s.fake", make->module )); add_install_rule( make, make->module, strmake( "%s%s", make->module, dll_ext ), - strmake( "p$(dlldir)/%s%s", make->module, dll_ext )); + strmake( "p%s/%s%s", so_dir, make->module, dll_ext )); add_install_rule( make, make->module, strmake( "%s.fake", make->module ), strmake( "d%s/%s", pe_dir, make->module )); output( "%s%s %s.fake:", module_path, dll_ext, module_path ); @@ -3368,7 +3369,7 @@ static void output_module( struct makefile *make ) strarray_addall( &unix_libs, add_unix_libraries( make, &unix_deps )); strarray_add( &make->all_targets, unix_lib ); - add_install_rule( make, make->module, unix_lib, strmake( "p$(dlldir)/%s", unix_lib )); + add_install_rule( make, make->module, unix_lib, strmake( "p%s/%s", so_dir, unix_lib )); output( "%s:", obj_dir_path( make, unix_lib )); if (spec_file) output_filename( spec_file ); output_filenames_obj_dir( make, make->unixobj_files ); @@ -3402,7 +3403,7 @@ static void output_module( struct makefile *make ) output( "\n" ); add_install_rule( make, make->importlib, strmake( "lib%s.def", make->importlib ), - strmake( "d$(dlldir)/lib%s.def", make->importlib )); + strmake( "d%s/lib%s.def", so_dir, make->importlib )); } else { @@ -3424,7 +3425,7 @@ static void output_module( struct makefile *make ) output( "\n" ); add_install_rule( make, make->importlib, strmake( "lib%s.a", make->importlib ), - strmake( "d$(dlldir)/lib%s.a", make->importlib )); + strmake( "d%s/lib%s.a", so_dir, make->importlib )); } if (crosstarget) { @@ -3478,8 +3479,7 @@ static void output_static_lib( struct makefile *make ) output_filenames_obj_dir( make, make->object_files ); output_filenames_obj_dir( make, make->unixobj_files ); output( " && %s $@\n", ranlib ); - add_install_rule( make, make->staticlib, make->staticlib, - strmake( "d$(dlldir)/%s", make->staticlib )); + add_install_rule( make, make->staticlib, make->staticlib, strmake( "d%s/%s", so_dir, make->staticlib )); if (crosstarget && make->module) { char *name = replace_extension( make->staticlib, ".a", ".cross.a" ); @@ -4428,9 +4428,12 @@ int main( int argc, char *argv[] ) if (!tools_ext) tools_ext = ""; if (!man_ext) man_ext = "3w"; if (arch) + { + so_dir = strmake( "$(dlldir)/%s-unix", arch ); pe_dir = strmake( "$(dlldir)/%s-windows", arch ); + } else - pe_dir = "$(dlldir)"; + so_dir = pe_dir = "$(dlldir)"; top_makefile->src_dir = root_src_dir; subdirs = get_expanded_make_var_array( top_makefile, "SUBDIRS" );