esp_rom: Fix esp32.rom.newlib-time.ld should includes all time ROM functions/data

- Added UT
Closes: https://github.com/espressif/esp-idf/issues/4925
This commit is contained in:
KonstantinKondrashov 2020-03-17 17:02:24 +08:00
parent b3410b9210
commit ae063d96c2
6 changed files with 36 additions and 10 deletions

View file

@ -32,7 +32,7 @@ else() # Regular app build
# 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.
target_linker_script(${COMPONENT_LIB} INTERFACE "esp32/ld/esp32.rom.newlib-funcs-time.ld")
target_linker_script(${COMPONENT_LIB} INTERFACE "esp32/ld/esp32.rom.newlib-time.ld")
endif()
# Include in newlib nano from ROM only if SPIRAM cache workaround is disabled

View file

@ -26,6 +26,13 @@ ifndef CONFIG_SPI_FLASH_ROM_DRIVER_PATCH
LINKER_SCRIPTS += esp32.rom.spiflash.ld
endif
ifndef 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.
LINKER_SCRIPTS += esp32.rom.newlib-time.ld
endif
COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH)/esp32/ld \
$(addprefix -T ,$(LINKER_SCRIPTS)) \

View file

@ -10,14 +10,10 @@
_ctype_ = 0x3ff96354;
__ctype_ptr__ = 0x3ff96350;
_daylight = 0x3ffae0a4;
environ = 0x3ffae0b4;
_global_impure_ptr = 0x3ffae0b0;
__mb_cur_max = 0x3ff96530;
__month_lengths = 0x3ff9609c;
__sf_fake_stderr = 0x3ff96458;
__sf_fake_stdin = 0x3ff96498;
__sf_fake_stdout = 0x3ff96478;
_timezone = 0x3ffae0a0;
_tzname = 0x3ffae030;
__wctomb = 0x3ff96540;

View file

@ -9,7 +9,7 @@
which declares strong symbols. This is done so that ROM functions are always
used instead of the ones provided by libc.a.
Time functions were moved to the esp32.rom.newlib-funcs-time.ld file.
Time functions were moved to the esp32.rom.newlib-time.ld file.
*/
abs = 0x40056340;
@ -126,9 +126,6 @@ __swsetup_r = 0x40058cc8;
toascii = 0x4000c720;
tolower = 0x40001868;
toupper = 0x40001884;
__tzcalc_limits = 0x400018a0;
__tz_lock = 0x40001a04;
__tz_unlock = 0x40001a10;
ungetc = 0x400590f4;
_ungetc_r = 0x40058fa0;
__utoa = 0x400561f0;

View file

@ -1,4 +1,4 @@
/* These are the newlib functions present in ESP32 ROM.
/* These are the newlib functions and the .bss/.data symbols necessary for these functions present in ESP32 ROM.
They should not be used when you need to solve the Y2K38 problem.
Because these functions were compiled with 32-bit width for the time_t structure.
*/
@ -19,3 +19,11 @@ time = 0x40001844;
__time_load_locale = 0x4000183c;
tzset = 0x40001a1c;
_tzset_r = 0x40001a28;
__tzcalc_limits = 0x400018a0;
__tz_lock = 0x40001a04;
__tz_unlock = 0x40001a10;
/* The .bss/.data symbols necessary for these functions */
_timezone = 0x3ffae0a0;
_tzname = 0x3ffae030;
_daylight = 0x3ffae0a4;
__month_lengths = 0x3ff9609c;

View file

@ -187,3 +187,21 @@ TEST_CASE("newlib: can link 'system', 'raise'", "[newlib]")
{
printf("system: %p, raise: %p\n", &system, &raise);
}
TEST_CASE("newlib: rom and toolchain localtime func gives the same result", "[newlib]")
{
// This UNIX time represents 2020-03-12 15:00:00 EDT (19:00 GMT)
// as can be verified with 'date --date @1584039600'
const time_t seconds = 1584039600;
setenv("TZ", "EST5EDT,M3.2.0,M11.1.0", 1); // America/New_York
tzset();
struct tm *tm = localtime(&seconds);
tm->tm_isdst = 1;
static char buf[32];
strftime(buf, sizeof(buf), "%F %T %Z", tm);
static char test_result[64];
sprintf(test_result, "%s (tm_isdst = %d)", buf, tm->tm_isdst);
printf("%s\n", test_result);
TEST_ASSERT_EQUAL_STRING("2020-03-12 15:00:00 EDT (tm_isdst = 1)", test_result);
}