{"id":15693040,"url":"https://github.com/zredshift/esp-spinlock-repro","last_synced_at":"2025-08-08T17:44:37.878Z","repository":{"id":62736361,"uuid":"562112185","full_name":"zRedShift/esp-spinlock-repro","owner":"zRedShift","description":null,"archived":false,"fork":false,"pushed_at":"2022-11-25T19:54:56.000Z","size":266,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-05T14:39:18.594Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zRedShift.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-05T10:54:45.000Z","updated_at":"2022-11-05T11:56:32.000Z","dependencies_parsed_at":"2022-11-05T11:45:28.984Z","dependency_job_id":null,"html_url":"https://github.com/zRedShift/esp-spinlock-repro","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zRedShift%2Fesp-spinlock-repro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zRedShift%2Fesp-spinlock-repro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zRedShift%2Fesp-spinlock-repro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zRedShift%2Fesp-spinlock-repro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zRedShift","download_url":"https://codeload.github.com/zRedShift/esp-spinlock-repro/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246320138,"owners_count":20758407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T18:41:01.603Z","updated_at":"2025-03-30T12:44:00.043Z","avatar_url":"https://github.com/zRedShift.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esp-spinlock-repro\nRunning `cargo espflash --release --monitor` with fat LTO enabled seems to cause the timer driver to misbehave and \nlock the thread up after working as intended beforehand, exactly 256 times.\n\nThis looks like a bug with `CAS` semantics when compiling with fat LTO.\n\nOptimization level doesn't seem to affect the result.\n\nThe serial output should be the following and no more, when compiling with LTO=\"fat\". Other settings result in the \ntimer continuing to work:\n```\ncounter at 0\ncounter at 1\ncounter at 2\ncounter at 3\n\n...\n\ncounter at 253\ncounter at 254\ncounter at 255\ncounter at 256\n \n \n!! A panic occured in 'src/main.rs', at line 7, column 1\n \nPanicInfo {\n    payload: Any { .. },\n    message: Some(\n        called `Option::unwrap()` on a `None` value,\n    ),\n    location: Location {\n        file: \"src/main.rs\",\n        line: 7,\n        col: 1,\n    },\n    can_unwind: true,\n}\n \nBacktrace:\n \n0x42000a1a\n0x42000a1a - esp_spinlock_repro::__xtensa_lx_rt_main\n    at ??:??\n0x420035c4\n0x420035c4 - Reset\n    at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/xtensa-lx-rt-0.13.0/src/lib.rs:77\n0x403785aa\n0x403785aa - ESP32Reset\n    at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/esp32s3-hal-0.3.0/src/lib.rs:233\n0x40000000\n0x40000000 - _external_heap_end\n    at ??:??\n0x403cdb78\n0x403cdb78 - _text_heap_end\n    at ??:??\n0x403c996c\n0x403c996c - _text_heap_end\n    at ??:??\n0x40045c04\n0x40045c04 - rom_config_instruction_cache_mode\n    at ??:??\n0x40043ab9\n0x40043ab9 - rom_config_instruction_cache_mode\n    at ??:??\n0x40034c48\n0x40034c48 - rom_config_instruction_cache_mode\n    at ??:??\n0x40000000\n0x40000000 - _external_heap_end\n    at ??:??\n```\n\nWhereas running `cargo espflash --monitor` results in\n```\ncounter at 0\ncounter at 1\ncounter at 2\ncounter at 3\n\n...\n\ncounter at 253\ncounter at 254\ncounter at 255\ncounter at 256\n\n...\n\n\ncounter at 10000\ncounter at 10001\ncounter at 10002\ncounter at 10003\n\n...\n```\n\n![Disassembly](./images/disassembly.png)\n\nThis was reproduced on ESP32S3 w, using the `esp` rust toolchain, versions `1.64.0.0`, `1.65.0.0`, `1.65.0.1`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzredshift%2Fesp-spinlock-repro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzredshift%2Fesp-spinlock-repro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzredshift%2Fesp-spinlock-repro/lists"}