Skip to content

Commit

Permalink
Merge pull request #20719 from maribu/esp32/fix-build-gcc13
Browse files Browse the repository at this point in the history
cpu/esp*: fix compilation with GCC 14.1.0
  • Loading branch information
maribu authored Jun 3, 2024
2 parents a67793d + 784fb5d commit 86e0ca3
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 7 deletions.
55 changes: 48 additions & 7 deletions cpu/esp_common/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string.h>
#include <stdio_ext.h>
#include <sys/unistd.h>
#include <sys/reent.h>

#include "irq_arch.h"
#include "mutex.h"
Expand Down Expand Up @@ -49,6 +50,7 @@
*/
int pthread_setcancelstate(int state, int *oldstate)
{
(void)state;
if (oldstate) {
*oldstate = PTHREAD_CANCEL_DISABLE;
}
Expand Down Expand Up @@ -182,7 +184,9 @@ void IRAM_ATTR _lock_acquire(_lock_t *lock)
assert(*lock != 0);
}

mutex_lock((mutex_t*)*lock);
/* disable warning about increasing cast alignment from 4 to 8 via
* intermediate cast to uintptr_t */
mutex_lock((mutex_t *)(uintptr_t)*lock);
}

void IRAM_ATTR _lock_acquire_recursive(_lock_t *lock)
Expand Down Expand Up @@ -219,7 +223,9 @@ void IRAM_ATTR _lock_acquire_recursive(_lock_t *lock)

_lock_critical_enter();

rmutex_lock((rmutex_t*)*lock);
/* disable warning about increasing cast alignment from 4 to 8 via
* intermediate cast to uintptr_t */
rmutex_lock((rmutex_t *)(uintptr_t)*lock);

_lock_critical_exit();
}
Expand All @@ -243,7 +249,9 @@ int IRAM_ATTR _lock_try_acquire(_lock_t *lock)
assert(*lock != 0);
}

return mutex_trylock((mutex_t*)*lock);
/* disable warning about increasing cast alignment from 4 to 8 via
* intermediate cast to uintptr_t */
return mutex_trylock((mutex_t *)(uintptr_t)*lock);
}

int IRAM_ATTR _lock_try_acquire_recursive(_lock_t *lock)
Expand All @@ -267,7 +275,9 @@ int IRAM_ATTR _lock_try_acquire_recursive(_lock_t *lock)

_lock_critical_enter();

int res = rmutex_trylock((rmutex_t*)*lock);
/* disable warning about increasing cast alignment from 4 to 8 via
* intermediate cast to uintptr_t */
int res = rmutex_trylock((rmutex_t *)(uintptr_t)*lock);

_lock_critical_exit();

Expand All @@ -284,7 +294,9 @@ void IRAM_ATTR _lock_release(_lock_t *lock)
/* the locking variable has to be valid and initialized */
assert(lock != NULL && *lock != 0);

mutex_unlock((mutex_t*)*lock);
/* disable warning about increasing cast alignment from 4 to 8 via
* intermediate cast to uintptr_t */
mutex_unlock((mutex_t *)(uintptr_t)*lock);
}

void IRAM_ATTR _lock_release_recursive(_lock_t *lock)
Expand All @@ -299,7 +311,9 @@ void IRAM_ATTR _lock_release_recursive(_lock_t *lock)

_lock_critical_enter();

rmutex_unlock((rmutex_t*)*lock);
/* disable warning about increasing cast alignment from 4 to 8 via
* intermediate cast to uintptr_t */
rmutex_unlock((rmutex_t *)(uintptr_t)*lock);

_lock_critical_exit();
}
Expand Down Expand Up @@ -440,22 +454,32 @@ void heap_caps_free(void *ptr, const char *file, size_t line)
void* _heap_caps_malloc(size_t size, uint32_t caps, const char *file, size_t line)
{
(void)caps;
(void)file;
(void)line;
return malloc(size);
}

void* _heap_caps_calloc(size_t n, size_t size, uint32_t caps, const char *file, size_t line)
{
(void)caps;
(void)file;
(void)line;
return calloc(n, size);
}

void* _heap_caps_realloc(void *ptr, size_t size, uint32_t caps, const char *file, size_t line)
{
(void)caps;
(void)file;
(void)line;
return realloc(ptr, size);
}

void *_heap_caps_zalloc(size_t size, uint32_t caps, const char *file, size_t line)
{
(void)caps;
(void)file;
(void)line;
void *ptr = malloc(size);
if (ptr) {
memset(ptr, 0, size);
Expand Down Expand Up @@ -490,7 +514,7 @@ unsigned int IRAM_ATTR get_free_heap_size(void)
{
struct mallinfo minfo = mallinfo();
/* cppcheck-suppress comparePointers */
unsigned int heap_size = &_eheap - &_sheap;
uintptr_t heap_size = (uintptr_t)&_eheap - (uintptr_t)&_sheap;
#if NUM_HEAPS > 1
heap_size += &_eheap1 - &_sheap1;
#endif
Expand All @@ -515,21 +539,38 @@ uint32_t esp_get_free_internal_heap_size( void ) __attribute__((alias("get_free_

int _rename_r(struct _reent *r, const char *from, const char *to)
{
(void)r;
(void)from;
(void)to;
return 0;
}

struct _reent* __getreent(void) {
return _GLOBAL_REENT;
}

/* in older versions of newlib, the OS has to allocate a reentry structure */
#ifndef __ATTRIBUTE_IMPURE_DATA__
static struct _reent s_reent;
#endif

void syscalls_init(void)
{
extern void syscalls_init_arch(void);
syscalls_init_arch();

/* _GLOBAL_REENT is a pointer to the reentry structure. In older versions
* of newlib, the OS has to allocate a reentry structure and update
* _GLOBAL_REENT to point to that. In more recent versions, the allocation
* is done by newlib. We use a macro introduced by the commit to detect
* which flavor is used:
*
* See https://github.com/espressif/newlib-esp32/commit/ad51d0006a0aaf17aa61ec34221add09bfe01f0c
* for the commit that introduced the change.
*/
#ifndef __ATTRIBUTE_IMPURE_DATA__
_GLOBAL_REENT = &s_reent;
#endif

environ = malloc(sizeof(char*));
environ[0] = NULL;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 2957d710a61c11d20e9f9fea10a8fb5d7ef94e15 Mon Sep 17 00:00:00 2001
From: Marian Buschsieweke <marian.buschsieweke@posteo.net>
Date: Tue, 13 Feb 2024 13:31:10 +0100
Subject: [PATCH] components/efuse: fix incorrect forward declaration

---
components/efuse/private_include/esp_efuse_utility.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/components/efuse/private_include/esp_efuse_utility.h b/components/efuse/private_include/esp_efuse_utility.h
index 3016d55d..630a3a32 100644
--- a/components/efuse/private_include/esp_efuse_utility.h
+++ b/components/efuse/private_include/esp_efuse_utility.h
@@ -119,7 +119,7 @@ uint32_t esp_efuse_utility_read_reg(esp_efuse_block_t blk, unsigned int num_reg)
/**
* @brief Writing efuse register with checking of repeated programming of programmed bits.
*/
-esp_err_t esp_efuse_utility_write_reg(unsigned int num_reg, esp_efuse_block_t efuse_block, uint32_t reg_to_write);
+esp_err_t esp_efuse_utility_write_reg(esp_efuse_block_t efuse_block, unsigned int num_reg, uint32_t reg_to_write);

/* @brief Reset efuse write registers
*
--
2.43.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From a9d2537cb0a3f0967588b625f44a32dcdef2af52 Mon Sep 17 00:00:00 2001
From: Marian Buschsieweke <marian.buschsieweke@posteo.net>
Date: Sat, 1 Jun 2024 09:31:50 +0200
Subject: [PATCH] components/wpa_supplicant: add missing include

---
components/wpa_supplicant/port/include/os.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/components/wpa_supplicant/port/include/os.h b/components/wpa_supplicant/port/include/os.h
index d00bd6f6..5a67c4e3 100644
--- a/components/wpa_supplicant/port/include/os.h
+++ b/components/wpa_supplicant/port/include/os.h
@@ -18,6 +18,7 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
#include "esp_err.h"
#include "supplicant_opt.h"

--
2.45.1

105 changes: 105 additions & 0 deletions pkg/esp32_sdk/patches/0036-components-fix-calls-to-calloc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
From 3062316cd717b4df3099f40587e37c133195e9ca Mon Sep 17 00:00:00 2001
From: Marian Buschsieweke <marian.buschsieweke@posteo.net>
Date: Sat, 1 Jun 2024 09:59:40 +0200
Subject: [PATCH] components: fix calls to calloc()

The first argument is the number of array members, the second the
member size, not the other way round.

This fixes compilation with `-Werror=calloc-transposed-args`
---
components/app_update/esp_ota_ops.c | 2 +-
components/esp_hw_support/port/esp32/esp_himem.c | 10 +++++-----
components/esp_phy/src/phy_init.c | 2 +-
components/spi_flash/partition.c | 4 ++--
4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/components/app_update/esp_ota_ops.c b/components/app_update/esp_ota_ops.c
index c81dff19..664dd7b3 100644
--- a/components/app_update/esp_ota_ops.c
+++ b/components/app_update/esp_ota_ops.c
@@ -156,7 +156,7 @@ esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp
}
}

- new_entry = (ota_ops_entry_t *) calloc(sizeof(ota_ops_entry_t), 1);
+ new_entry = (ota_ops_entry_t *) calloc(1, sizeof(ota_ops_entry_t));
if (new_entry == NULL) {
return ESP_ERR_NO_MEM;
}
diff --git a/components/esp_hw_support/port/esp32/esp_himem.c b/components/esp_hw_support/port/esp32/esp_himem.c
index 061b2661..45d07f6e 100644
--- a/components/esp_hw_support/port/esp32/esp_himem.c
+++ b/components/esp_hw_support/port/esp32/esp_himem.c
@@ -144,8 +144,8 @@ void __attribute__((constructor)) esp_himem_init(void)
int paddr_end = maxram;
s_ramblockcnt = ((paddr_end - paddr_start) / CACHE_BLOCKSIZE);
//Allocate data structures
- s_ram_descriptor = calloc(sizeof(ramblock_t), s_ramblockcnt);
- s_range_descriptor = calloc(sizeof(rangeblock_t), SPIRAM_BANKSWITCH_RESERVE);
+ s_ram_descriptor = calloc(s_ramblockcnt, sizeof(ramblock_t));
+ s_range_descriptor = calloc(SPIRAM_BANKSWITCH_RESERVE, sizeof(rangeblock_t));
if (s_ram_descriptor == NULL || s_range_descriptor == NULL) {
ESP_EARLY_LOGE(TAG, "Cannot allocate memory for meta info. Not initializing!");
free(s_ram_descriptor);
@@ -188,11 +188,11 @@ esp_err_t esp_himem_alloc(size_t size, esp_himem_handle_t *handle_out)
return ESP_ERR_INVALID_SIZE;
}
int blocks = size / CACHE_BLOCKSIZE;
- esp_himem_ramdata_t *r = calloc(sizeof(esp_himem_ramdata_t), 1);
+ esp_himem_ramdata_t *r = calloc(1, sizeof(esp_himem_ramdata_t));
if (!r) {
goto nomem;
}
- r->block = calloc(sizeof(uint16_t), blocks);
+ r->block = calloc(blocks, sizeof(uint16_t));
if (!r->block) {
goto nomem;
}
@@ -239,7 +239,7 @@ esp_err_t esp_himem_alloc_map_range(size_t size, esp_himem_rangehandle_t *handle
ESP_RETURN_ON_FALSE(s_ram_descriptor != NULL, ESP_ERR_INVALID_STATE, TAG, "Himem not available!");
ESP_RETURN_ON_FALSE(size % CACHE_BLOCKSIZE == 0, ESP_ERR_INVALID_SIZE, TAG, "requested size not aligned to blocksize");
int blocks = size / CACHE_BLOCKSIZE;
- esp_himem_rangedata_t *r = calloc(sizeof(esp_himem_rangedata_t), 1);
+ esp_himem_rangedata_t *r = calloc(1, sizeof(esp_himem_rangedata_t));
if (!r) {
return ESP_ERR_NO_MEM;
}
diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c
index 5be0fa91..71ece1bb 100644
--- a/components/esp_phy/src/phy_init.c
+++ b/components/esp_phy/src/phy_init.c
@@ -625,7 +625,7 @@ void esp_phy_load_cal_and_init(void)
phy_eco_version_sel(esp_efuse_get_chip_ver());
#endif
esp_phy_calibration_data_t* cal_data =
- (esp_phy_calibration_data_t*) calloc(sizeof(esp_phy_calibration_data_t), 1);
+ (esp_phy_calibration_data_t*) calloc(1, sizeof(esp_phy_calibration_data_t));
if (cal_data == NULL) {
ESP_LOGE(TAG, "failed to allocate memory for RF calibration data");
abort();
diff --git a/components/spi_flash/partition.c b/components/spi_flash/partition.c
index d1140ad0..dcd00324 100644
--- a/components/spi_flash/partition.c
+++ b/components/spi_flash/partition.c
@@ -211,7 +211,7 @@ static esp_err_t load_partitions(void)
#endif

// allocate new linked list item and populate it with data from partition table
- partition_list_item_t* item = (partition_list_item_t*) calloc(sizeof(partition_list_item_t), 1);
+ partition_list_item_t* item = (partition_list_item_t*) calloc(1, sizeof(partition_list_item_t));
if (item == NULL) {
err = ESP_ERR_NO_MEM;
break;
@@ -326,7 +326,7 @@ esp_err_t esp_partition_register_external(esp_flash_t* flash_chip, size_t offset
return err;
}

- partition_list_item_t* item = (partition_list_item_t*) calloc(sizeof(partition_list_item_t), 1);
+ partition_list_item_t* item = (partition_list_item_t*) calloc(1, sizeof(partition_list_item_t));
if (item == NULL) {
return ESP_ERR_NO_MEM;
}
--
2.45.1

0 comments on commit 86e0ca3

Please sign in to comment.