Skip to content

feat: add libc rom linker files #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion example/stub_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdint.h>
#include <stdarg.h>
#include <stddef.h>
#include <string.h>

#include <esp-stub-lib/log.h>
#include <esp-stub-lib/flash.h>
Expand Down Expand Up @@ -48,7 +49,9 @@ static __attribute__((unused)) int handle_test2(va_list ap)
{
(void)ap;

STUB_LOG("test2\n");
char buf[10];
strcpy(buf, "test2\n");
STUB_LOG(buf);

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ target_include_directories(${ESP_TARGET_LIB}
)

target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32.rom.ld)
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32.rom.libc-funcs.ld)
74 changes: 74 additions & 0 deletions src/esp32/ld/esp32.rom.libc-funcs.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* These are the newlib functions present in ESP32 ROM.
They should not be used when compiling with PSRAM cache workaround enabled.
See also esp32.rom.newlib-data.ld for the list of .data/.bss symbols
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erhankur @antmak Looks like for esp32s2 we also need esp32.rom.newlib-data.ld
with symbols used by these functions. If functions used by stub does not need these symbols so we need to update these header comment.

used by these functions, and esp32.rom.newlib-nano.ld for "nano" versions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove esp32.rom.newlib-nano.ld reference

of printf/scanf family of functions.

Unlike other ROM functions which are exported using PROVIDE, which declares
weak symbols, newlib related functions are exported using assignment,
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-time.ld file.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have no esp32.rom.newlib-time.ld in the lib

*/

abs = 0x40056340;
bzero = 0x4000c1f4;
div = 0x40056348;
__dummy_lock = 0x4000c728;
__dummy_lock_try = 0x4000c730;
isalnum = 0x40000f04;
isalpha = 0x40000f18;
isascii = 0x4000c20c;
isblank = 0x40000f2c;
iscntrl = 0x40000f50;
isdigit = 0x40000f64;
isgraph = 0x40000f94;
islower = 0x40000f78;
isprint = 0x40000fa8;
ispunct = 0x40000fc0;
isspace = 0x40000fd4;
isupper = 0x40000fe8;
__itoa = 0x40056678;
itoa = 0x400566b4;
labs = 0x40056370;
ldiv = 0x40056378;
longjmp = 0x400562cc;
memccpy = 0x4000c220;
memchr = 0x4000c244;
memcmp = 0x4000c260;
memcpy = 0x4000c2c8;
memmove = 0x4000c3c0;
memrchr = 0x4000c400;
memset = 0x4000c44c;
qsort = 0x40056424;
__sccl = 0x4000c498;
setjmp = 0x40056268;
strcasecmp = 0x400011cc;
strcasestr = 0x40001210;
strcat = 0x4000c518;
strchr = 0x4000c53c;
strcmp = 0x40001274;
strcoll = 0x40001398;
strcpy = 0x400013ac;
strcspn = 0x4000c558;
strlcat = 0x40001470;
strlcpy = 0x4000c584;
strlen = 0x400014c0;
strlwr = 0x40001524;
strncasecmp = 0x40001550;
strncat = 0x4000c5c4;
strncmp = 0x4000c5f4;
strncpy = 0x400015d4;
strnlen = 0x4000c628;
strrchr = 0x40001708;
strsep = 0x40001734;
strspn = 0x4000c648;
strstr = 0x4000c674;
strupr = 0x4000174c;
__submore = 0x40058f3c;
toascii = 0x4000c720;
tolower = 0x40001868;
toupper = 0x40001884;
__utoa = 0x400561f0;
utoa = 0x40056258;
1 change: 1 addition & 0 deletions src/esp32c2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ target_include_directories(${ESP_TARGET_LIB}
)

target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c2.rom.ld)
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c2.rom.libc.ld)
6 changes: 0 additions & 6 deletions src/esp32c2/ld/esp32c2.rom.ld
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

/* ROM function interface esp32c2.rom.ld for esp32c2
*
*
Expand Down
85 changes: 85 additions & 0 deletions src/esp32c2/ld/esp32c2.rom.libc.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
esp_rom_newlib_init_common_mutexes = 0x40000484;
memset = 0x40000488;
memcpy = 0x4000048c;
memmove = 0x40000490;
memcmp = 0x40000494;
strcpy = 0x40000498;
strncpy = 0x4000049c;
strcmp = 0x400004a0;
strncmp = 0x400004a4;
strlen = 0x400004a8;
strstr = 0x400004ac;
bzero = 0x400004b0;
sbrk = 0x400004b8;
isalnum = 0x400004bc;
isalpha = 0x400004c0;
isascii = 0x400004c4;
isblank = 0x400004c8;
iscntrl = 0x400004cc;
isdigit = 0x400004d0;
islower = 0x400004d4;
isgraph = 0x400004d8;
isprint = 0x400004dc;
ispunct = 0x400004e0;
isspace = 0x400004e4;
isupper = 0x400004e8;
toupper = 0x400004ec;
tolower = 0x400004f0;
toascii = 0x400004f4;
memccpy = 0x400004f8;
memchr = 0x400004fc;
memrchr = 0x40000500;
strcasecmp = 0x40000504;
strcasestr = 0x40000508;
strcat = 0x4000050c;
strchr = 0x40000514;
strcspn = 0x40000518;
strcoll = 0x4000051c;
strlcat = 0x40000520;
strlcpy = 0x40000524;
strlwr = 0x40000528;
strncasecmp = 0x4000052c;
strncat = 0x40000530;
strnlen = 0x40000538;
strrchr = 0x4000053c;
strsep = 0x40000540;
strspn = 0x40000544;
strtok_r = 0x40000548;
strupr = 0x4000054c;
longjmp = 0x40000550;
setjmp = 0x40000554;
abs = 0x40000558;
div = 0x4000055c;
labs = 0x40000560;
ldiv = 0x40000564;
qsort = 0x40000568;
utoa = 0x40000578;
itoa = 0x4000057c;
__match = 0x400005dc;
__hexnan = 0x400005e0;
__hexdig_fun = 0x400005e4;
__gethex = 0x400005e8;
_Balloc = 0x400005ec;
_Bfree = 0x400005f0;
__multadd = 0x400005f4;
__s2b = 0x400005f8;
__hi0bits = 0x400005fc;
__lo0bits = 0x40000600;
__i2b = 0x40000604;
__multiply = 0x40000608;
__pow5mult = 0x4000060c;
__lshift = 0x40000610;
__mcmp = 0x40000614;
__mdiff = 0x40000618;
__ulp = 0x4000061c;
__b2d = 0x40000620;
__d2b = 0x40000624;
__ratio = 0x40000628;
_mprec_log10 = 0x4000062c;
__copybits = 0x40000630;
__any_on = 0x40000634;
nan = 0x40000668;
nanf = 0x4000066c;
/* Data (.data, .bss, .rodata) */
syscall_table_ptr = 0x3fcdffd8;
_global_impure_ptr = 0x3fcdffd4;
1 change: 1 addition & 0 deletions src/esp32c3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ target_include_directories(${ESP_TARGET_LIB}
)

target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c3.rom.ld)
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c3.rom.libc.ld)
60 changes: 60 additions & 0 deletions src/esp32c3/ld/esp32c3.rom.libc.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
esp_rom_newlib_init_common_mutexes = 0x40000350;
memset = 0x40000354;
memcpy = 0x40000358;
memmove = 0x4000035c;
memcmp = 0x40000360;
strcpy = 0x40000364;
strncpy = 0x40000368;
strcmp = 0x4000036c;
strncmp = 0x40000370;
strlen = 0x40000374;
strstr = 0x40000378;
bzero = 0x4000037c;
sbrk = 0x40000384;
isalnum = 0x40000388;
isalpha = 0x4000038c;
isascii = 0x40000390;
isblank = 0x40000394;
iscntrl = 0x40000398;
isdigit = 0x4000039c;
islower = 0x400003a0;
isgraph = 0x400003a4;
isprint = 0x400003a8;
ispunct = 0x400003ac;
isspace = 0x400003b0;
isupper = 0x400003b4;
toupper = 0x400003b8;
tolower = 0x400003bc;
toascii = 0x400003c0;
memccpy = 0x400003c4;
memchr = 0x400003c8;
memrchr = 0x400003cc;
strcasecmp = 0x400003d0;
strcasestr = 0x400003d4;
strcat = 0x400003d8;
strchr = 0x400003e0;
strcspn = 0x400003e4;
strcoll = 0x400003e8;
strlcat = 0x400003ec;
strlcpy = 0x400003f0;
strlwr = 0x400003f4;
strncasecmp = 0x400003f8;
strncat = 0x400003fc;
strnlen = 0x40000404;
strrchr = 0x40000408;
strsep = 0x4000040c;
strspn = 0x40000410;
strtok_r = 0x40000414;
strupr = 0x40000418;
longjmp = 0x4000041c;
setjmp = 0x40000420;
abs = 0x40000424;
div = 0x40000428;
labs = 0x4000042c;
ldiv = 0x40000430;
qsort = 0x40000434;
utoa = 0x40000444;
itoa = 0x40000448;
/* Data (.data, .bss, .rodata) */
syscall_table_ptr = 0x3fcdffe0;
_global_impure_ptr = 0x3fcdffdc;
1 change: 1 addition & 0 deletions src/esp32c5/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ target_include_directories(${ESP_TARGET_LIB}
)

target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c5.rom.ld)
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c5.rom.libc.ld)
60 changes: 60 additions & 0 deletions src/esp32c5/ld/esp32c5.rom.libc.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
esp_rom_newlib_init_common_mutexes = 0x400004b4;
memset = 0x400004b8;
memcpy = 0x400004bc;
memmove = 0x400004c0;
memcmp = 0x400004c4;
strcpy = 0x400004c8;
strncpy = 0x400004cc;
strcmp = 0x400004d0;
strncmp = 0x400004d4;
strlen = 0x400004d8;
strstr = 0x400004dc;
bzero = 0x400004e0;
sbrk = 0x400004e8;
isalnum = 0x400004ec;
isalpha = 0x400004f0;
isascii = 0x400004f4;
isblank = 0x400004f8;
iscntrl = 0x400004fc;
isdigit = 0x40000500;
islower = 0x40000504;
isgraph = 0x40000508;
isprint = 0x4000050c;
ispunct = 0x40000510;
isspace = 0x40000514;
isupper = 0x40000518;
toupper = 0x4000051c;
tolower = 0x40000520;
toascii = 0x40000524;
memccpy = 0x40000528;
memchr = 0x4000052c;
memrchr = 0x40000530;
strcasecmp = 0x40000534;
strcasestr = 0x40000538;
strcat = 0x4000053c;
strchr = 0x40000544;
strcspn = 0x40000548;
strcoll = 0x4000054c;
strlcat = 0x40000550;
strlcpy = 0x40000554;
strlwr = 0x40000558;
strncasecmp = 0x4000055c;
strncat = 0x40000560;
strnlen = 0x40000568;
strrchr = 0x4000056c;
strsep = 0x40000570;
strspn = 0x40000574;
strtok_r = 0x40000578;
strupr = 0x4000057c;
longjmp = 0x40000580;
setjmp = 0x40000584;
abs = 0x40000588;
div = 0x4000058c;
labs = 0x40000590;
ldiv = 0x40000594;
qsort = 0x40000598;
utoa = 0x400005a8;
itoa = 0x400005ac;
/* Data (.data, .bss, .rodata) */
syscall_table_ptr = 0x4085ffd4;
_global_impure_ptr = 0x4085ffd0;
1 change: 1 addition & 0 deletions src/esp32c6/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ target_include_directories(${ESP_TARGET_LIB}
)

target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c6.rom.ld)
target_link_options(${ESP_TARGET_LIB} PUBLIC -T${CMAKE_CURRENT_LIST_DIR}/ld/esp32c6.rom.libc.ld)
60 changes: 60 additions & 0 deletions src/esp32c6/ld/esp32c6.rom.libc.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
esp_rom_newlib_init_common_mutexes = 0x400004a4;
memset = 0x400004a8;
memcpy = 0x400004ac;
memmove = 0x400004b0;
memcmp = 0x400004b4;
strcpy = 0x400004b8;
strncpy = 0x400004bc;
strcmp = 0x400004c0;
strncmp = 0x400004c4;
strlen = 0x400004c8;
strstr = 0x400004cc;
bzero = 0x400004d0;
sbrk = 0x400004d8;
isalnum = 0x400004dc;
isalpha = 0x400004e0;
isascii = 0x400004e4;
isblank = 0x400004e8;
iscntrl = 0x400004ec;
isdigit = 0x400004f0;
islower = 0x400004f4;
isgraph = 0x400004f8;
isprint = 0x400004fc;
ispunct = 0x40000500;
isspace = 0x40000504;
isupper = 0x40000508;
toupper = 0x4000050c;
tolower = 0x40000510;
toascii = 0x40000514;
memccpy = 0x40000518;
memchr = 0x4000051c;
memrchr = 0x40000520;
strcasecmp = 0x40000524;
strcasestr = 0x40000528;
strcat = 0x4000052c;
strchr = 0x40000534;
strcspn = 0x40000538;
strcoll = 0x4000053c;
strlcat = 0x40000540;
strlcpy = 0x40000544;
strlwr = 0x40000548;
strncasecmp = 0x4000054c;
strncat = 0x40000550;
strnlen = 0x40000558;
strrchr = 0x4000055c;
strsep = 0x40000560;
strspn = 0x40000564;
strtok_r = 0x40000568;
strupr = 0x4000056c;
longjmp = 0x40000570;
setjmp = 0x40000574;
abs = 0x40000578;
div = 0x4000057c;
labs = 0x40000580;
ldiv = 0x40000584;
qsort = 0x40000588;
utoa = 0x40000598;
itoa = 0x4000059c;
/* Data (.data, .bss, .rodata) */
syscall_table_ptr = 0x4087ffd4;
_global_impure_ptr = 0x4087ffd0;
Loading