How to compile a static library into 4-byte aligned format in NCS project?

Hello, I am debugging a program running on the FLPR core on the nRF54L15 development board. I need to call a static library (. a file) on the FLPR core. I use the project created by the nRF Connect SDK to generate a static library, and then call it in the main function of the project.


This is the code for generating a static library in the CMakeLists.txt file:


target_sources(app PRIVATE
    src/flpr_lib_src.c
)
include_directories(${PROJECT_SOURCE_DIR}/include)
set(CMAKE_SYSTEM_PROCESSOR riscv)
set(CMAKE_TOOLCHAIN_FILE ${ZEPHYR_BASE}/cmake/toolchain/riscv.cmake)
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_LIST_DIR}/lib)
set(SOURCES
    src/flpr_lib_src.c
)
add_library(flpr STATIC ${SOURCES})


And this is the CMakeLists.txt code when I compile the static library into hex:


target_sources(app PRIVATE ${app_sources})
target_link_libraries(app PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/lib/libflpr.a
)


When compiling the static library into hex, the following errors was reported:
"error: ../lib/libflpr.a(flpr_lib_src.c.obj) use 16-byte stack aligned but the output use 4-byte stack aligned"

"error: ../lib/libflpr.a(flpr_lib_src.c.obj): mis-matched ISA string to merge 'i' and 'e'"


How can I compile a static library into 4-byte aligned format?

Or is there any other way to solve these error problem?

Parents
  • Hi, 

    I would first look at ninja files to see how these files are built. It seems that ABI is not compatible (are they using the same compiler and the same option set?). Looking at ninja build files should show how the code is constructed, so you will likely spot what is off.

    Then you need to apply what's needed - assuming the toolchain is right.

    You can look at which option to play with in Option Summary (Using the GNU Compiler Collection (GCC)). If this is compiled by zephyr, you can add a custom option with CONFIG_COMPILER_OPT (zephyr/Kconfig.zephyr at main · zephyrproject-rtos/zephyr)

    In CMake, you can add the option to a specific target with target_compile_options (target_compile_options — CMake 4.1.0-rc4 Documentation)

    Regards,
    Amanda H.

  • Hi,

    Thank you very much for your reply. I have been busy with other things before, so this issue has been temporarily put on hold. Now I am coming back to find a solution.

    I am not very familiar with the ninja file you mentioned, and I am also not very clear about the compilation mechanism of NCS, so I cannot provide you with the ninja file.

    Recently, I found a method through the technical support staff of a Nordic agent: when compiling a static library, adding “target_compile_options (flpr PRIMATE - pre preferred stack background=2)” to the. a library can change the byte alignment of the static library. However, I found that adding this compilation option would result in an error: error: '- pre preferred stack background=2' must be between 3 and 8. This means that using this method can only produce static libraries that are aligned with at least 8 bytes, or it cannot be compiled into a 4-byte aligned hex.

    Do you know how to create a 4-byte aligned static library for the flpr core?

    Regards,

    ZH

Reply
  • Hi,

    Thank you very much for your reply. I have been busy with other things before, so this issue has been temporarily put on hold. Now I am coming back to find a solution.

    I am not very familiar with the ninja file you mentioned, and I am also not very clear about the compilation mechanism of NCS, so I cannot provide you with the ninja file.

    Recently, I found a method through the technical support staff of a Nordic agent: when compiling a static library, adding “target_compile_options (flpr PRIMATE - pre preferred stack background=2)” to the. a library can change the byte alignment of the static library. However, I found that adding this compilation option would result in an error: error: '- pre preferred stack background=2' must be between 3 and 8. This means that using this method can only produce static libraries that are aligned with at least 8 bytes, or it cannot be compiled into a 4-byte aligned hex.

    Do you know how to create a 4-byte aligned static library for the flpr core?

    Regards,

    ZH

Children
Related