Skip to content

Linker failure when using times or rename #9051

@jcarrano

Description

@jcarrano

Description

When building for an ARM platform, certain functions in newlib are not implemented and cause a linker error.

Steps to reproduce the issue

Try to compile a program that uses times or rename.

For example:

#include <stdio.h>
#include <sys/times.h>

/*
#include <string.h>
#include <errno.h>
#include <reent.h>

int _link_r(struct _reent *ptr, const char *old_name, const char *new_name)
{
    (void)old_name;
    (void)new_name;

    ptr->_errno = ENOSYS;

    return -1;
}

clock_t _times(struct tms *ptms)
{
    memset(ptms, 0, sizeof(*ptms));

    return 0;
}
*/
int main(void)
{
    struct tms tm;
    clock_t t = times(&tm);

    puts("Hello World!");

    printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
    printf("This board features a(n) %s MCU.\n", RIOT_MCU);
    printf("Time %lu.\n", t);
    rename("/in", "/out");

    puts("renamed!!!");

    return 0;
}

Expected results

Compilation succeeds, even though times may return irrelevant results an rename will alwa

Actual results

Compilation fails at the linker stage with error:

/opt/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/libc_nano.a(lib_a-timesr.o): In function `_times_r':
timesr.c:(.text._times_r+0x2): undefined reference to `_times'
/opt/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m/libc_nano.a(lib_a-linkr.o): In function `_link_r':
linkr.c:(.text._link_r+0xe): undefined reference to `_link'
collect2: error: ld returned 1 exit status

Versions

Operating system: Debian Testing and Stable
Build environment:

  • arm-none-eabi-gcc: arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204]
  • arm-none-eabi-newlib: "2.5.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions