Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when loading *.so file while running test #692

Open
judimator opened this issue Nov 14, 2024 · 12 comments
Open

Error when loading *.so file while running test #692

judimator opened this issue Nov 14, 2024 · 12 comments

Comments

@judimator
Copy link

OS

x86_64 GNU/Linux

Error

FFI\Exception: Failed loading '/var/www/app/vendor/pact-foundation/pact-php/src/PhpPact/Standalone/Installer/Model/../../../../../bin/pact-ffi-lib/pact.so' (/lib/x86_64-linux-gnu/libc.so: invalid ELF header)
/var/www/app/vendor/pact-foundation/pact-php/src/PhpPact/FFI/Client.php:26
/var/www/app/vendor/pact-foundation/pact-php/src/PhpPact/Standalone/ProviderVerifier/Verifier.php:24
/var/www/app/tests/Contracts/VerificationTest.php:86
@tienvx
Copy link
Contributor

tienvx commented Nov 14, 2024

I'm not sure what is the issue behind this error. But I need more information to be able to debug. Can you run these commands and provide the output?

sha256sum bin/pact-ffi-lib/pact.so
sha256sum bin/pact-ffi-headers/pact.h
ldd /bin/sh 2>&1

@judimator
Copy link
Author

Sure, @tienvx here you are

6e727f382c7452358dbf9d3da59b8b8fa88eb285c6624240e2b6f921a2026a08 /var/www/app/vendor/pact-foundation/pact-php/bin/pact-ffi-lib/pact.so

98cc7df216bdd8a5600db0a7558c80dcfd05653123d5cefedb2af841de516a7e /var/www/app/vendor/pact-foundation/pact-php/bin/pact-ffi-headers/pact.h

linux-vdso.so.1 (0x00007ffcc9d9a000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f992a1ae000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f992a3b6000)

@tienvx
Copy link
Contributor

tienvx commented Nov 14, 2024

I'm on the same platform with you: x86_64 GNU/Linux. I assume you are using 10.1.0-beta1. And the shared library you have is not musl build.

Then the sha256sum of the file pact.so should be the same with mine (480e819b8e2b63625d982676c38585e84315cba25640addf5edf39c338c0cef3). But it's not. Probably it's not downloaded correctly.

One thing you can try is to force it to be downloaded again:

mv vendor/pact-foundation/pact-php/bin vendor/pact-foundation/pact-php/bin.bak
composer update pact-foundation/pact-php

Then run this command again to compare the sha256sum with mine:

sha256sum vendor/pact-foundation/pact-php/bin/pact-ffi-lib/pact.so

@judimator
Copy link
Author

Probably you can tell me what is it build then? I am installing vendors separately and mount the folder into the project

@YOU54F
Copy link
Member

YOU54F commented Nov 14, 2024

has this worked previously before moving the vendors folder?

are you installing the deps on the same target platform as you are running it in?

@judimator
Copy link
Author

Guys, seems I found the issue. The step where I prepare vendors using

/lib/ld-musl-x86_64.so.1 (0x7fed98bab000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7fed98bab000) 

But the place where I run it

linux-vdso.so.1 (0x00007ffdcc589000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2090b31000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2090d39000)

@judimator
Copy link
Author

Would you help me, how to make the library work inside env with?

linux-vdso.so.1 (0x00007ffdcc589000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2090b31000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2090d39000)

@YOU54F
Copy link
Member

YOU54F commented Nov 14, 2024

are you running these in containers? which flavours?

can you provide a repro

@tienvx
Copy link
Contributor

tienvx commented Nov 14, 2024

I think I understand your setup:

  1. Use docker container with alpine image to run composer install to download vendor (including libpact_ffi-linux-x86_64-musl.so.gz)
  2. Mount that vendor (including libpact_ffi-linux-x86_64-musl.so.gz) inside another docker container with ubuntu image for example (doesn't have musl)
  3. Run tests (on ubuntu container)
  4. Tests fail, because:
    1. libpact_ffi-linux-x86_64-musl.so.gz doesn't work on ubuntu? @YOU54F do you know if it is possible? If it's possible, do you know what to do to support this one?
    2. and FYI: libpact_ffi-linux-x86_64.so.gz doesn't work on alpine

For now, I think the workaround is to use the same images for both containers.

@YOU54F
Copy link
Member

YOU54F commented Nov 14, 2024

the musl based library wont work in a glibc based environment

if you need to build your php vendored directory from a glibc based distro and copy it into alpine, you will need to manually install and copy over the musl based library.

php can only load so files on linux which rely on the relevant shared libc

@judimator
Copy link
Author

@tienvx You understood right.
As for workaround, I think so. Thank you @tienvx and @YOU54F !

@YOU54F
Copy link
Member

YOU54F commented Nov 21, 2024

Did this work for you Judimator?

Is this a common scenario that is worthy of documenting, or will this issue suffice for users to find.

Looking at our Docker guidance, we should probably state that Alpine users, can use alpine specific shared libraries, using musl libc, as we provide two variants, one linked to musl libc and one linked to glibc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants