diff --git a/components/esp_rom/CMakeLists.txt b/components/esp_rom/CMakeLists.txt index c00a7aa28..076621201 100644 --- a/components/esp_rom/CMakeLists.txt +++ b/components/esp_rom/CMakeLists.txt @@ -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 diff --git a/components/esp_rom/component.mk b/components/esp_rom/component.mk index 40f327e24..f4ddad068 100644 --- a/components/esp_rom/component.mk +++ b/components/esp_rom/component.mk @@ -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)) \ diff --git a/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld b/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld index 71e2d9160..642bd6a07 100644 --- a/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld +++ b/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld @@ -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; diff --git a/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld b/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld index a8cf66044..d38e44527 100644 --- a/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld +++ b/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld @@ -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; diff --git a/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs-time.ld b/components/esp_rom/esp32/ld/esp32.rom.newlib-time.ld similarity index 60% rename from components/esp_rom/esp32/ld/esp32.rom.newlib-funcs-time.ld rename to components/esp_rom/esp32/ld/esp32.rom.newlib-time.ld index e773480d2..f6b222eb1 100644 --- a/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs-time.ld +++ b/components/esp_rom/esp32/ld/esp32.rom.newlib-time.ld @@ -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; diff --git a/components/newlib/test/test_newlib.c b/components/newlib/test/test_newlib.c index f0c4216d1..d9692e7c3 100644 --- a/components/newlib/test/test_newlib.c +++ b/components/newlib/test/test_newlib.c @@ -193,3 +193,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); +} \ No newline at end of file