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

stdatomic.h incompatible with PSRAM (IDFGH-2549) #4635

Closed
szmodz opened this issue Jan 16, 2020 · 4 comments
Closed

stdatomic.h incompatible with PSRAM (IDFGH-2549) #4635

szmodz opened this issue Jan 16, 2020 · 4 comments
Assignees
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@szmodz
Copy link

szmodz commented Jan 16, 2020

GCC atomic builtins are not compatible with PSRAM addresses, as they rely on s32c1i.

This in turn makes the compiler incompatible with the C standard (stdatomic.h), and will cause difficult to find problems with valid, standard C code.

Worst part is, using stdatomic.h with PSRAM will not cause any exceptions. It will simply result in difficult to find race conditions.

esp-idf is also affected by this issue. Examples include the ethernet and SPI drivers.

esp_err_t esp_eth_increase_reference(esp_eth_handle_t hdl)

esp_eth_driver_t *eth_driver = calloc(1, sizeof(esp_eth_driver_t));

(no MALLOC_CAP_INTERNAL)

spihost[host]=malloc(sizeof(spi_host_t));

(also no MALLOC_CAP_INTERNAL)

atomic_compare_exchange_weak(&host->acquire_cs, &no_cs, handle->id);

@github-actions github-actions bot changed the title stdatomic.h incompatible with PSRAM stdatomic.h incompatible with PSRAM (IDFGH-2549) Jan 16, 2020
@szmodz
Copy link
Author

szmodz commented Jan 16, 2020

#include <stdatomic.h>

void xfaa(atomic_int *x) {
    atomic_fetch_add(x, 1);
}

xtensa-esp32-elf-gcc -O2 -std=gnu11 -S test.c

	.file	"test.c"
	.text
	.align	4
	.global	xfaa
	.type	xfaa, @function
xfaa:
	entry	sp, 32
	memw
	l32i.n	a8, a2, 0
.L2:
	mov.n	a9, a8
	addi.n	a10, a8, 1
	wsr	a8, SCOMPARE1
	s32c1i	a10, a2, 0        <----------------
	mov.n	a8, a10
	bne	a10, a9, .L2
	retw.n
	.size	xfaa, .-xfaa
	.ident	"GCC: (crosstool-NG esp-2019r2) 8.2.0"

comment regarding s32c1i in esp-idf source (as no other documentation is available):

@suda-morris suda-morris added the Type: Bug bugs in IDF label Jan 16, 2020
@suda-morris
Copy link
Collaborator

Thanks @szmodz Well spotted!

@szmodz
Copy link
Author

szmodz commented Jan 22, 2020 via email

espressif-bot pushed a commit that referenced this issue Mar 12, 2020
espressif-bot pushed a commit that referenced this issue Mar 18, 2020
@igrr igrr reopened this May 26, 2020
@Mras2an
Copy link
Contributor

Mras2an commented Sep 9, 2020

Hello,

I think I have this issue on esp-idf 4.0 with a ESP32-WROVER (8mb of RAM)

In file included from /tmp/esp-homekit-sdk/esp-idf/components/esp_eth/src/esp_eth.c:15:0:
/tmp/esp-homekit-sdk/esp-idf/components/newlib/include/stdatomic.h: In function 'atomic_flag_test_and_set_explicit':
/tmp/esp-homekit-sdk/esp-idf/components/newlib/include/stdatomic.h:271:31: error: request for member '__val' in something not a structure or union

Is there any news on it?

thank you

@espressif-bot espressif-bot added Status: In Progress Work is in progress Status: Opened Issue is new and removed Status: In Progress Work is in progress labels May 7, 2021
@espressif-bot espressif-bot assigned Lapshin and unassigned gerekon Jan 11, 2024
@espressif-bot espressif-bot added Status: In Progress Work is in progress Status: Reviewing Issue is being reviewed and removed Status: Opened Issue is new Status: In Progress Work is in progress labels Jan 11, 2024
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: Reviewing Issue is being reviewed labels Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

8 participants