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

gobjectIntrospection: fix incorrect GIR shared library paths #37381

Merged
merged 1 commit into from Mar 22, 2018

Conversation

jtojnar
Copy link
Contributor

@jtojnar jtojnar commented Mar 19, 2018

Motivation for this change

When a library path contained the library name it was eagerly matched

libfwupd.so.2 => /build/fwupd-1.0.5/build/libfwupd/libfwupd.so.2 (0x00007ffff7bbd000)
                                          ^^^^^^^^^^^^^^^^^^^^^^
libgweather-3.so.15 => /build/libgweather-3.28.0/build/libgweather/libgweather-3.so.15 (0x00007ffff7bae000)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

which lead to a broken shared library path in the generated GIR file.

This patch allows the soname on the left-hand side of the arrow to
be matched to avoid the trap of the right-hand side. A negative
lookahead had to be added to select the store path, since only
the first match is taken into account.

libglib-2.0.so.0 => /nix/store/dqlc8y4phlg1hmdbwkhqfwhnxcac88d1-glib-2.56.0/lib/libglib-2.0.so.0 (0x00007ffff6400000)

This will not fix non-GNU platforms, where the soname is not printed
first, but we cannot do much without structured ldd output.

Closes: #34988

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

cc @hedning

@jtojnar
Copy link
Contributor Author

jtojnar commented Mar 19, 2018

Cherry picked for easy reviewing, does not apply to gobject introspection in master though.

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Attempted: gobjectIntrospection

Partial log (click to expand)

setting SOURCE_DATE_EPOCH to timestamp 1506947095 of file gobject-introspection-1.54.1/win32/vs15/gi-version-paths.props
patching sources
applying patch /nix/store/29yj1dwm79m195l854p383bjwqc9i14s-absolute_shlib_path.patch
patching file giscanner/scannermain.py
patching file giscanner/shlibs.py
Hunk #3 FAILED at 127.
1 out of 3 hunks FAILED -- saving rejects to file giscanner/shlibs.py.rej
patching file giscanner/utils.py
builder for '/nix/store/qimbkl3xcrxy7my93a37slr46zh0anwy-gobject-introspection-1.54.1.drv' failed with exit code 1
�[31;1merror:�[0m build of '/nix/store/qimbkl3xcrxy7my93a37slr46zh0anwy-gobject-introspection-1.54.1.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: gobjectIntrospection

Partial log (click to expand)

setting SOURCE_DATE_EPOCH to timestamp 1506947095 of file gobject-introspection-1.54.1/win32/vs15/gi-version-paths.props
patching sources
applying patch /nix/store/llg86j1c6wy95wzfj2h7y5qaac842nd8-absolute_shlib_path.patch
patching file giscanner/scannermain.py
patching file giscanner/shlibs.py
Hunk #3 FAILED at 127.
1 out of 3 hunks FAILED -- saving rejects to file giscanner/shlibs.py.rej
patching file giscanner/utils.py
builder for '/nix/store/dmhsmd9wbccq5mgp6bm3cg9amlg2balw-gobject-introspection-1.54.1.drv' failed with exit code 1
error: build of '/nix/store/dmhsmd9wbccq5mgp6bm3cg9amlg2balw-gobject-introspection-1.54.1.drv' failed

@GrahamcOfBorg
Copy link

Failure on x86_64-darwin (full log)

Attempted: gobjectIntrospection

Partial log (click to expand)

setting SOURCE_DATE_EPOCH to timestamp 1506947095 of file gobject-introspection-1.54.1/win32/vs15/gi-version-paths.props
patching sources
applying patch /nix/store/k10r0g0hgm9nyhdp63mxkix9lnylfc7v-absolute_shlib_path.patch
patching file giscanner/scannermain.py
patching file giscanner/shlibs.py
Hunk #3 FAILED at 127.
1 out of 3 hunks FAILED -- saving rejects to file giscanner/shlibs.py.rej
patching file giscanner/utils.py
builder for '/nix/store/v4pfx8g89msklqyyzlk1vv7ckc4jaslk-gobject-introspection-1.54.1.drv' failed with exit code 1
error: build of '/nix/store/v4pfx8g89msklqyyzlk1vv7ckc4jaslk-gobject-introspection-1.54.1.drv' failed

+ and len(options.fallback_libpath) > 0:
+ match = os.path.join(options.fallback_libpath, match)
+ shlibs.append(match)
+ shlibs.append(os.path.join(options.fallback_libpath, m.group(1)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing fallback_libpath is known to be empty when dealing with absolute paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component.

https://docs.python.org/3/library/os.path.html#os.path.join

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense.

Copy link
Contributor

@hedning hedning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested the _ldd_nix_pattern function minimally, and it seemed to do the job :)

When a library path contained the library name it was eagerly matched

    libfwupd.so.2 => /build/fwupd-1.0.5/build/libfwupd/libfwupd.so.2 (0x00007ffff7bbd000)
                                              ^^^^^^^^^^^^^^^^^^^^^^
    libgweather-3.so.15 => /build/libgweather-3.28.0/build/libgweather/libgweather-3.so.15 (0x00007ffff7bae000)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

which lead to a broken shared library path in the generated GIR file.

This patch allows the soname on the left-hand side of the arrow to
be matched to avoid the trap of the right-hand side. A negative
lookahead had to be added to select the store path, since only
the first match is taken into account.

    libglib-2.0.so.0 => /nix/store/dqlc8y4phlg1hmdbwkhqfwhnxcac88d1-glib-2.56.0/lib/libglib-2.0.so.0 (0x00007ffff6400000)

This will not fix non-GNU platforms, where the soname is not printed
first, but we cannot do much without structured ldd output.

Closes: NixOS#34988
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

meson sometimes generates incorrect GIR paths
3 participants