Skip to content

atomic patch not working for esp32 #251

Closed

Description

@niedr
  • Hardware description: esp32
  • RTOS: FreeRTOS
  • Installation type: espidf, component
  • Version or commit hash: humble

Steps to reproduce the issue

Clone this repo in components folder, then as always:

idf.py set-target esp32
idf.py build 

Actual behavior

build fails:

/home/raphael/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: esp-idf/newlib/libnewlib.a(stdatomic.c.obj): in function `__atomic_exchange_8':
/home/raphael/esp/v5.3/esp-idf/components/newlib/stdatomic.c:77: multiple definition of `__atomic_exchange_8'; /home/raphael/idf_components/micro_ros_espidf_component/libmicroros.a(librcutils-atomic_64bits.c.obj):atomic_64bits.c:(.text.__atomic_exchange_8+0x0): first defined here
/home/raphael/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: esp-idf/newlib/libnewlib.a(stdatomic.c.obj): in function `__atomic_fetch_add_8':
/home/raphael/esp/v5.3/esp-idf/components/newlib/stdatomic.c:77: multiple definition of `__atomic_fetch_add_8'; /home/raphael/idf_components/micro_ros_espidf_component/libmicroros.a(librcutils-atomic_64bits.c.obj):atomic_64bits.c:(.text.__atomic_fetch_add_8+0x0): first defined here
/home/raphael/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: esp-idf/newlib/libnewlib.a(stdatomic.c.obj): in function `__atomic_load_8':
/home/raphael/esp/v5.3/esp-idf/components/newlib/stdatomic.c:77: multiple definition of `__atomic_load_8'; /home/raphael/idf_components/micro_ros_espidf_component/libmicroros.a(librcutils-atomic_64bits.c.obj):atomic_64bits.c:(.text.__atomic_load_8+0x0): first defined here
/home/raphael/.espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/13.2.0/../../../../xtensa-esp-elf/bin/ld: esp-idf/newlib/libnewlib.a(stdatomic.c.obj): in function `__atomic_store_8':
/home/raphael/esp/v5.3/esp-idf/components/newlib/stdatomic.c:77: multiple definition of `__atomic_store_8'; /home/raphael/idf_components/micro_ros_espidf_component/libmicroros.a(librcutils-atomic_64bits.c.obj):atomic_64bits.c:(.text.__atomic_store_8+0x0): first defined here
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1, output of the command is in the

Additional information

By modifying the file libmicroros.mk i was able to make it work:
in line 110 i added esp32 as target too. So the full line looks like this then:
ifeq ($(IDF_TARGET),$(filter $(IDF_TARGET), esp32 esp32s2 esp32c3))
However, i`m not experienced enough to know whether this has any side effects and is a valid change.

Activity

  1. Care-Again commented on Jun 27, 2025

    @Care-Again

    I met the same error:( with my ESP32-S3. libnewlib.a form ESP-IDF & newlib and libmicroros.a form micro-ROS
    is conficting, which means my ESPIDF-V5.4 has no idea on __atomic_exchange_8、__atomic_fetch_add_8

  2. Roboprotos commented on Jun 28, 2025

    @Roboprotos

    Hi, I'm experiencing the same issue with micro-ros on ESP32 S3 using ESP-IDF V5.3.1.
    esp-idf/components/newlib/stdatomic.c:77: multiple definition of __atomic_fetch_add_8';

    Has this issue been patched or solved ?

    EDIT: however, adding esp32s3 to the patch_atomic section in libmicroros.mk worked for me:
    feq ($(IDF_TARGET),$(filter $(IDF_TARGET),esp32s3 esp32s2 esp32c3 esp32c6))

    ESP32 S3 is quite popular, it would be great if someone could add it to patch_atomic.

  3. Care-Again commented on Jun 29, 2025

    @Care-Again

    @Roboprotos
    My issue was just as same as yours. My ESPIDF told me those __atomic__functions were defined for twice. I had tried plenty of methods but none works.

    I tried to give a clear order in my Cmakelists to make sure those functions from ESPIDF should be "neglected" while only the ones from Micro-ROS are on thery duty but this DIDN'T WORK.

    Then I tried to delete these functions in /esp-idf/newlib/stdatomic.c. BUT the error occurred again.

    At last I had to use a complete OS from the shop which I bought my ESP32-S3 from. This time it works with no error.

    HOPE you could find the solutions !

  4. Care-Again commented on Jun 29, 2025

    @Care-Again

    @Roboprotos
    You can try previous versions of ESPIDF. The owner of the shop tells me to use ROS2-humble, Micro-ROS-humble and ESPIDF-V5.1.2.

    MAYBE this works !

  5. Roboprotos commented on Jun 29, 2025

    @Roboprotos

    @Care-Again Thank you for your feedback. I wrote the solution I found at the end of my previous comment. It works for me using ESP-IDF v5.3.1, ESP32 S3 and jazzy branch of micro-ros espidf component.

  6. kmarques-24 commented on Oct 19, 2025

    @kmarques-24

    @Care-Again For future reference, the combination of ROS2-humble, MicroROS-humble, and ESPIDF-v5.1.2 worked for me!

  7. JoseGomesJr commented on Jan 23, 2026

    @JoseGomesJr

    I am encountering the exact same issue with ESP-IDF v5.5 (Master) targeting the ESP32-S3.

    Context:
    I cannot downgrade to the stable version (v5.3) because my project strictly requires specific DMA features for the ESP32-S3 that are currently only available in v5.5.

    Workaround:
    Since GCC 14 (bundled with IDF v5.5) now includes built-in atomic implementations that conflict with rcutils, I managed to fix the build by patching the CMakeLists.txt of the component to force the linker to accept multiple definitions.

    In components/micro_ros/CMakeLists.txt, append the interface link option at the end:

    add_dependencies(${COMPONENT_LIB} libmicroros-prebuilt)
    target_link_libraries(${COMPONENT_LIB} INTERFACE libmicroros-prebuilt)
    
    # FIX: Allow multiple definitions to handle GCC 14 / micro-ROS atomic conflict
    target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--allow-multiple-definition")
    

    After applying this change and running a full clean (rm -rf build / idf.py build), the project compiles successfully.

  8. added a commit that references this issue on Apr 5, 2026
  9. Narukara commented on Apr 13, 2026

    @Narukara
    Contributor

    I ran a test: based on the humble branch of this repository, I tried building the examples/int32_publisher using different versions of ESP-IDF and for different target chips. Here are the test results:

    version ESP32 ESP32S3 ESP32C3
    5.2 T,✅ T,✅ U,✅
    5.3 T,❌ T,❌ U,✅
    5.4 T,❌ T,❌ U,✅
    5.5 U,✅ U,✅ U,✅

    T: libmicroros.a contains atomic operations.
    U: libmicroros.a does not contain atomic operations.
    ❌: Build failed due to duplicate definition of atomic operations.
    ✅: Build succeeded.

    ESP-IDF 6.0: Build failed, possibly because ESP-IDF has been using picolibc by default since 6.0.

  10. Narukara commented on Apr 13, 2026

    @Narukara
    Contributor

    On ESP-IDF 5.2, libmicroros.a includes atomic operations but does not cause a build failure. This appears to be because atomic operations are not used internally by ESP-IDF, so its built-in atomic operations are not actually linked. On version 5.3, however, ESP-IDF has introduced some atomic operations internally. See:

    This then leads to a build failure.

    One more thing: I tried adding atomic operations manually in ESP-IDF version 5.2 and successfully triggered a duplicate definition error for atomic operations.

  11. Narukara commented on Apr 13, 2026

    @Narukara
    Contributor

    The patch_atomic mechanism in the libmicroros.mk comes from #18. It was introduced to address the issue that ESP-IDF only provided partial atomic operations. From version 5.2 onward, it seems that ESP-IDF provides complete atomic operations. Therefore, perhaps we can simply disable the micro-ROS 64-bit atomic extension and remove patch_atomic? I'll give it a try later.

    "-DRCUTILS_NO_64_ATOMIC=ON",

  12. added a commit that references this issue on Apr 15, 2026
  13. Narukara commented on May 27, 2026

    @Narukara
    Contributor

    Since the atomic patch has been removed, this issue can be closed.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions