Skip to content

7.4.0 Linux native shared libraries in module not loaded using the RID directory #20740

Closed

Description

@rhubarb-geek-nz

Prerequisites

Steps to reproduce

I have powershell module that uses native shared libraries packaged in the module.

/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/System.Data.SQLite.dll
/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/osx-x64/SQLite.Interop.dll.dylib
/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/linux-arm/SQLite.Interop.dll.so
/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/linux-x64/SQLite.Interop.dll.so
/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/linux-arm64/SQLite.Interop.dll.so
/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/win-x86/SQLite.Interop.dll.dll
/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/osx-arm64/SQLite.Interop.dll.dylib
/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/win-arm/SQLite.Interop.dll.dll
/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/win-arm64/SQLite.Interop.dll.dll
/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/SQLiteConnection.dll
/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/win-x64/SQLite.Interop.dll.dll

7.3.10 finds and loads these shared libraries.

7.4.0 does not look for them on Linux under the RID directory

Expected behavior

3463:     file=/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/SQLite.Interop.dll.so [0];  dynamically loaded by /opt/microsoft/powershell/7/libcoreclr.so [0]
      3463:     file=/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/libSQLite.Interop.dll.so [0];  dynamically loaded by /opt/microsoft/powershell/7/libcoreclr.so [0]
      3463:     opening file=/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/linux-x64/SQLite.Interop.dll.so [0]; direct_opencount=25
      3463:     symbol=sqlite3_set_authorizer;  lookup in file=/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/linux-x64/SQLite.Interop.dll.so [0]
      3463:     binding file /home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/linux-x64/SQLite.Interop.dll.so [0] to /home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/linux-x64/SQLite.Interop.dll.so [0]: normal symbol `sqlite3_set_authorizer'

Actual behavior

3223:     file=/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/SQLite.Interop.dll.so [0];  dynamically loaded by /opt/microsoft/powershell/7/libcoreclr.so [0]
      3223:     file=/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/libSQLite.Interop.dll.so [0];  dynamically loaded by /opt/microsoft/powershell/7/libcoreclr.so [0]
      3223:     file=/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/SQLite.Interop.dll.so [0];  dynamically loaded by /opt/microsoft/powershell/7/libcoreclr.so [0]
      3223:     file=/home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/libSQLite.Interop.dll.so [0];  dynamically loaded by /opt/microsoft/powershell/7/libcoreclr.so [0]
     | /home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/SQLite.Interop.dll.so: cannot open shared object file: No such file or directory
     | /home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/libSQLite.Interop.dll.so: cannot open shared object file: No such file or directory

Error details

     | Unable to load shared library 'SQLite.Interop.dll' or one of its dependencies. In order to help diagnose loading
     | problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment
     | variable:  /opt/microsoft/powershell/7/SQLite.Interop.dll.so: cannot open shared object file: No such file or
     | directory
     | /home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/SQLite.Interop.dll.so:
     | cannot open shared object file: No such file or directory /opt/microsoft/powershell/7/libSQLite.Interop.dll.so:
     | cannot open shared object file: No such file or directory
     | /home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/libSQLite.Interop.dll.so: cannot open shared object file: No such file or directory /opt/microsoft/powershell/7/SQLite.Interop.dll: cannot open shared object file: No such file or directory /home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/SQLite.Interop.dll: cannot open shared object file: No such file or directory /opt/microsoft/powershell/7/libSQLite.Interop.dll: cannot open shared object file: No such file or directory /home/bythesea/.local/share/powershell/Modules/rhubarb-geek-nz.SQLiteConnection/1.0.118.0/libSQLite.Interop.dll: cannot open shared object file: No such file or directory

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Ubuntu 22.04.3 LTS
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

Important detail -

Running the test.ps1 from within a PowerShell 7.4.0 session works, but running "test.ps1" directly from a bash shell (using the shebang) doesn't.

Activity

  1. 237dmitry commented on Nov 21, 2023

    @237dmitry

    Maybe try to export LD_LIBRARY_PATH to set path to home shared libraries? In ~/.profile:

    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/user/.local/share/powershell/Modules/your_dir"
    

    Or do similar in $profile:

    $env:LD_LIBRARY_PATH="$env:LD_LIBRARY_PATH:/home/user/.local/share/powershell/Modules/your_dir"
    
  2. bording commented on Dec 12, 2023

    @bording

    rhubarb-geek-nz The folder structure you have listed seems a bit unexpected to me. If the dep.json files are being used at all to the platform-specific dependencies, then all of those RID folders should be inside a runtimes folder.

    The deployed folder structure should match the layout from the NuGet package, with the native subfolders, etc:
    image

  3. bording commented on Dec 12, 2023

    @bording

    It is not the same layout as a NuGet library package.

    It really should be. If it's not, then I'd argue PowerShell is doing something wrong.

  4. iSazonov commented on Dec 13, 2023

    @iSazonov
    Collaborator

    If I run my script within a powershell console session, then it works but if I run it from unix shell with the prefix..

    Please update the OP with the repro fact.

  5. iSazonov commented on Dec 13, 2023

    @iSazonov
    Collaborator

    $ head test.ps1
    #!/usr/bin/env pwsh

    Can you dump env variables in the script and in console. And compare with 7.3 version.

  6. iSazonov commented on Dec 13, 2023

    @iSazonov
    Collaborator

    rhubarb-geek-nz I mean to put gci env: in the test script and see results.

  7. iSazonov commented on Dec 13, 2023

    @iSazonov
    Collaborator

    rhubarb-geek-nz Thanks for additional information! I don't see difference in envs too. Perhaps you could debug the broken scenario. You need to look the method internal static IntPtr NativeDllHandler(Assembly assembly, string libraryName).

  8. iSazonov commented on Dec 13, 2023

    @iSazonov
  9. daxian-dbw commented on Dec 13, 2023

    @daxian-dbw
    Member

    rhubarb-geek-nz, you mentioned the following in the PR description:

    7.3.10 finds and loads these shared libraries.
    7.4.0 does not look for them on Linux under the RID directory

    Can you please double check if the repro steps work as expected on v7.3.10?
    I'm asking because there is no change that we know of in the native library resolver between v7.3.x and v7.4.0, so if it's true that the reported issue doesn't happen on v7.3.10, then the root cause must be in somewhere else instead of the native library resolver.

  10. iSazonov commented on Dec 13, 2023

    @iSazonov
    Collaborator

    Michael Klement (@mklement0) Have you any ideas why shebang scenario doesn't work?

  11. iSazonov commented on Dec 13, 2023

    @iSazonov
    Collaborator

    rhubarb-geek-nz I still wonder that you reported SQLite.Interop.dll.so and SQLite.Interop.dll.dll - why the names have two file extensions?

  12. iSazonov commented on Dec 13, 2023

    @iSazonov
    Collaborator

    https://nuget.info/packages/Stub.System.Data.SQLite.Core.NetStandard/1.0.118.0

    SQLLite distributes all native assemblies with dll extention! Steve Lee (@SteveL-MSFT) we shouldn't change extension in related PR.

  13. iSazonov commented on Dec 14, 2023

    @iSazonov
    Collaborator

    rhubarb-geek-nz I know only one package - SQLite - where dll extension is used instead of standard platform extension. I believe it is very edge case (but it's in the law.). So obviously current pwsh behavior is a bug we should fix without a fallback to old behavior. I realize this breaks your module, but you can easily fix it by using two versions of the libraries with old and new names. And I'm surprised you didn't report this problem early, but just used a workaround.

  14. iSazonov commented on Dec 14, 2023

    @iSazonov
    Collaborator

    And I'm surprised you didn't report this problem early, but just used a workaround.

    We did - #19277

    Thanks for the reminder. I was sure it was supposed to be fixed in SQLite. I still think so now. Obviously it generates unpredictable behavior in other applications. It's always a bad thing to deviate from de facto standards without justifiable need. (Although the analysis showed that we should fix the pwsh code too.)

  15. added
    WG-Enginecore PowerShell engine, interpreter, and runtime
    and removed
    In-PRIndicates that a PR is out for the issue
    WG-DevEx-Portabilityauthoring cross-platform or cross-architecture modules, cmdlets, and scripts
    on Mar 15, 2024
  16. daxian-dbw commented on Mar 19, 2024

    @daxian-dbw
    Member

    This issue is actually a duplicate of #21319, only that this one surfaced it with native library loading while the other one is GAC assembly loading.

    The root cause is that the native lib resolver and GAC assembly resolvers are not yet registered when running Import-Module by pwsh -c. It's an unexpected regression from the PR #18356, specifically this line of change in ExternalScriptInfo.

    We depend on ClrFacade to be referenced early at startup, but seemingly unrelated change could break that assumption.

  17. added
    Issue-BugIssue has been identified as a bug in the product
    In-PRIndicates that a PR is out for the issue
    and removed
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Mar 19, 2024
  18. microsoft-github-policy-service commented on Mar 21, 2024

    @microsoft-github-policy-service
    Contributor

    📣 Hey rhubarb-geek-nz, how did we do? We would love to hear your feedback with the link below! 🗣️

    🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.4-regressionRegression in 7.4In-PRIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions