Skip to content

Failure with Link Time Optimization enabled #66

@unlimitedbacon

Description

@unlimitedbacon

I am trying to use Link Time Optimization (via GCC flag -flto) to reduce binary size. My sketch is too large to fit on the H7's flash otherwise. However, if I enable this then mounting a USB drive always fails.

I am using this library via Arduino_UnifiedStorage > Arduino_POSIXStorage. I don't know enough about how linking works to say whether the problem is really in this library, or one of those. However I was able to trace the issue as far as this section in Arduino_POSIXStorage.cpp.

https://github.com/arduino-libraries/Arduino_POSIXStorage/blob/2b1e7f641bbf565ebcf194cd7d24ecb812e59b63/src/Arduino_POSIXStorage.cpp#L475C1-L486C4

  if (false == (usbHostDevice->connected()))
  {
    if (false == (usbHostDevice->connect()))
    {
      // Only delete if the object was created by this function
      if (false == hotplugKeep)
      {
        deleteDevice(DEV_USB, &usb);
      }
      return ENOTBLK;
    }
  }

usbHostDevice->connect() is returning false.

To try to get more info I set #define DEBUG 4 in dgb.h. Interestingly, with LTO enabled there is no debug output at all. But with LTO off I can see all the debug output over serial and the drive works correctly. This makes me think that USBHostMSD is getting optimized out completely, but I'm not sure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: enhancementProposed improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions