Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linking issues during LTO #716

Open
christianrauch opened this issue Dec 24, 2023 · 1 comment
Open

linking issues during LTO #716

christianrauch opened this issue Dec 24, 2023 · 1 comment

Comments

@christianrauch
Copy link
Contributor

I am trying to create a Debian package for LibTorch (C++ API for PyTorch) and encounter linking issues that do not appear with the CMake project.

Steps:

  1. Clone the project

    git clone --recurse-submodule https://github.com/pytorch/pytorch.git -b v2.1.2
    cd pytorch
  2. Create a package.xml with content:

    <?xml version="1.0"?>
    <?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
    <package format="3">
      <name>libtorch</name>
      <version>2.1.2</version>
      <description>PyTorch C++ API</description>
      <maintainer email="[email protected]">Christian Rauch</maintainer>
      <license>MIT</license>
    
      <buildtool_depend>cmake</buildtool_depend>
    
      <build_depend>nvidia-cuda</build_depend>
      <build_depend>python3</build_depend>
      <build_depend>python3-yaml</build_depend>
      <build_depend>python3-setuptools</build_depend>
    
      <export>
        <build_type>cmake</build_type>
      </export>
    </package>
  3. Create Debian package:

    bloom-generate rosdebian --ros-distro humble
    fakeroot debian/rules binary

This results in linking errors related to LTO:

[ 97%] Linking CXX shared library ../lib/libtorch_cpu.so
[...]
/tmp/ccPB8088.s: Assembler messages:
/tmp/ccPB8088.s:74: Error: unsupported instruction `mov'
/tmp/ccPB8088.s:107: Error: junk `(%rdi)' after expression
/tmp/ccPB8088.s:195: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:196: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:197: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:224: Error: unsupported instruction `mov'
/tmp/ccPB8088.s:240: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:251: Error: junk `(%rbp)' after expression
/tmp/ccPB8088.s:283: Error: junk `(%rbp)' after expression
/tmp/ccPB8088.s:291: Error: missing ')'
/tmp/ccPB8088.s:291: Error: junk `)' after expression
/tmp/ccPB8088.s:301: Error: junk `(%rbp)' after expression
/tmp/ccPB8088.s:312: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:370: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:379: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:385: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:391: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:427: Error: junk `(%rcx)' after expression
/tmp/ccPB8088.s:436: Error: missing ')'
/tmp/ccPB8088.s:436: Error: junk `)' after expression
/tmp/ccPB8088.s:462: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:476: Error: operand size mismatch for `sal'
/tmp/ccPB8088.s:512: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:542: Error: junk `(%rbp)' after expression
/tmp/ccPB8088.s:560: Error: missing ')'
/tmp/ccPB8088.s:560: Error: junk `)' after expression
/tmp/ccPB8088.s:568: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:570: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:572: Error: junk `(%rbp)' after expression
/tmp/ccPB8088.s:583: Error: junk `(%rax)' after expression
/tmp/ccPB8088.s:585: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:593: Error: missing ')'
/tmp/ccPB8088.s:593: Error: junk `)' after expression
/tmp/ccPB8088.s:596: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:612: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:616: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:623: Error: missing ')'
/tmp/ccPB8088.s:623: Error: junk `)' after expression
/tmp/ccPB8088.s:647: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:649: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:778: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:856: Error: junk `(%rdi)' after expression
/tmp/ccPB8088.s:898: Error: junk `(%rdi)' after expression
/tmp/ccPB8088.s:903: Error: junk `(%rdi)' after expression
/tmp/ccPB8088.s:909: Error: junk `(%rdi)' after expression
/tmp/ccPB8088.s:914: Error: junk `(%rdi)' after expression
/tmp/ccPB8088.s:916: Error: junk `(%rdi)' after expression
/tmp/ccPB8088.s:922: Error: junk `(%rdi)' after expression
/tmp/ccPB8088.s:925: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:930: Error: junk `(%rdi)' after expression
/tmp/ccPB8088.s:943: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:951: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:971: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:986: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:987: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1010: Error: junk `(%rbp)' after expression
/tmp/ccPB8088.s:1011: Error: junk `(%rbp)' after expression
/tmp/ccPB8088.s:1058: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1184: Error: junk `(%rbp)' after expression
/tmp/ccPB8088.s:1188: Error: junk `(%rbp)' after expression
/tmp/ccPB8088.s:1194: Error: junk `(%rax)' after expression
/tmp/ccPB8088.s:1237: Error: junk `(%rax)' after expression
/tmp/ccPB8088.s:1247: Error: junk `(%r13)' after expression
/tmp/ccPB8088.s:1268: Error: junk `(%rbp)' after expression
/tmp/ccPB8088.s:1279: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1281: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1282: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1293: Error: junk `(%r13)' after expression
/tmp/ccPB8088.s:1308: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1309: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1319: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1334: Error: junk `(%r13)' after expression
/tmp/ccPB8088.s:1342: Error: missing ')'
/tmp/ccPB8088.s:1342: Error: junk `)' after expression
/tmp/ccPB8088.s:1352: Error: junk `(%r13)' after expression
/tmp/ccPB8088.s:1363: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1388: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1391: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1406: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1414: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1419: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1420: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1471: Error: junk `(%rcx)' after expression
/tmp/ccPB8088.s:1480: Error: missing ')'
/tmp/ccPB8088.s:1480: Error: junk `)' after expression
/tmp/ccPB8088.s:1486: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1490: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1497: Error: missing ')'
/tmp/ccPB8088.s:1497: Error: junk `)' after expression
/tmp/ccPB8088.s:1513: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1521: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1530: Error: operand size mismatch for `sal'
/tmp/ccPB8088.s:1547: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1578: Error: junk `(%r13)' after expression
/tmp/ccPB8088.s:1598: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1618: Error: missing ')'
/tmp/ccPB8088.s:1618: Error: junk `)' after expression
/tmp/ccPB8088.s:1626: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1628: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1630: Error: junk `(%r13)' after expression
/tmp/ccPB8088.s:1641: Error: junk `(%rax)' after expression
/tmp/ccPB8088.s:1643: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1651: Error: missing ')'
/tmp/ccPB8088.s:1651: Error: junk `)' after expression
/tmp/ccPB8088.s:1654: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1695: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1697: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1723: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1725: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1937: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:1943: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:1952: Error: operand size mismatch for `sal'
/tmp/ccPB8088.s:2023: Error: junk `(%rbx)' after expression
/tmp/ccPB8088.s:2029: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:2038: Error: operand size mismatch for `sal'
/tmp/ccPB8088.s:2078: Error: junk `(%rsp)' after expression
/tmp/ccPB8088.s:2079: Error: junk `(%rbx)' after expression
[...]
make[5]: *** [/tmp/cc7Efm3E.mk:383: /tmp/ccGPxvUX.ltrans127.ltrans.o] Error 1
make[5]: *** [/tmp/cc7Efm3E.mk:380: /tmp/ccGPxvUX.ltrans126.ltrans.o] Error 1
make[5]: *** [/tmp/cc7Efm3E.mk:362: /tmp/ccGPxvUX.ltrans120.ltrans.o] Error 1
lto-wrapper: fatal error: make returned 2 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

However, running the cmake steps manually does work without these issues.

@christianrauch
Copy link
Contributor Author

A workaround would be to disable LTO (https://wiki.debian.org/ToolChain/LTO):

DEB_BUILD_MAINT_OPTIONS=optimize=-lto fakeroot debian/rules binary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant