# There are differences in binary compiled by the same code on different machines

**URL:** https://discourse.cmake.org/t/there-are-differences-in-binary-compiled-by-the-same-code-on-different-machines/10467
**Category:** Development
**Tags:** os:linux
**Created:** [March 25, 2024, 9:06am UTC](https://discourse.cmake.org/t/there-are-differences-in-binary-compiled-by-the-same-code-on-different-machines/10467 "2024-03-25T09:06:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lxu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lxu/32/4434_2.png) [@lxu](https://discourse.cmake.org/u/lxu)
#### Post date: [March 25, 2024, 9:06am UTC](https://discourse.cmake.org/t/there-are-differences-in-binary-compiled-by-the-same-code-on-different-machines/10467/1 "2024-03-25T09:06:39Z")

</div>

Hi  
I meet a weird issue in the different environments  
I set the environments by

- The same docker image Ubuntu 18.04 LTS
- Mount the same NFS folder which contains the TVM source code
- Use the same user account and .bashrc for the same env variables
- One is based on VMware, one is based on a bare-metal machine with Ubuntu 22.04 LTS
- Use the same config.cmake

I got the result as below:  
In docker on VMware, cmake has not found the llvm

```auto
-- Not found - LLVM_LIBS
-- Fall back to using llvm-config
-- Use llvm-config=/usr/lib/llvm-10/bin/llvm-config
-- Found LLVM_INCLUDE_DIRS=/usr/lib/llvm-10/include
-- Found LLVM_DEFINITIONS=-D_GNU_SOURCE;-D __STDC_CONSTANT_MACROS;-D__ STDC_FORMAT_MACROS;-D__STDC_LIMIT_MACROS
-- Found LLVM_LIBS=/usr/lib/llvm-10/lib/libLLVM-10.so
-- Found TVM_LLVM_VERSION=100
-- Build with LLVM 10.0.0
-- Set TVM_LLVM_VERSION=100
-- Build with contrib.random
-- Build with contrib.sort
-- Build with contrib.hybriddump
-- Build with PACE2 support
-- Git found: /usr/bin/git
-- Found TVM_GIT_COMMIT_HASH=be557109007ecc7a6d822984594b87790160a201
-- Found TVM_GIT_COMMIT_TIME=2024-03-21 10:55:21 +0800
-- Performing Test SUPPORT_CXX17
-- Performing Test SUPPORT_CXX17 - Success
-- Autoset: USE_LIBBACKTRACE=ON in Linux

```

```auto
52680 ./tvm_src/build/libtvm.so
ldd ./tvm_src/build/libtvm.so
        linux-vdso.so.1 (0x00007ffe3126c000)
        libLLVM-10.so.1 => /usr/lib/llvm-10/lib/libLLVM-10.so.1 (0x00007f176abab000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f176a9a7000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f176a61e000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f176a280000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f176a068000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1769e49000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1769a58000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f1771e7e000)
        libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f1769850000)
        libedit.so.2 => /usr/lib/x86_64-linux-gnu/libedit.so.2 (0x00007f1769619000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f17693fc000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f17691f4000)
        libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f1768fca000)

```

In the docker on bare-metal machine

```auto
-- Link with dynamic LLVM library
-- Found LLVM_INCLUDE_DIRS=/usr/lib/llvm-6.0/include
-- Found LLVM_DEFINITIONS=-D_GNU_SOURCE -D __STDC_CONSTANT_MACROS -D__ STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Found LLVM_LIBS=LLVM
-- Found TVM_LLVM_VERSION=60
-- Build with LLVM 6.0.0
-- Set TVM_LLVM_VERSION=60
-- Build with contrib.random
-- Build with contrib.sort
-- Build with contrib.hybriddump
-- Build with PACE2 support
-- Git found: /usr/bin/git
-- Found TVM_GIT_COMMIT_HASH=be557109007ecc7a6d822984594b87790160a201
-- Found TVM_GIT_COMMIT_TIME=2024-03-21 10:55:21 +0800
-- Performing Test SUPPORT_CXX17
-- Performing Test SUPPORT_CXX17 - Success
-- Autoset: USE_LIBBACKTRACE=ON in Linux

```

```auto
52356 ./tvm_src/build/libtvm.so
ldd ./tvm_src/build/libtvm.so
        linux-vdso.so.1 (0x00007fff98bdb000)
        libLLVM-6.0.so.1 => /usr/lib/llvm-6.0/lib/libLLVM-6.0.so.1 (0x00007f7dcfebd000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7dcfcb9000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7dcf930000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7dcf592000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7dcf37a000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7dcf15b000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7dced6a000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f7dd6520000)
        libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f7dceb62000)
        libedit.so.2 => /usr/lib/x86_64-linux-gnu/libedit.so.2 (0x00007f7dce92b000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7dce70e000)
        libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f7dce4e4000) 

```

The initial judgment is that the difference appears in the execution results of find\_package

```auto
  if(${LLVM_CONFIG} MATCHES ${IS_TRUE_PATTERN})
    find_package(LLVM ${llvm_version_required} REQUIRED CONFIG)
    llvm_map_components_to_libnames(LLVM_LIBS "all")
    if (NOT LLVM_LIBS)
      message(STATUS "Not found - LLVM_LIBS")
      message(STATUS "Fall back to using llvm-config")
      set(LLVM_CONFIG "${LLVM_TOOLS_BINARY_DIR}/llvm-config")
    endif()
  endif()

```

I guess that the processing of find\_package is related to the CPU flag, is that true and why?  
The CPU flags of VMware:

```auto
    Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 ds_cpl vmx smx est 
                         tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad 
                         fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect wbnoinvd dtherm 
                         ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities

```

The CPU flags of bare-metal machine

```auto
    Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid avx512f avx512dq rdseed adx smap clflushopt clwb avx512c d avx512bw avx512vl xsaveopt xsavec xsaves arat pku ospke md_clear flush_l1d arch_capabilities

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 11, 2024, 12:27am UTC](https://discourse.cmake.org/t/there-are-differences-in-binary-compiled-by-the-same-code-on-different-machines/10467/2 "2024-04-11T00:27:01Z")

</div>

> [@lxu](#):
>
> - The same docker image Ubuntu 18.04 LTS
> - Mount the same NFS folder which contains the TVM source code
> - Use the same user account and .bashrc for the same env variables
> - One is based on VMware, one is based on a bare-metal machine with Ubuntu 22.04 LTS

The difference is that Ubuntu 22.04 provides LLVM 10 and 18.04 provides LLVM 6. What other differences are you observing?

---

<div class="post-metadata">

### Author: ![lxu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/lxu/32/4434_2.png) [@lxu](https://discourse.cmake.org/u/lxu)
#### Post date: [April 17, 2024, 2:47am UTC](https://discourse.cmake.org/t/there-are-differences-in-binary-compiled-by-the-same-code-on-different-machines/10467/3 "2024-04-17T02:47:06Z")

</div>

I compile the TVM in the same docker environment, both llvm10 and llvm6 exist  
The difference is that the host used to start docker is different, and the hosts are all ubuntu22.04.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 17, 2024, 6:07pm UTC](https://discourse.cmake.org/t/there-are-differences-in-binary-compiled-by-the-same-code-on-different-machines/10467/4 "2024-04-17T18:07:06Z")

</div>

The VM finds LLVM 10 and the bare metal finds LLVM 6. You can use the `--debug-find` flag to have configure log how it ends up with each of these results.

> [@lxu](#):
>
> `-- Build with LLVM 10.0.0`

> [@lxu](#):
>
> `-- Build with LLVM 6.0.0`
