JonathonReinhart / staticx

Create static executable from dynamic executable
https://staticx.readthedocs.io/
Other
324 stars 34 forks source link

staticx: GLIBC binary detected but libnssfix.so not available #287

Closed ctrohin closed 1 month ago

ctrohin commented 1 month ago

Hello! I'm trying to build a static binary from a pyinstaller one file output. Below you have my docker setup. I'm getting this libnssfix.so not available error message.

Can you please tell me if I'm missing a library or something? And if so, which library do I need in order to avoid this error.

Thanks

FROM arm64v8/python:3-alpine3.13 AS transformer
RUN apk add scons alpine-sdk patchelf 
RUN apk add --no-cache nss
RUN python3 -m pip install scons staticx
WORKDIR /app
COPY --from=build /app/dist/cloud-connector-aarch64 /app/cloud-connector-arm-non-static
RUN staticx /app/cloud-connector-arm-non-static /app/cloud-connector-arm
JonathonReinhart commented 1 month ago

Please provide the full command and error message.

ctrohin commented 1 month ago

This is basically all I can get from my docker build console:

=> [transformer 7/8] COPY --from=build /app/dist/cloud-connector-aarch64 /app/cloud-connector-arm-non-static 0.1s => ERROR [transformer 8/8] RUN staticx /app/cloud-connector-arm-non-static /app/cloud-connector-arm 2.3s

[transformer 8/8] RUN staticx /app/cloud-connector-arm-non-static /app/cloud-connector-arm: 2.234 staticx: GLIBC binary detected but libnssfix.so not available

Dockerfile-ysl:27

25 | WORKDIR /app 26 | COPY --from=build /app/dist/cloud-connector-aarch64 /app/cloud-connector-arm-non-static 27 | >>> RUN staticx /app/cloud-connector-arm-non-static /app/cloud-connector-arm 28 |
29 | FROM arm64v8/ubuntu:22.04 AS packager

ERROR: failed to solve: process "/bin/sh -c staticx /app/cloud-connector-arm-non-static /app/cloud-connector-arm" did not complete successfully: exit code: 2

ctrohin commented 1 month ago

Managed to capture a more detailed error log by using staticx --debug. Here it is:

30 [transformer 8/8] RUN staticx --debug /app/cloud-connector-arm-non-static /app/cloud-connector-arm

30 2.667 INFO:root:Running StaticX version 0.14.1

30 2.668 INFO:root:Libraries:

30 2.668 INFO:root: elftools: 0.31

30 2.669 DEBUG:root:External tools:

30 2.720 INFO:root: ldd: /usr/bin/ldd: ??? (exited 1)

30 2.763 INFO:root: objcopy: /usr/bin/objcopy: GNU objcopy (GNU Binutils) 2.35.2

30 2.798 INFO:root: strip: /usr/bin/strip: GNU strip (GNU Binutils) 2.35.2

30 2.839 INFO:root: patchelf: /usr/bin/patchelf: patchelf 0.12

30 2.840 DEBUG:root:Arguments:

30 2.840 DEBUG:root: prog: '/app/cloud-connector-arm-non-static'

30 2.841 DEBUG:root: output: '/app/cloud-connector-arm'

30 2.841 DEBUG:root: libs: None

30 2.842 DEBUG:root: strip: False

30 2.843 DEBUG:root: compress: True

30 2.843 DEBUG:root: debug: True

30 2.923 DEBUG:root:Bootloader: bootloader version 0.14.1 compiled Aug 11 2024 at 15:53:38 by gcc version 10.2.1 20201203

30 2.939 INFO:root:Program interpreter: /lib/ld-linux-aarch64.so.1

30 3.020 DEBUG:root:Running ['patchelf', '--remove-rpath', '/tmp/staticx-prog-nobssdk1']

30 3.088 DEBUG:root:Running ['patchelf', '--set-interpreter', 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii', '--set-rpath', 'rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr', '--force-rpath', '/tmp/staticx-prog-nobssdk1']

30 3.215 DEBUG:root:Running ['patchelf', '--no-default-lib', '/tmp/staticx-prog-nobssdk1']

30 3.346 INFO:root:PyInstaller not installed; skipping hook

30 3.375 DEBUG:root:Program linked with GLIBC: Found libc.so.6 GLIBC_2.17

30 3.403 Traceback (most recent call last):

30 3.403 File "/usr/local/lib/python3.10/site-packages/staticx/assets.py", line 8, in locate_asset

30 3.407 return pkg_resources.resource_stream(name, path)

30 3.407 File "/usr/local/lib/python3.10/site-packages/pkg_resources/init.py", line 1136, in resource_stream

30 3.410 return get_provider(package_or_requirement).get_resource_stream(

30 3.410 File "/usr/local/lib/python3.10/site-packages/pkg_resources/init.py", line 1608, in get_resource_stream

30 3.412 return open(self._fn(self.module_path, resource_name), 'rb')

30 3.413 FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.10/site-packages/staticx/assets/debug/libnssfix.so'

30 3.413

30 3.413 During handling of the above exception, another exception occurred:

30 3.413

30 3.413 Traceback (most recent call last):

30 3.413 File "/usr/local/lib/python3.10/site-packages/staticx/hooks/glibc.py", line 15, in process_glibc_prog

30 3.414 nssfix = copy_asset_to_tempfile(LIBNSSFIX, debug=sx.debug,

30 3.414 File "/usr/local/lib/python3.10/site-packages/staticx/assets.py", line 14, in copy_asset_to_tempfile

30 3.415 with locate_asset(assetname, debug) as fsrc:

30 3.415 File "/usr/local/lib/python3.10/site-packages/staticx/assets.py", line 10, in locate_asset

30 3.416 raise KeyError(f"Asset not found: {name!r} (mode={mode!r})")

30 3.416 KeyError: "Asset not found: 'libnssfix.so' (mode='debug')"

30 3.416

30 3.416 During handling of the above exception, another exception occurred:

30 3.416

30 3.416 Traceback (most recent call last):

30 3.416 File "/usr/local/bin/staticx", line 8, in

30 3.417 sys.exit(main())

30 3.417 File "/usr/local/lib/python3.10/site-packages/staticx/main.py", line 49, in main

30 3.417 generate(args.prog, args.output,

30 3.417 File "/usr/local/lib/python3.10/site-packages/staticx/api.py", line 328, in generate

30 3.419 gen.generate(output=output)

30 3.419 File "/usr/local/lib/python3.10/site-packages/staticx/api.py", line 134, in generate

30 3.420 run_hooks(self)

30 3.420 File "/usr/local/lib/python3.10/site-packages/staticx/hooks/init.py", line 12, in run_hooks

30 3.421 hook(sx)

30 3.421 File "/usr/local/lib/python3.10/site-packages/staticx/hooks/glibc.py", line 18, in process_glibc_prog

30 3.422 raise InternalError("GLIBC binary detected but libnssfix.so not available")

30 3.422 staticx.errors.InternalError: GLIBC binary detected but libnssfix.so not available

30 ERROR: process "/bin/sh -c staticx --debug /app/cloud-connector-arm-non-static /app/cloud-connector-arm" did not complete successfully: exit code: 1


[transformer 8/8] RUN staticx --debug /app/cloud-connector-arm-non-static /app/cloud-connector-arm: 3.417 generate(args.prog, args.output, 3.417 File "/usr/local/lib/python3.10/site-packages/staticx/api.py", line 328, in generate 3.419 gen.generate(output=output) 3.419 File "/usr/local/lib/python3.10/site-packages/staticx/api.py", line 134, in generate 3.420 run_hooks(self) 3.420 File "/usr/local/lib/python3.10/site-packages/staticx/hooks/init.py", line 12, in run_hooks 3.421 hook(sx) 3.421 File "/usr/local/lib/python3.10/site-packages/staticx/hooks/glibc.py", line 18, in process_glibc_prog 3.422 raise InternalError("GLIBC binary detected but libnssfix.so not available") 3.422 staticx.errors.InternalError: GLIBC binary detected but libnssfix.so not available

Dockerfile-ysl:27

25 | WORKDIR /app 26 | COPY --from=build /app/dist/cloud-connector-aarch64 /app/cloud-connector-arm-non-static 27 | >>> RUN staticx --debug /app/cloud-connector-arm-non-static /app/cloud-connector-arm 28 |
29 | FROM arm64v8/ubuntu:22.04 AS packager

ERROR: failed to solve: process "/bin/sh -c staticx --debug /app/cloud-connector-arm-non-static /app/cloud-connector-arm" did not complete successfully: exit code: 1

ctrohin commented 1 month ago

Some updates... What I've been doing is building the pyinstaller one file bundle on an alpine container, then tried to build the static binary on a Ubuntu container. I've moved both steps (pyinstaller onefile + staticx) in the same alpine container, and I managed to build it. It did threw some relocation warnings, but it did build it. I've tried running it on an arm64 machine and it did run. I also need to do the same on a arm32 machine.

ctrohin commented 1 month ago

Latest update: I managed to build a static binary from the pyinstaller output as long as I have used the same Docker file for both operations. Didn't work on Ubuntu 22, seems that staticx was just stuck on ldd-ing the original binary, but it did work with an Alpine linux image. Closing the issue