[libvirt] [PATCH 09/11] tests: Use flat namespace on macOS

Daniel P. Berrangé berrange at redhat.com
Wed Aug 21 17:08:05 UTC 2019


On Wed, Aug 21, 2019 at 07:13:21PM +0300, Roman Bolshakov wrote:
> Test executables and mocks have assumption that any symbol can be
> replaced with LD_PRELOAD. That's not a case for macOS unless flat
> namespace is used, because every external symbol reference records the
> library to be looked up. And the symbols cannot be replaced unless dyld
> interposing is used.
> 
> Setting DYLD_FORCE_FLAT_NAMESPACE changes symbol lookup behaviour to be
> similar to Linux dynamic linker. It's more lightweight solution than
> explicitly decorating all mock symbols as interpositions and building
> libvirt as interposable dynamic library.
> 
> This fixes vircryptotest and allows to proceed other tests that rely on
> mocks a little bit further.
> 
> Signed-off-by: Roman Bolshakov <r.bolshakov at yadro.com>
> ---
>  tests/testutils.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tests/testutils.h b/tests/testutils.h
> index 7660101991..b46bc86d84 100644
> --- a/tests/testutils.h
> +++ b/tests/testutils.h
> @@ -119,9 +119,12 @@ int virTestMain(int argc,
>  
>  #ifdef __APPLE__
>  # define PRELOAD_VAR "DYLD_INSERT_LIBRARIES"
> +# define FORCE_FLAT_NAMESPACE \
> +            setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", 1);

Remove the ';'

>  # define MOCK_EXT ".dylib"
>  #else
>  # define PRELOAD_VAR "LD_PRELOAD"
> +# define FORCE_FLAT_NAMESPACE

Make that  'do {} while (0)'

>  # define MOCK_EXT ".so"
>  #endif
>  
> @@ -141,6 +144,7 @@ int virTestMain(int argc,
>                  return EXIT_FAILURE; \
>              } \
>              setenv(PRELOAD_VAR, newenv, 1); \
> +            FORCE_FLAT_NAMESPACE \

so that here you can have a trailing ';'

>              execv(argv[0], argv); \
>          } \
>      } while (0)

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




More information about the libvir-list mailing list