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 5d47efb72d
commit 24c20d188e
12 changed files with 103 additions and 48 deletions

View File

@@ -0,0 +1,15 @@
/*
* 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.
*/
_isatty_r = 0x4000126c;
PROVIDE( __smakebuf_r = 0x40001530 );
PROVIDE( __swsetup_r = 0x40001560 );
PROVIDE( __swhatbuf_r = 0x4000153c );

View File

@@ -25,7 +25,6 @@ strncmp = 0x4000123c;
strlen = 0x40001248;
strstr = 0x40001254;
bzero = 0x40001260;
_isatty_r = 0x4000126c;
sbrk = 0x40001278;
isalnum = 0x40001284;
isalpha = 0x40001290;
@@ -84,11 +83,8 @@ PROVIDE( fflush = 0x40001500 );
PROVIDE( _fflush_r = 0x4000150c );
PROVIDE( _fwalk = 0x40001518 );
PROVIDE( _fwalk_reent = 0x40001524 );
PROVIDE( __smakebuf_r = 0x40001530 );
PROVIDE( __swhatbuf_r = 0x4000153c );
PROVIDE( __swbuf_r = 0x40001548 );
__swbuf = 0x40001554;
PROVIDE( __swsetup_r = 0x40001560 );
/* Data (.data, .bss, .rodata) */
syscall_table_ptr = 0x3fceffd4;
_global_impure_ptr = 0x3fceffd0;