Use of LTO causes linker to fail due to multiple definitions of compiler RTS functions

XMLWordPrintable

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Medium
    • Code Generation Tools
    • CODEGEN-14672
    • Hide
      ARMCLANG_5.0.0.STS
      ARMCLANG_4.0.4.LTS
      ARMCLANG_5.1.0.LTS
      Show
      ARMCLANG_5.0.0.STS ARMCLANG_4.0.4.LTS ARMCLANG_5.1.0.LTS
    • default
    • Hide
      The root cause of the issue when LTO is enabled and not using --reread_libs or --priority is that the symbol resolution part of the link needs to be completely done before we do the LTO recompile. In the failing use case, after the LTO recompile is done and further symbols remain unresolved, the link will try to find the remaining unresolved symbols in a library search, but in the process may introduce new symbol references that are resolved in a different way than they were resolved in the symbol resolution that happened before the LTO recompile.

      To avoid this problem, you can specify either one or both of the following linker options for the build of the application:

          -Wl,--reread_libs
          -Wl,--priority

      This will ensure that symbol resolution is completely done prior to the LTO recompile.

      The "-Wl,--reread_libs" linker option instructs the linker to re-scan the list of archive files (object libraries) that have been specified in the linker command until either all symbol references have been resolved to a definition or the linker makes a complete scan through all of the object libraries without resolving any of the remaining unresolved symbol references.

      The "-Wl,--priority" linker option instructs the linker to scan all of the input object files first before scanning any of the specified object libraries in the linker command. After the scanning of the input object files, if there are unresolved symbol references remaining, the linker will scan the object libraries in the order that they are specified on the linker command. If any new symbol references are introduced by an object file that is pulled in from an object library into the link, then the search for a definition to resolve that new symbol reference will start from the beginning of the object library list.

      These options are commonly used to avoid the "unresolved symbols remain" error when symbols that are referenced from one library are defined in other libraries.
      Show
      The root cause of the issue when LTO is enabled and not using --reread_libs or --priority is that the symbol resolution part of the link needs to be completely done before we do the LTO recompile. In the failing use case, after the LTO recompile is done and further symbols remain unresolved, the link will try to find the remaining unresolved symbols in a library search, but in the process may introduce new symbol references that are resolved in a different way than they were resolved in the symbol resolution that happened before the LTO recompile. To avoid this problem, you can specify either one or both of the following linker options for the build of the application:     -Wl,--reread_libs     -Wl,--priority This will ensure that symbol resolution is completely done prior to the LTO recompile. The "-Wl,--reread_libs" linker option instructs the linker to re-scan the list of archive files (object libraries) that have been specified in the linker command until either all symbol references have been resolved to a definition or the linker makes a complete scan through all of the object libraries without resolving any of the remaining unresolved symbol references. The "-Wl,--priority" linker option instructs the linker to scan all of the input object files first before scanning any of the specified object libraries in the linker command. After the scanning of the input object files, if there are unresolved symbol references remaining, the linker will scan the object libraries in the order that they are specified on the linker command. If any new symbol references are introduced by an object file that is pulled in from an object library into the link, then the search for a definition to resolve that new symbol reference will start from the beginning of the object library list. These options are commonly used to avoid the "unresolved symbols remain" error when symbols that are referenced from one library are defined in other libraries.

      Extract the attached zip file to an empty directory.  Build it ...

      % tiarmclang @lc.txt
      error: symbol "ldexp" redefined: first defined in
         ".\{CE08F262-89FB-4696-B4B8-3E7DDD12BA40}"; redefined in
         "C:\ti\compilers\ti-cgt-armllvm_4.0.4.LTS\lib\armv7r-ti-none-eabihf/c/libc.a
         <s_scalbn.c.obj>"
      error: symbol "ldexpl" redefined: first defined in
         ".\{CE08F262-89FB-4696-B4B8-3E7DDD12BA40}"; redefined in
         "C:\ti\compilers\ti-cgt-armllvm_4.0.4.LTS\lib\armv7r-ti-none-eabihf/c/libc.a
         <s_scalbn.c.obj>"
      "j721s2_linker_safertos.cmd", line 90: warning: no matching section
      "j721s2_linker_safertos.cmd", line 136: warning: no matching section
      <many more similar diagnostics skipped>
      error: errors encountered during linking; "adc5_spu.elf" not built
      tiarmclang: error: tiarmlnk command failed with exit code 1 (use -v to see invocation)
      

      The function ldexp is from the compiler RTS library. The diagnostic says it is defined in both the LTO temporary file and the compiler RTS library.

      Build with version 3.2.2.LTS and the build succeeds.  (Note the warning diagnostics are still issued.)

            Assignee:
            TI User
            Reporter:
            TI User
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

                Connection: Intermediate to External PROD System
                EXTSYNC-6076 - Use of LTO causes linker to fail du...
                SYNCHRONIZED
                • Last Sync Date: