<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 - Compiler-rt missing long double builtins for x86_64"
   href="https://bugs.llvm.org/show_bug.cgi?id=39376">39376</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Compiler-rt missing long double builtins for x86_64
          </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>All
          </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>builtins
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>manojgupta@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Chrome OS bug: <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=843822">https://bugs.chromium.org/p/chromium/issues/detail?id=843822</a>


With glibc 2.27, clang cannot compile a static binary with compiler-rt since
compiler-rt does not have support for long double builtins for x86_64.

With glibc 2.27
cat a.c
#include "stdio.h"
int main() {
  printf("hello.\n");
}

 clang -static a.c -rtlib=compiler-rt
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/../../../../lib64/libc.a(printf_fp.o):
In function `__printf_fp_l':
(.text+0x5ea): undefined reference to `__unordtf2'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x/../../../../lib64/libc.a(printf_fphex.o):
In function `__printf_fphex':
(.text+0x9a): undefined reference to `__unordtf2'


The following patch is enough to add the builtins to compiler-rt but not sure
of the correctness or any other implications. Interesting thing to note is that
__LDBL_MANT_DIG__ is 64 so the check __LDBL_MANT_DIG__ == 113 failed on
x86_64/Linux. 

diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt
index 82332967b..c49d9af00 100644
--- a/lib/builtins/CMakeLists.txt
+++ b/lib/builtins/CMakeLists.txt
@@ -232,6 +232,7 @@ set(x86_ARCH_SOURCES

 if (NOT MSVC)
   set(x86_64_SOURCES
+      ${GENERIC_TF_SOURCES}
       x86_64/floatdidf.c
       x86_64/floatdisf.c
       x86_64/floatdixf.c
diff --git a/lib/builtins/fp_lib.h b/lib/builtins/fp_lib.h
index a0e19ab6a..c4f9d1d90 100644
--- a/lib/builtins/fp_lib.h
+++ b/lib/builtins/fp_lib.h
@@ -103,7 +103,7 @@ static __inline void wideMultiply(rep_t a, rep_t b, rep_t
*hi, rep_t *lo) {
 COMPILER_RT_ABI fp_t __adddf3(fp_t a, fp_t b);

 #elif defined QUAD_PRECISION
-#if __LDBL_MANT_DIG__ == 113
+#ifdef __LP64__
 #define CRT_LDBL_128BIT
 typedef __uint128_t rep_t;
 typedef __int128_t srep_t;</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>