Hello GNU Tools – Thanks for maintaining a wonderful and efficient toolchain!

I recently discovered a strange behaviour, when using printf from the RX toolchain (Windows version 20.04).

Until now (many versions of GNU toolchains for RX and H8), I have implemented the following 2 functions (overwrite of weak declared library functions) in order to have printf output on a UART.

int _fstat(int filedes, struct stat *buf)
(void)filedes; // Tell compiler not to warn of unused arguments

return 0;

int _write(int file, char* ptr, int len)

// Direct output from printf to service port
UARTWrite(SERVICE_PORT, (unsigned char*)ptr, len);

return len;

That still works fine with no optimisation (-O0)

When I raise optimisation to -O3, linking fails. The following list of functions is not found:

ssize_t read(int fd, void *buf, size_t count);
off_t lseek(int fd, off_t offset, int whence);
int kill(pid_t pid, int sig);
int close(int fd);
int isatty(int fd);
pid_t getpid(void);
int fstat(int filedes, struct stat *buf);
int write(int file, char* ptr, int len);

When I implement those mentioned functions – only write needs to have real functionality – printf works and the program compiles without warnings and errors.

Why does no weak references exist when optimisation is -O3?

Best regards Frank Kjul Larsen

NoMaY-jp answered