ARM-software / LLVM-embedded-toolchain-for-Arm

A project dedicated to building LLVM toolchain for Arm and AArch64 embedded targets.
Apache License 2.0
425 stars 98 forks source link

picolib: stdio.h is missing extern "C" #558

Open nolange opened 3 weeks ago

nolange commented 3 weeks ago

This should be fixed since 1.8.7: https://github.com/picolibc/picolibc/commit/c4b55b01f6d8a238e25aa16d28be0f6fe52e0c43

including stdio.h or cstdio will result in subtle to obvious breakage:

#include <stdio.h>

#ifdef FDEV_SETUP_STREAM

namespace {

int sample_putc(char c, FILE *file)
{
    (void) file;        /* Not used in this function */
    // __uart_putc(c);      /* Defined by underlying system */
    return c;
}

int sample_getc(FILE *file)
{
    unsigned char c = '\0';
    (void) file;        /* Not used in this function */
    // c = __uart_getc();   /* Defined by underlying system */
    return c;
}
FILE __stdio = FDEV_SETUP_STREAM(sample_putc,
                    sample_getc,
                    NULL,
                    _FDEV_SETUP_RW);

} // namespace
extern "C" {
FILE *const stdin = &__stdio; __strong_reference(stdin, stdout); __strong_reference(stdin, stderr);
}

#endif // FDEV_SETUP_STREAM
voltur01 commented 3 weeks ago

Hi, this fix should be available in the builds from the main branch now or you can rebuild llvm-19 branch with updated picolibc revision in https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/blob/llvm-19/versions.json