Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 12 of 12

Thread: Linker issue about gettimeofday() on Teensy 4.0 with FreeRTOS

  1. #1
    Junior Member
    Join Date
    Aug 2022
    Posts
    11

    Linker issue about gettimeofday() on Teensy 4.0 with FreeRTOS

    Hello,
    I cannot build my code on Teensy 4.0 with core library 1.58.0-beta2

    c:/users/utilisateur/appdata/local/arduino15/packages/teensy/tools/teensy-compile/11.3.1-beta1/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Utilisateur\AppData\Local\Temp\arduino-sketch-4BE4F06CEFDDFAC044404B2337125028/..\arduino-core-cache\core_9fa68f27d5e81ef98338bbff089303f0.a(rtc. c.o): in function `_gettimeofday':
    .......\teensy\hardware\avr\1.58.0-beta2\cores\teensy4/rtc.c:76: multiple definition of `_gettimeofday'; ....\arduino-sketch-4BE4F06CEFDDFAC044404B2337125028\libraries\freerto s-teensy-master\portable\teensy_common.cpp.o:d:\Users\Utili sateur\OneDrive\Documents\Arduino\libraries\freert os-teensy-master\src\portable/teensy_common.cpp:412: first defined here
    collect2.exe: error: ld returned 1 exit status

    This is a new problem, I didn't get it before Teensy core library update.

    My code uses:
    Code:
        #include <Arduino.h>
        #include "arduino_freertos.h"
        #include <ICM_20948.h>
        #include <PWMServo.h>
        #include <SPI.h>
        #include <SD.h>
    Any idea to fix it please?

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Posts
    105
    Install the 1.57 again. Remember that the beta versions seek to improve some aspects, but also usually bring some errors, in this case with the most recent version of the GNU toolchain, comes with some pre-halloween scares

  3. #3
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,668
    Quote Originally Posted by TFTLCDCyg View Post
    Install the 1.57 again. Remember that the beta versions seek to improve some aspects, but also usually bring some errors, in this case with the most recent version of the GNU toolchain, comes with some pre-halloween scares
    Actually the issue isn't with the new toolchain. I believe the issue is related to the addition of a _gettimeofday function added to core via this: https://github.com/PaulStoffregen/co...153bb6532a5727.

    You should probably create an issue on the FreeRTOS github to let them know they need to update their library for the new core.

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Posts
    105
    I think that the new toolchain must have something, since this function: _gettimeofday, was not defined in the previous GNU.

    So I think that some libraries must have it enabled. Is it possible to bypass the use of that GNU toolchain function, to use the custom version of such a function, so that the compiler does not generate a duplicity error?


    In my case this is the error with 1.58-beta2 (with the 1.57 runs fine):

    Code:
    c:/users/w11pc/desktop/arduino-1.8.19   xd xd/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\W11PC\AppData\Local\Temp\arduino_build_795882/..\arduino_cache_583586\core\core_bcca1fd6f87e4a2e726df32b2b3408ee.a(rtc.c.o): in function `_gettimeofday':
    C:\Users\W11PC\Desktop\arduino-1.8.19   XD XD\hardware\teensy\avr\cores\teensy4/rtc.c:76: multiple definition of `_gettimeofday'; C:\Users\W11PC\AppData\Local\Temp\arduino_build_795882\sketch\00_T41_Frio_Servo1.ino.cpp.o:C:\Users\W11PC\Documents\Arduino\libraries\nmealib/nmea.h:22: first defined here
    collect2.exe: error: ld returned 1 exit status
    If I comment out the function in the nmea.h file, the compiler doesn't show the error with loader 1.58-beta2, but I get the error with loader 1.57

    Code:
    c:/arduino-1.8.19/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/fpv5-d16\libc.a(lib_a-gettimeofdayr.o): In function `_gettimeofday_r':
    gettimeofdayr.c:(.text._gettimeofday_r+0x10): undefined reference to `_gettimeofday'
    collect2.exe: error: ld returned 1 exit status

  5. #5
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,668
    Quote Originally Posted by TFTLCDCyg View Post
    I think that the new toolchain must have something, since this function: _gettimeofday, was not defined in the previous GNU.

    So I think that some libraries must have it enabled. Is it possible to bypass the use of that GNU toolchain function, to use the custom version of such a function, so that the compiler does not generate a duplicity error?


    In my case this is the error with 1.58-beta2 (with the 1.57 runs fine):

    Code:
    c:/users/w11pc/desktop/arduino-1.8.19   xd xd/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/11.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\W11PC\AppData\Local\Temp\arduino_build_795882/..\arduino_cache_583586\core\core_bcca1fd6f87e4a2e726df32b2b3408ee.a(rtc.c.o): in function `_gettimeofday':
    C:\Users\W11PC\Desktop\arduino-1.8.19   XD XD\hardware\teensy\avr\cores\teensy4/rtc.c:76: multiple definition of `_gettimeofday'; C:\Users\W11PC\AppData\Local\Temp\arduino_build_795882\sketch\00_T41_Frio_Servo1.ino.cpp.o:C:\Users\W11PC\Documents\Arduino\libraries\nmealib/nmea.h:22: first defined here
    collect2.exe: error: ld returned 1 exit status
    If I comment out the function in the nmea.h file, the compiler doesn't show the error with loader 1.58-beta2, but I get the error with loader 1.57

    Code:
    c:/arduino-1.8.19/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/fpv5-d16\libc.a(lib_a-gettimeofdayr.o): In function `_gettimeofday_r':
    gettimeofdayr.c:(.text._gettimeofday_r+0x10): undefined reference to `_gettimeofday'
    collect2.exe: error: ld returned 1 exit status
    Not sure what nmea library you all are using so can't not give it a try.

    But as a test you could always just comment out the gettimeofday function in the teensy 4 core file: rtc.c , and give it another try.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    17,112
    This from TD 1.58 b1:

    Quote Originally Posted by PaulStoffregen View Post
    I committed include of time.h, at least for testing with 1.58-beta2.

    https://github.com/PaulStoffregen/co...c4b784adb33984

    If this causes too many programs to break or other problems, it may get removed and replaced with some way to define only time_t as the old toolchain did.

  7. #7
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,668
    Quote Originally Posted by TFTLCDCyg View Post
    Install the 1.57 again. Remember that the beta versions seek to improve some aspects, but also usually bring some errors, in this case with the most recent version of the GNU toolchain, comes with some pre-halloween scares
    As a quick test I commented out gettimeofday in the rtc.c in the teensy4 core and the Arduino-freeRtos blick sketch ran with out an issue, i.e., no errors using 1.57-beta2

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,966
    There are a few different FreeRTOS ports. I'm guessing you used this one?

    https://github.com/tsandmann/freertos-teensy

    Looks like it has an implementation of _gettimeofday() in src/portable/teensy_common.cpp at line 419:

    https://github.com/tsandmann/freerto...ommon.cpp#L419

    This will need to be removed or disabled for compatibility with Teensyduino 1.58, since we're now providing this function in Teensy's core library.

    Cleanest way is probably something like this...

    Code:
    #if TEENSYDUINO < 158
    FLASHMEM int _gettimeofday(timeval* tv, void*) {
        const auto now_us { freertos::get_us() };
    #if defined(__has_include) && __has_include("freertos_time.h")
        const auto off { free_rtos_std::wall_clock::get_offset() };
    #else
        const timeval off { 0, 0 };
    #endif
        const timeval now { static_cast<time_t>(now_us / 1'000'000UL), static_cast<suseconds_t>(now_us % 1'000'000UL) };
    
        timeradd(&off, &now, tv);
        return 0;
    }
    #endif

  9. #9
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,668
    Quote Originally Posted by PaulStoffregen View Post
    There are a few different FreeRTOS ports. I'm guessing you used this one?

    https://github.com/tsandmann/freertos-teensy

    Looks like it has an implementation of _gettimeofday() in src/portable/teensy_common.cpp at line 419:

    https://github.com/tsandmann/freerto...ommon.cpp#L419

    This will need to be removed or disabled for compatibility with Teensyduino 1.58, since we're now providing this function in Teensy's core library.

    Cleanest way is probably something like this...

    Code:
    #if TEENSYDUINO < 158
    FLASHMEM int _gettimeofday(timeval* tv, void*) {
        const auto now_us { freertos::get_us() };
    #if defined(__has_include) && __has_include("freertos_time.h")
        const auto off { free_rtos_std::wall_clock::get_offset() };
    #else
        const timeval off { 0, 0 };
    #endif
        const timeval now { static_cast<time_t>(now_us / 1'000'000UL), static_cast<suseconds_t>(now_us % 1'000'000UL) };
    
        timeradd(&off, &now, tv);
        return 0;
    }
    #endif
    Just tried it and compiles with out errors and runs the blink sketch in the freeRTOS library without a problem. T4.1 is blinking and:
    Code:
    Running FreeRTOS kernel V10.5.0. Built by gcc 11.3.1 20220712.
    setup(): starting scheduler...
    TICK
    TOCK
    TICK
    TOCK
    TICK ...
    Be honest forgot that you could test for Teensduino version.

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,966
    Thanks for testing. Could I talk you into sending a pull request?

  11. #11
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,668
    Quote Originally Posted by PaulStoffregen View Post
    Thanks for testing. Could I talk you into sending a pull request?
    PR just created: Avoid Linker issue w/gettimeofday() on Teensy 4.0 #13

  12. #12
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,668
    PR has been incorporated with the following comment from @tsandmann

    Thank you for figuring this out :-)
    The drawback might be a reduced resolution for things that use gettimeofday() like std::chrono or std::thread. But I think it's fine as a workaround, at least as long as Teensyduino 1.58 is still beta.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •