Skip to content

Commit

Permalink
Fix #31 - update README to mention _write and _sbrk for IO retarget
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Jun 16, 2023
1 parent ca76038 commit 2a61ea2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,10 @@ fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
```
Since we've used a newlib stdio function, we need to supply newlib with the rest
of syscalls. Let's add just a simple stubs that do nothing:
Since we've used a newlib stdio function, we need to supply newlib with the
rest of syscalls. We add a simple stubs that do nothing, with exception of
`_sbrk()`. It needs to be implemented, since `printf()` calls `malloc()` which
calls `_sbrk()`:
```c
int _fstat(int fd, struct stat *st) {
Expand All @@ -1192,8 +1194,13 @@ int _fstat(int fd, struct stat *st) {
}
void *_sbrk(int incr) {
(void) incr;
return NULL;
extern char _end;
static unsigned char *heap = NULL;
unsigned char *prev_heap;
if (heap == NULL) heap = (unsigned char *) &_end;
prev_heap = heap;
heap += incr;
return prev_heap;
}
int _close(int fd) {
Expand Down

0 comments on commit 2a61ea2

Please sign in to comment.