<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Linux kernel build: Regression due memcmp to bcmp optimization"
   href="https://bugs.llvm.org/show_bug.cgi?id=41035">41035</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Linux kernel build: Regression due memcmp to bcmp optimization
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>adhemerval.zanella@linaro.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Revision r355672 [1] introduced a Linux kernel regression build since it Linux
does not build the kernel with -ffreestanding and also it does not provide
bcmp.

The compiler command line issued is:

clang -Wp,-MD,init/.do_mounts.o.d  -nostdinc -isystem
/home/adhemerval.zanella/investigate-llvm-8e16d73346f8091461319a7dfc4ddd18eedcff13/llvm-install/lib/clang/9.0.0/include
-I./arch/arm64/include -I./arch/arm64/include/generated  -I./include
-I./arch/arm64/include/uapi -I./arch/arm64/include/generated/uapi
-I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h
-include ./include/linux/compiler_types.h -D__KERNEL__ -mlittle-endian
-DKASAN_SHADOW_SCALE_SHIFT=3 -Qunused-arguments -Wall -Wundef
-Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common
-fshort-wchar -fno-PIE -Werror-implicit-function-declaration
-Werror=implicit-int -Wno-format-security -std=gnu89 -no-integrated-as
-mgeneral-regs-only -DCONFIG_AS_LSE=1 -fno-asynchronous-unwind-tables
-DKASAN_SHADOW_SCALE_SHIFT=3 -fno-delete-null-pointer-checks -O2
-Wframe-larger-than=2048 -fstack-protector-strong -Wno-format-invalid-specifier
-Wno-gnu -Wno-address-of-packed-member -Wno-tautological-compare
-mno-global-merge -Wno-unused-const-variable -fno-omit-frame-pointer
-fno-optimize-sibling-calls -g -Wdeclaration-after-statement -Wvla
-Wno-pointer-sign -fno-strict-overflow -fno-merge-all-constants
-fno-stack-check -Werror=date-time -Werror=incompatible-pointer-types
-Wno-initializer-overrides -Wno-unused-value -Wno-format -Wno-sign-compare
-Wno-format-zero-length -Wno-uninitialized -fno-function-sections
-fno-data-sections    -DKBUILD_BASENAME='"do_mounts"'
-DKBUILD_MODNAME='"mounts"' -c -o init/do_mounts.o init/do_mounts.c

And the resulting error is:

ld.lld -EL -maarch64elf --no-undefined -X --fix-cortex-a53-843419 --build-id -o
.tmp_vmlinux1 -T ./arch/arm64/kernel/vmlinux.lds --whole-archive built-in.a
--no-whole-archive --start-group arch/arm64/lib/lib.a lib/lib.a --end-group
ld.lld: error: undefined symbol: bcmp
<span class="quote">>>> referenced by do_mounts.c:593 (/home/adhemerval.zanella/investigate-llvm-8e16d73346f8091461319a7dfc4ddd18eedcff13/linux/init/do_mounts.c:593)
>>>               init/do_mounts.o:(prepare_namespace) in archive built-in.a</span >

ld.lld: error: undefined symbol: bcmp
<span class="quote">>>> referenced by do_mounts.c:594 (/home/adhemerval.zanella/investigate-llvm-8e16d73346f8091461319a7dfc4ddd18eedcff13/linux/init/do_mounts.c:594)
>>>               init/do_mounts.o:(prepare_namespace) in archive built-in.a</span >

[...]

This can be fixed on Linux kernel side, but it will require to add
-fno-builtin-bcmp and rollout this on all support releases. However I really
think we should disable such transformation for -nostdinc. Also, as jyknight
has stated on <a href="https://reviews.llvm.org/D56593">https://reviews.llvm.org/D56593</a>, this optimization currently is
also not a performance gain on Linux (on glibc it is a weak alias to memcmp,
while on musl is a tail call to memcmp).


[1] <a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=355672">http://llvm.org/viewvc/llvm-project?view=revision&revision=355672</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>