flipperdevices / flipperzero-ufbt

Compact tool for building and debugging applications for Flipper Zero.
https://pypi.org/project/ufbt/
GNU General Public License v3.0
494 stars 36 forks source link

Unresolved symbols for sub-library #24

Closed qistoph closed 8 months ago

qistoph commented 8 months ago

I can´t seem to compile a FAP with ufbt that has a private library referencing methods from a shared library (mbedtls).

fbt: warning: [...]: app may not be runnable. Symbols not resolved using firmware's API: {'mbedtls_sha1'} (in API, but disabled: {'mbedtls_sha1'})

For research, testing and demonstration I have created a small app with 2 branches. https://github.com/qistoph/ufbt-lib-lib

master looks like this and has no issues compiling.

template.c: main() --> demo.c: calc_sha1() --> mbedtls/sha1: mbedtls_sha1()

ext_lib looks like this and gives the error I'm running into.

template.c: main() --> lib/demo/demo.c: calc_sha1() --> mbedtls/sha1: mbedtls_sha1()

The application.fam uses these definitions:

    fap_libs=["mbedtls"],
    fap_private_libs=[Lib(name="demo")],

I'm sorry if this is an error on my side and not a limitation of ufbt and this shouldn't have been posted as an issue.

hedger commented 8 months ago

The mbedtls library that is distributed alongside the firmware only contains a small subset of its code that the firmware itself makes use of.

For now, please bring an implementation of sha routines alongside your app (using fap_private_libs). We'll re-evaluate the subset of features that are available in mbedtls library later, but addition of all of its features to basic firmware build is quite unlikely.

qistoph commented 8 months ago

Thanks for the feedback and suggestion. I don't think my issue was understood properly though.

I am trying to bring the implementation of sha routines from mbedtls. This works fine as long as the calls to this library are from the main application. When I move the call to a custom, private library there seems no way to tell how to resolve a dependent (public) library.

hedger commented 8 months ago

Ah. So it depends on the order of libraries ufbt passes to the linker, that makes sense. Could you please upload a minimal example for reproduction of the issue somewhere?

qistoph commented 8 months ago

Minimal examples are available in the repository linked in the initial post.

"master" works as expected, but without private library. "ext_lib" has almost the same code and uses a private library.

hedger commented 8 months ago
$ ufbt status
20:47:03.104 [I] uFBT version    0.2.4.3.dev1
20:47:03.104 [I] State dir       /Users/hedger/.ufbt
20:47:03.104 [I] Download dir    /Users/hedger/.ufbt/download
20:47:03.104 [I] SDK dir         /Users/hedger/.ufbt/current
20:47:03.104 [I] Toolchain dir   /Users/hedger/.ufbt/toolchain
20:47:03.104 [I] Target          f7
20:47:03.104 [I] Mode            channel
20:47:03.104 [I] Version         0.94.1
20:47:03.104 [I] Details         {'hw_target': 'f7', 'mode': 'channel', 'channel': 'release', 'json_index': 'https://update.flipperzero.one/firmware/directory.json', 'version': '0.94.1'}

$ git status
On branch ext_lib
Your branch is up to date with 'origin/ext_lib'.

nothing to commit, working tree clean

$ ufbt
scons: Entering directory `/Users/hedger/.ufbt/current/scripts/ufbt'
    ICONS   /Users/hedger/.ufbt/build/template/template_icons.c
    CC  /Users/hedger/tmp/ufbt_test/good faps repo/ufbt-lib-lib/lib/demo/demo.c
    INSTALL /Users/hedger/tmp/ufbt_test/good faps repo/ufbt-lib-lib/template.png
    CDB /Users/hedger/tmp/ufbt_test/good faps repo/ufbt-lib-lib/.vscode/compile_commands.json
    AR  /Users/hedger/.ufbt/build/template/demo
    RANLIB  /Users/hedger/.ufbt/build/template/demo
    CC  /Users/hedger/tmp/ufbt_test/good faps repo/ufbt-lib-lib/template.c
    CC  /Users/hedger/.ufbt/build/template/template_icons.c
    LINK    /Users/hedger/.ufbt/build/template_d.elf
    APPMETA /Users/hedger/.ufbt/build/template.fap
    INSTALL /Users/hedger/tmp/ufbt_test/good faps repo/ufbt-lib-lib/dist/debug/template_d.elf
    FAP /Users/hedger/.ufbt/build/template.fap
    FASTFAP /Users/hedger/.ufbt/build/template.fap
    INSTALL /Users/hedger/tmp/ufbt_test/good faps repo/ufbt-lib-lib/dist/template.fap
    APPCHK  /Users/hedger/.ufbt/build/template.fap
        Target: 7, API: 40.1

what's the reproduction case?

qistoph commented 8 months ago

Thanks @hedger for looking into this issue. Apparently it was fixed in 0.94.

Using the 0.93.0 branch:

$ ufbt update --branch=0.93.0
20:31:53.877 [I] Deploying SDK for f7
20:31:53.877 [I] Fetching branch index https://update.flipperzero.one/builds/firmware/0.93.0/
20:31:54.257 [I] Found version 0.93.0
20:31:54.257 [I] uFBT SDK dir: /home/chris/.ufbt/current
20:31:55.960 [I] Deploying SDK
20:31:56.294 [I] SDK deployed.

$ ufbt status
20:32:04.563 [I] uFBT version    0.2.4.3
20:32:04.563 [I] State dir       /home/chris/.ufbt
20:32:04.563 [I] Download dir    /home/chris/.ufbt/download
20:32:04.563 [I] SDK dir         /home/chris/.ufbt/current
20:32:04.563 [I] Toolchain dir   /home/chris/.ufbt/toolchain
20:32:04.563 [I] Target          f7
20:32:04.563 [I] Mode            branch
20:32:04.563 [I] Version         0.93.0
20:32:04.563 [I] Details         {'hw_target': 'f7', 'mode': 'branch', 'branch': '0.93.0', 'version': '0.93.0', 'branch_root': 'https://update.flipperzero.one/builds/firmware'}

$ ufbt
scons: Entering directory `/home/chris/.ufbt/current/scripts/ufbt'
    ICONS   /home/chris/.ufbt/build/template/template_icons.c
    CC  /home/chris/Projects/ufbt-lib-lib/lib/demo/demo.c
    INSTALL /home/chris/Projects/ufbt-lib-lib/template.png
    CDB /home/chris/Projects/ufbt-lib-lib/.vscode/compile_commands.json
    AR  /home/chris/.ufbt/build/template/demo
    RANLIB  /home/chris/.ufbt/build/template/demo
    CC  /home/chris/.ufbt/build/template/template_icons.c
    CC  /home/chris/Projects/ufbt-lib-lib/template.c
    LINK    /home/chris/.ufbt/build/template_d.elf
    INSTALL /home/chris/Projects/ufbt-lib-lib/dist/debug/template_d.elf
    APPMETA /home/chris/.ufbt/build/template.fap
    FAP /home/chris/.ufbt/build/template.fap
    FASTFAP /home/chris/.ufbt/build/template.fap
    INSTALL /home/chris/Projects/ufbt-lib-lib/dist/template.fap
    APPCHK  /home/chris/.ufbt/build/template.fap
        Target: 7, API: 39.2

fbt: warning: /home/chris/.ufbt/build/template.fap: app may not be runnable. Symbols not resolved using firmware's API: {'mbedtls_sha1'} (in API, but disabled: {'mbedtls_sha1'})
validate_app_imports, line 303, in file "/home/chris/.ufbt/current/scripts/fbt_tools/fbt_extapps.py"

Using the current release, 0.94.1:

$ ufbt update --channel=release
20:34:09.501 [I] Deploying SDK for f7
20:34:09.501 [I] Fetching version info for UpdateChannel.RELEASE from https://update.flipperzero.one/firmware/directory.json
20:34:09.837 [I] Using version: 0.94.1
20:34:09.837 [I] uFBT SDK dir: /home/chris/.ufbt/current
20:34:09.838 [I] SDK is up-to-date

$ ufbt status
20:34:28.994 [I] uFBT version    0.2.4.3
20:34:28.994 [I] State dir       /home/chris/.ufbt
20:34:28.994 [I] Download dir    /home/chris/.ufbt/download
20:34:28.994 [I] SDK dir         /home/chris/.ufbt/current
20:34:28.994 [I] Toolchain dir   /home/chris/.ufbt/toolchain
20:34:28.994 [I] Target          f7
20:34:28.994 [I] Mode            channel
20:34:28.995 [I] Version         0.94.1
20:34:28.995 [I] Details         {'hw_target': 'f7', 'mode': 'channel', 'channel': 'release', 'json_index': 'https://update.flipperzero.one/firmware/directory.json', 'version': '0.94.1'}

$ ufbt
scons: Entering directory `/home/chris/.ufbt/current/scripts/ufbt'
    ICONS   /home/chris/.ufbt/build/template/template_icons.c
    CC  /home/chris/Projects/ufbt-lib-lib/lib/demo/demo.c
    INSTALL /home/chris/Projects/ufbt-lib-lib/template.png
    CDB /home/chris/Projects/ufbt-lib-lib/.vscode/compile_commands.json
    AR  /home/chris/.ufbt/build/template/demo
    RANLIB  /home/chris/.ufbt/build/template/demo
    CC  /home/chris/Projects/ufbt-lib-lib/template.c
    CC  /home/chris/.ufbt/build/template/template_icons.c
    LINK    /home/chris/.ufbt/build/template_d.elf
    INSTALL /home/chris/Projects/ufbt-lib-lib/dist/debug/template_d.elf
    APPMETA /home/chris/.ufbt/build/template.fap
    FAP /home/chris/.ufbt/build/template.fap
    FASTFAP /home/chris/.ufbt/build/template.fap
    INSTALL /home/chris/Projects/ufbt-lib-lib/dist/template.fap
    APPCHK  /home/chris/.ufbt/build/template.fap
        Target: 7, API: 40.1
hedger commented 8 months ago

You're welcome. Also please check out latest 0.95.0-rc, there are more changes and improvements for .faps.