Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suspected miscompilation (as observed in a BLE Mesh function) #270

Open
ok32 opened this issue Dec 22, 2023 · 1 comment
Open

Suspected miscompilation (as observed in a BLE Mesh function) #270

ok32 opened this issue Dec 22, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@ok32
Copy link
Contributor

ok32 commented Dec 22, 2023

Hello. I've stumbled upon a peculiar error which was quite hard to trace.

The minimal reproducible example app: https://github.com/ok32/esp-rs-ble-miscomp. I build it in the default devcontainer.

Build target: xtensa-esp32s3-espidf.
esp-idf versions tried: 5.0.5, 5.1.1, 5.1.2.

I tried to initialize BLE Mesh (with the Nimble stack) by replicating the sequence of C calls from an example from the esp-idf repo. I ended up getting an internal assertion violation during one of the calls (esp_ble_mesh_node_prov_enable()). Furhter investigation showed that the problem was not in that particular function. Instead, it was here:
https://github.com/espressif/esp-idf/blob/482a8fb2d78e3b58eb21b26da8a5bedf90623213/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c#L1293-L1312

If I use it as it is, it somehow manages to skip the else branch of the if statement completely, resulting in some garbage in the uuid variable. But once I add anything there, it starts to work. It works with this patch:

diff --git a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c
index a651b54284..5e5af02f91 100644
--- a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c
+++ b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c
@@ -1299,6 +1299,8 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc)
         uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_VAL);
     } else {
         uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROV_VAL);
+        // just add this line and it works:
+        BT_ERR("(bt_mesh_gatts_service_start:else) abcabcabca");
     }

     rc = ble_gatts_find_svc(uuid, &handle);

What's in the log when it fails: https://github.com/ok32/esp-rs-ble-miscomp/blob/master/debug_stuff/log_fail.txt
What's in the log when it's ok (with the patch)': https://github.com/ok32/esp-rs-ble-miscomp/blob/master/debug_stuff/log_ok.txt

Anybody has any ideas what can be causing this and how to debug it further?

@ivmarkov
Copy link
Collaborator

@ok32 If you suspect miscompilation, we better ping @MabezDev as he is having the best grasp of the xtensa backlend.

@Vollbrecht Vollbrecht added the bug Something isn't working label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

3 participants