LinwoodDev / Butterfly

🎨 Powerful, minimalistic, cross-platform, opensource note-taking app
https://butterfly.linwood.dev
GNU Affero General Public License v3.0
891 stars 62 forks source link

[Bug]: RPATH error in lib/xxx.so #647

Closed Kiri2002 closed 3 months ago

Kiri2002 commented 3 months ago

What happened?

After build in archlinux, in app/build/linux/x64/release/bundle/lib, some so files got run RPATH:

0x000000000000000e (SONAME)             Library soname: [libdynamic_color_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [/home/kiri/Build/butterfly/src/Butterfly-2.0.3/app/linux/flutter/ephemeral]
--
 0x000000000000000e (SONAME)             Library soname: [libfile_selector_linux_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [/home/kiri/Build/butterfly/src/Butterfly-2.0.3/app/linux/flutter/ephemeral]
--
 0x000000000000000e (SONAME)             Library soname: [libflutter_secure_storage_linux_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [/home/kiri/Build/butterfly/src/Butterfly-2.0.3/app/linux/flutter/ephemeral]
--
 0x000000000000000e (SONAME)             Library soname: [libprinting_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/home/kiri/Build/butterfly/src/Butterfly-2.0.3/app/build/linux/x64/release/pdfium-src/lib]
--
 0x000000000000000e (SONAME)             Library soname: [libscreen_retriever_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [/home/kiri/Build/butterfly/src/Butterfly-2.0.3/app/linux/flutter/ephemeral]
--
 0x000000000000000e (SONAME)             Library soname: [liburl_launcher_linux_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [/home/kiri/Build/butterfly/src/Butterfly-2.0.3/app/linux/flutter/ephemeral]
--
 0x000000000000000e (SONAME)             Library soname: [libwindow_manager_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [/home/kiri/Build/butterfly/src/Butterfly-2.0.3/app/linux/flutter/ephemeral]

"/home/kiri/Build/butterfly/src" is my building path.

Although it can run successfully, but maybe not safe.

I changed use this cmd and works well.

    patchelf --remove-rpath "libdynamic_color_plugin.so"
    patchelf --remove-rpath "libfile_selector_linux_plugin.so"
    patchelf --remove-rpath "libflutter_secure_storage_linux_plugin.so"
    patchelf --set-rpath '$ORIGIN' "libprinting_plugin.so"
    patchelf --remove-rpath "libscreen_retriever_plugin.so"
    patchelf --remove-rpath "liburl_launcher_linux_plugin.so"
    patchelf --remove-rpath "libwindow_manager_plugin.so"

But idk how to avoid this issue in build process.

Version

2.0.3

Platform

Linux

Relevant log output

This is how I build

prepare() {
    cd "${_pkgname}-${pkgver}/app"
    fvm global stable

    # Disable analytics and enable linux desktop
    fvm flutter --no-version-check config --no-analytics
    fvm flutter --no-version-check config --enable-linux-desktop

    # Pull dependencies within prepare, allowing for offline builds later on
    fvm flutter --no-version-check pub get
}

build() {
    cd "${_pkgname}-${pkgver}/app"
    fvm flutter --no-version-check build linux --release --prefixed-errors
}
package() {

    install -Dm 755 "${srcdir}/${pkgname}.sh" "${pkgdir}/usr/bin/${pkgname}"

    cd "${srcdir}/${_pkgname}-${pkgver}/app/build/linux/x64/release/bundle"
    install -Dm 755 butterfly "${pkgdir}/usr/share/${pkgname}/butterfly"
    install -Dm 644 lib/* -t "${pkgdir}/usr/lib/${pkgname}"
    cp -r data "${pkgdir}/usr/share/${pkgname}/data"
    ln -sr "${pkgdir}/usr/lib/${pkgname}" "${pkgdir}/usr/share/${pkgname}/lib"

    cd "${srcdir}/${_pkgname}-${pkgver}/app/linux/debian/usr/share"
    install -Dm 664  "applications/dev.linwood.butterfly.desktop" "${pkgdir}/usr/share/applications/dev.linwood.butterfly.desktop"
    install -Dm 664  "icons/hicolor/128x128/apps/dev.linwood.butterfly.png" "${pkgdir}/usr/share/icons/hicolor/128x128/apps/dev.linwood.butterfly.png"
    install -Dm 664  "icons/hicolor/256x256/apps/dev.linwood.butterfly.png" "${pkgdir}/usr/share/icons/hicolor/256x256/apps/dev.linwood.butterfly.png"
    install -Dm 664  "metainfo/dev.linwood.butterfly.appdata.xml" "${pkgdir}/usr/share/metainfo/dev.linwood.butterfly.appdata.xml"
    install -Dm 664  "mime/packages/dev.linwood.butterfly.xml" "${pkgdir}/usr/share/mime/packages/dev.linwood.butterfly.xml"
}

Code of Conduct

Kiri2002 commented 3 months ago

well, I meet same issue in other flutter package. I think maybe this is something wrong with flutter itself

CodeDoctorDE commented 3 months ago

I had a similar issue but i fixed it using these commands: https://github.com/LinwoodDev/Butterfly/blob/5eeb947dad8f8205f0b163040cdbf4a16f34d2b3/app/scripts/build-rpm.sh#L21-L33 Just run this after flutter build Can you try if these fixes your issue?

Kiri2002 commented 3 months ago

I had a similar issue but i fixed it using these commands:

https://github.com/LinwoodDev/Butterfly/blob/5eeb947dad8f8205f0b163040cdbf4a16f34d2b3/app/scripts/build-rpm.sh#L21-L33

Just run this after flutter build Can you try if these fixes your issue?

Yes, this script fix well. I added to PKGBUILD(arch package script).

It would be very beneficial, if this ".so fixing" script run in app/build/linux/x64/release/bundle/lib/ directly after build. So that others could ignore this issue totally.

Kiri2002 commented 3 months ago

Well, bad news, it can't just set all "issue .so" runpath to "ORIGIN", otherwise app will down:

[FATAL:flutter/runtime/dart_vm_initializer.cc(89)] Error while initializing the Dart VM: Invalid vm isolate snapshot seen
Aborted: oops, process 'butterfly' core dumped

this happened because some .so shouldn't have runpath even "ORIGIN" run after above script, all issue .so set to "ORIGIN":

readelf -d lib/*|grep run -B 1                                                                           03/28/2024 10:00:13 PM PM
  Tag        Type                         Name/Value
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
--
 0x000000000000000e (SONAME)             Library soname: [libdynamic_color_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
--
 0x000000000000000e (SONAME)             Library soname: [libfile_selector_linux_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
--
  Tag        Type                         Name/Value
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
--
 0x000000000000000e (SONAME)             Library soname: [libflutter_secure_storage_linux_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
--
  Tag        Type                         Name/Value
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
--
 0x000000000000000e (SONAME)             Library soname: [libprinting_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
--
 0x000000000000000e (SONAME)             Library soname: [libscreen_retriever_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
--
 0x000000000000000e (SONAME)             Library soname: [liburl_launcher_linux_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
--
 0x000000000000000e (SONAME)             Library soname: [libwindow_manager_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]

while, it should be:

 readelf -d lib/*|grep run -B 1                                                                           03/28/2024 10:00:26 PM PM
  Tag        Type                         Name/Value
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]
--
 0x000000000000000e (SONAME)             Library soname: [libprinting_plugin.so]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]

In this way, app run well.

So i thinks the right way may be just delete wrong path.

Kiri2002 commented 3 months ago

I had a similar issue but i fixed it using these commands:

https://github.com/LinwoodDev/Butterfly/blob/5eeb947dad8f8205f0b163040cdbf4a16f34d2b3/app/scripts/build-rpm.sh#L21-L33

Just run this after flutter build Can you try if these fixes your issue?

refined script like this, works fine:

    # Fix .so files using patchelf
    for file in *.so; do
        PATCHELF_OUTPUT=$(patchelf --print-rpath $file)
        echo "Checking $file: $PATCHELF_OUTPUT"
    # Skip file if PATCHELF_OUTPUT does not contain CURRENT_DIR
        if [[ ! $PATCHELF_OUTPUT =~ $CURRENT_DIR ]]; then
            echo "Skipping $file"
            continue
        fi
    # Remove rpath if it not contain ORIGIN before
        if [[ ! $PATCHELF_OUTPUT =~ 'ORIGIN' ]]; then
            echo "Removing rpath for $file"
            patchelf --remove-rpath $file
            continue
        fi
    # Set rpath to ORIGIN if it contain ORIGIN before
        echo "Setting ORIGIN rpath for $file"
        patchelf --set-rpath '$ORIGIN' $file
    done
CodeDoctorDE commented 3 months ago

perfect, can i close this issue? Please send me a link to the package if you are done :)

Kiri2002 commented 3 months ago

perfect, can i close this issue? Please send me a link to the package if you are done :)

Well I pushed the package to Archlinuxcn'repo, I will link the package as long as it passed.

Thanks to your beautiful software and your nice work :smiley:

CodeDoctorDE commented 3 months ago

Oh nice, but is this package only available in china? I thought this build scripts are universal?