esp_rom: remove functions which depend on sizeof(struct stat)

...and all their callers.

With the upcoming switch from sizeof(time_t)==4 to sizeof(time_t)==8,
sizeof(struct stat) is also increasing.

A few newlib functions present in ROM allocate 'struct stat' on the
stack and call _fstat_r on this structure. The implementation of
fstat is provided in ESP-IDF. This implementation will often do
memset(st, 0, sizeof(*st)), where st is 'struct stat*', before setting
some fields of this structure. If IDF is built with sizeof(st)
different from sizeof(st) which ROM was built with, this will lead
to an out-of-bounds write and a stack corruption.

This commit removes problematic ROM functions from the linker script.
Here are the functions which allocate 'struct stat':
* _isatty_r (in ROM)
* __swhatbuf_r, called by __smakebuf_r, called by __swsetup_r and
  __srefill_r (in ROM)
* _fseeko_r (not in ROM)
* glob2 (not in ROM)
* _gettemp (not in ROM)

As a result, these functions are used from libc.a, and use correct
size of 'stat' structure.

Closes https://github.com/espressif/esp-idf/issues/7980
This commit is contained in:
Ivan Grokhotkov
2022-01-06 15:20:04 +01:00
parent dcfd5187ac
commit f527010044
7 changed files with 67 additions and 23 deletions

View File

@@ -29,7 +29,6 @@ _fwalk_reent = 0x4001bd24;
isalnum = 0x400078d8;
isalpha = 0x400078e8;
isascii = 0x4001aaec;
_isatty_r = 0x400078a0;
isblank = 0x400078f8;
iscntrl = 0x40007918;
isdigit = 0x40007930;
@@ -66,11 +65,9 @@ __sfmoreglue = 0x4001a4c8;
__sfp = 0x4001a590;
__sfp_lock_acquire = 0x4001a508;
__sfp_lock_release = 0x4001a514;
__sfvwrite_r = 0x40001310;
__sinit = 0x4001a538;
__sinit_lock_acquire = 0x4001a520;
__sinit_lock_release = 0x4001a52c;
__smakebuf_r = 0x40001954;
srand = 0x40007a24;
__sread = 0x4001a660;
__sseek = 0x4001a6cc;
@@ -104,9 +101,7 @@ strtok_r = 0x4001af7c;
strupr = 0x40008084;
__swbuf = 0x4000167c;
__swbuf_r = 0x400015bc;
__swhatbuf_r = 0x400018f8;
__swrite = 0x4001a698;
__swsetup_r = 0x40001690;
toascii = 0x4001af90;
tolower = 0x40008158;
toupper = 0x40008174;

View File

@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* These are the newlib functions and the .bss/.data symbols which are related to 'time_t'
or other structures which include 'time_t' (like 'struct stat').
These ROM functions were compiled with sizeof(time_t) == 4.
When compiling with sizeof(time_t) == 8, these functions should be excluded from the build.
*/
__swsetup_r = 0x40001690;
__smakebuf_r = 0x40001954;
__swhatbuf_r = 0x400018f8;
__sfvwrite_r = 0x40001310;
_isatty_r = 0x400078a0;