Skip to content

LTO is forcefully enabled instead of by default in the build system #2904

@davidhozic

Description

@davidhozic

Intro

Hi!

I am a student (in a few days researcher) at University of Ljubljana, I use MuJoCo for my research on RL.

My setup

MuJoCo 3.3.7. Other info is irrelevant.

What's happening? What did you expect?

A few CMake files contain forceful set of the CMake variable CMAKE_INTERPROCEDURAL_OPTIMIZATION (LTO).

  • if(NOT CMAKE_INTERPROCEDURAL_OPTIMIZATION AND (CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug"))
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
    endif()
  • if(NOT CMAKE_INTERPROCEDURAL_OPTIMIZATION AND (CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug"))
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
    endif()
  • if(NOT CMAKE_INTERPROCEDURAL_OPTIMIZATION AND (CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug"))
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
    endif()

This causes problems whenever the compiled (static) libraries may be used with a different linker, which is now the case for the Rust language on the default Linux target (they switched to rust-lld).

As a result of the forceful enable, the compiled library files contain additional information that is only compatible with the same linker. See the following issue: rust-lang/rust#146952.

Based on the commit message that added the forceful enable of LTO, the plan was to enable it by default, not permanently.

Several CI files also contain commands where this is explicitly disabled (

-DCMAKE_INTERPROCEDURAL_OPTIMIZATION:BOOL=OFF
), but as the result of the given lines inside CMake option files, nothing changes.

Steps for reproduction

  1. Compile with CMAKE_INTERPROCEDURAL_OPTIMIZATION disabled from the console
  2. CMAKE_INTERPROCEDURAL_OPTIMIZATION (LTO) is still enabled

Minimal model for reproduction

Irrelevant

Code required for reproduction

Irrelevant

Confirmations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions