<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 - check-builtins fails on musl libc system"
   href="https://bugs.llvm.org/show_bug.cgi?id=46628">46628</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>check-builtins fails on musl libc system
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>compiler-rt
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>builtins
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>p.waydan@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23699" name="attach_23699" title="Patch to disable glibc check when using musl">attachment 23699</a> <a href="attachment.cgi?id=23699&action=edit" title="Patch to disable glibc check when using musl">[details]</a></span>
Patch to disable glibc check when using musl

I am cross-compiling the compiler-rt builtins for armv6m on an Alpine Linux
docker image following the
<a href="https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html">https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html</a> guide. The builtins
compile and link successfully but running `ninja check-builtins` emits the
following error:

llvm-lit:
/tmp/llvm-project/build-rt/bin/../../llvm/utils/lit/lit/TestingConfig.py:99:
fatal: unable to parse config file
'/tmp/llvm-project/compiler-rt/test/lit.common.cfg.py', traceback: Traceback
(most recent call last):
  File
"/tmp/llvm-project/build-rt/bin/../../llvm/utils/lit/lit/TestingConfig.py",
line 88, in load_from_path
    exec(compile(data, path, 'exec'), cfg_globals, None)
  File "/tmp/llvm-project/compiler-rt/test/lit.common.cfg.py", line 398, in
<module>
    ver_line = sout.splitlines()[0]
IndexError: list index out of range

I ran lines 394:397 from compiler-rt/test/lit.common.cfg.py by hand and found
that `sout` is an empty string which explains the IndexError. I tried running
`ldd --version` in the terminal, but this command does not exist for the musl
ldd (ld-musl-x86_64.so.1) and output goes to stderr instead of stdout.

I found a workaround to this problem by adding a guard before `ver_line =
sout.splitlines()[0]` to check that the length of sout is greater than zero.
Please see the attached patch.

Cmake options are as follows:
cmake -GNinja ../compiler-rt \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
-DCOMPILER_RT_OS_DIR="baremetal" \
-DCOMPILER_RT_BUILD_BUILTINS=ON \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DCOMPILER_RT_BUILD_PROFILE=OFF \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DCMAKE_C_COMPILER_TARGET="armv6m-none-eabi" \
-DCMAKE_ASM_COMPILER_TARGET="armv6m-none-eabi" \
-DCMAKE_AR=/usr/bin/llvm-ar \
-DCMAKE_NM=/usr/bin/llvm-nm \
-DCMAKE_RANLIB=/usr/bin/llvm-ranlib \
-DCOMPILER_RT_BAREMETAL_BUILD=ON \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DCMAKE_C_FLAGS="-I/tmp/gcc-arm-none-eabi-9-2020-q2-update/arm-none-eabi/include
--target=armv6-none-eabi" \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
-DCMAKE_ASM_FLAGS="" \
-DLLVM_CONFIG_PATH=/usr/bin/llvm-config \
-DLLVM_MAIN_SRC_DIR="../llvm" \
-DCOMPILER_RT_EMULATOR="qemu-arm -L
/tmp/gcc-arm-8.2-2019.01-x86_64-arm-linux-gnueabi/arm-linux-gnueabi/libc" \
-DCOMPILER_RT_INCLUDE_TESTS=ON \
-DCOMPILER_RT_TEST_COMPILER=/usr/bin/clang \
-DCOMPILER_RT_TEST_COMPILER_CFLAGS="--target=arm-linux-gnueabi -march=armv7a
-mthumb -mfloat-abi=soft -mfpu=none -fuse-ld=lld \
--sysroot=/tmp/gcc-arm-8.2-2019.01-x86_64-arm-linux-gnueabi/arm-linux-gnueabi/libc
\
--gcc-toolchain=/tmp/gcc-arm-8.2-2019.01-x86_64-arm-linux-gnueabi"</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>