newlib: auto-detect sizeof(time_t)
To make the transition from 32-bit time_t to 64-bit time_t smoother, detect the size of this type in CMake and remove the manual option in Kconfig. The information about 64-bit time_t support is moved from Kconfig help string into the "system time" section of the API reference.
This commit is contained in:
@@ -57,6 +57,8 @@ else()
|
||||
rom_linker_script("libgcc")
|
||||
endif()
|
||||
|
||||
idf_build_get_property(time_t_size TIME_T_SIZE)
|
||||
|
||||
if(BOOTLOADER_BUILD)
|
||||
if(target STREQUAL "esp32")
|
||||
rom_linker_script("newlib-funcs")
|
||||
@@ -91,19 +93,20 @@ else() # Regular app build
|
||||
rom_linker_script("syscalls")
|
||||
|
||||
if(NOT CONFIG_SPIRAM_CACHE_WORKAROUND)
|
||||
# ESP32 only: these ROM functions may only be used if PSRAM cache workaround is disabled.
|
||||
# Otherwise we need to link to a multilib version of libc compiled with PSRAM workaround.
|
||||
rom_linker_script("newlib-funcs")
|
||||
if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
|
||||
# If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined
|
||||
# then all time functions from the ROM memory will not be linked.
|
||||
# Instead, those functions can be used from the toolchain by ESP-IDF.
|
||||
|
||||
if(time_t_size EQUAL 4)
|
||||
# The ROM functions listed in this linker script depend on sizeof(time_t).
|
||||
# Since ROM for ESP32 was compiled for 32-bit time_t, only link these functions
|
||||
# if the toolchain is also using 32-bit time_t.
|
||||
rom_linker_script("newlib-time")
|
||||
|
||||
# Include in newlib nano from ROM only if SPIRAM cache workaround is disabled
|
||||
# and sizeof(time_t) == 4
|
||||
if(CONFIG_NEWLIB_NANO_FORMAT)
|
||||
# nano formatting functions in ROM are also built for 32-bit time_t.
|
||||
rom_linker_script("newlib-nano")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -120,52 +123,48 @@ else() # Regular app build
|
||||
rom_linker_script("newlib-data")
|
||||
rom_linker_script("spiflash")
|
||||
|
||||
if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
|
||||
# If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined
|
||||
# then all time functions from the ROM memory will not be linked.
|
||||
# Instead, those functions can be used from the toolchain by ESP-IDF.
|
||||
if(time_t_size EQUAL 4)
|
||||
# The ROM functions listed in this linker script depend on sizeof(time_t).
|
||||
# Since ROM for ESP32-S2 was compiled for 32-bit time_t, only link these functions
|
||||
# if the toolchain is also using 32-bit time_t.
|
||||
rom_linker_script("newlib-time")
|
||||
|
||||
if(CONFIG_NEWLIB_NANO_FORMAT)
|
||||
# nano formatting functions in ROM are also built for 32-bit time_t.
|
||||
rom_linker_script("newlib-nano")
|
||||
endif()
|
||||
|
||||
rom_linker_script("newlib-time")
|
||||
endif()
|
||||
|
||||
|
||||
# descirptors used by ROM code
|
||||
target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_descriptors.c")
|
||||
|
||||
elseif(target STREQUAL "esp32s3")
|
||||
rom_linker_script("newlib")
|
||||
rom_linker_script("version")
|
||||
|
||||
if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
|
||||
# If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined
|
||||
# then all time functions from the ROM memory will not be linked.
|
||||
# Instead, those functions can be used from the toolchain by ESP-IDF.
|
||||
if(time_t_size EQUAL 4)
|
||||
# The ROM functions listed in this linker script depend on sizeof(time_t).
|
||||
# Since ROM for ESP32-S3 was compiled for 32-bit time_t, only link these functions
|
||||
# if the toolchain is also using 32-bit time_t.
|
||||
rom_linker_script("newlib-time")
|
||||
|
||||
if(CONFIG_NEWLIB_NANO_FORMAT)
|
||||
# nano formatting functions in ROM are also built for 32-bit time_t.
|
||||
rom_linker_script("newlib-nano")
|
||||
endif()
|
||||
|
||||
rom_linker_script("newlib-time")
|
||||
endif()
|
||||
|
||||
elseif(target STREQUAL "esp32c3")
|
||||
rom_linker_script("newlib")
|
||||
rom_linker_script("version")
|
||||
|
||||
if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
|
||||
# If SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is defined
|
||||
# then all time functions from the ROM memory will not be linked.
|
||||
# Instead, those functions can be used from the toolchain by ESP-IDF.
|
||||
if(time_t_size EQUAL 4)
|
||||
# The ROM functions listed in this linker script depend on sizeof(time_t).
|
||||
# Since ROM for ESP32-C3 was compiled for 32-bit time_t, only link these functions
|
||||
# if the toolchain is also using 32-bit time_t.
|
||||
rom_linker_script("newlib-time")
|
||||
|
||||
if(CONFIG_NEWLIB_NANO_FORMAT)
|
||||
# nano formatting functions in ROM are also built for 32-bit time_t.
|
||||
rom_linker_script("newlib-nano")
|
||||
endif()
|
||||
|
||||
rom_linker_script("newlib-time")
|
||||
endif()
|
||||
|
||||
if(CONFIG_ESP32C3_REV_MIN_3)
|
||||
@@ -176,10 +175,10 @@ else() # Regular app build
|
||||
rom_linker_script("newlib")
|
||||
rom_linker_script("version")
|
||||
|
||||
if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
|
||||
if(CONFIG_NEWLIB_NANO_FORMAT)
|
||||
rom_linker_script("newlib-nano")
|
||||
endif()
|
||||
if(CONFIG_NEWLIB_NANO_FORMAT AND time_t_size EQUAL 4)
|
||||
# nano formatting functions in ROM are built for 32-bit time_t,
|
||||
# only link them if the toolchain is also using 32-bit time_t and nano formatting was requested.
|
||||
rom_linker_script("newlib-nano")
|
||||
endif()
|
||||
|
||||
elseif(target STREQUAL "esp8684")
|
||||
@@ -187,10 +186,10 @@ else() # Regular app build
|
||||
rom_linker_script("version")
|
||||
rom_linker_script("mbedtls")
|
||||
|
||||
if(NOT CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS)
|
||||
if(CONFIG_NEWLIB_NANO_FORMAT)
|
||||
rom_linker_script("newlib-nano")
|
||||
endif()
|
||||
if(CONFIG_NEWLIB_NANO_FORMAT AND time_t_size EQUAL 4)
|
||||
# nano formatting functions in ROM are built for 32-bit time_t,
|
||||
# only link them if the toolchain is also using 32-bit time_t and nano formatting was requested.
|
||||
rom_linker_script("newlib-nano")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "unity.h"
|
||||
#include "driver/adc.h"
|
||||
@@ -446,8 +447,7 @@ TEST_CASE("test posix_timers clock_... functions", "[newlib]")
|
||||
test_posix_timers_clock();
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS
|
||||
#include <string.h>
|
||||
#ifndef _USE_LONG_TIME_T
|
||||
|
||||
static struct timeval get_time(const char *desc, char *buffer)
|
||||
{
|
||||
@@ -533,7 +533,7 @@ TEST_CASE("test time functions wide 64 bits", "[newlib]")
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS
|
||||
#endif // !_USE_LONG_TIME_T
|
||||
|
||||
#if defined( CONFIG_ESP_TIME_FUNCS_USE_ESP_TIMER ) && defined( CONFIG_ESP_TIME_FUNCS_USE_RTC_TIMER )
|
||||
|
||||
|
||||
@@ -1,16 +1,8 @@
|
||||
// Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
@@ -37,12 +29,6 @@
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS
|
||||
_Static_assert(sizeof(time_t) == 8, "The toolchain does not support time_t wide 64-bits");
|
||||
#else
|
||||
_Static_assert(sizeof(time_t) == 4, "The toolchain supports time_t wide 64-bits. Please enable CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS.");
|
||||
#endif
|
||||
|
||||
#if !CONFIG_ESP_TIME_FUNCS_USE_NONE
|
||||
#define IMPL_NEWLIB_TIME_FUNCS 1
|
||||
#endif
|
||||
|
||||
@@ -133,8 +133,8 @@ menu "SPIFFS Configuration"
|
||||
If the chip already has the spiffs image with the time field = 32 bits
|
||||
then this option cannot be applied in this case.
|
||||
Erase it first before using this option.
|
||||
To resolve the Y2K38 problem for the spiffs, use a toolchain with support
|
||||
time_t 64 bits (see SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS).
|
||||
To resolve the Y2K38 problem for the spiffs, use a toolchain with
|
||||
64-bit time_t support.
|
||||
|
||||
menu "Debug Configuration"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user