[llvm-bugs] [Bug 40553] New: wrong sizeof(long double) in 32-bit PowerPC NetBSD, OpenBSD

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 31 12:44:44 PST 2019


            Bug ID: 40553
           Summary: wrong sizeof(long double) in 32-bit PowerPC NetBSD,
           Product: clang
           Version: 7.0
          Hardware: Macintosh
                OS: OpenBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kernigh at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Created attachment 21414
  --> https://bugs.llvm.org/attachment.cgi?id=21414&action=edit
sizeof(long double) == 8 in 32-bit PowerPC NetBSD, OpenBSD

clang and gcc are using incompatible formats for long double in my big-endian
32-bit PowerPC machine, a PowerBook G4 running OpenBSD/macppc.  clang 6 and 7
have sizeof(long double) == 16, but gcc has sizeof(long double) == 8.  This
causes a linker error when a program built with clang tries to pass a long
double to a C++ library built with gcc.

NetBSD might have the same problem.  I have qemu running NetBSD/macppc, and its
gcc has sizeof(long double) == 8.  I have not tried to target NetBSD with

clang now uses sizeof(long double) == 8 on FreeBSD; I propose to do the same on
NetBSD and OpenBSD.  The attached patch is for llvm-project.git master.  I am
now using almost the same patch in clang 7.0.1, where the line to check for
FreeBSD was different, but you can apply the attached patch by hand.

This is a simple example of the problem:

$ cat szld.cc
#include <iostream>
void f(long double ld) {
        std::cout << "sizeof(ld) = " << sizeof(ld) << std::endl;
int main() { f(0.0L); }
$ gcc -o szld-gcc szld.cc
$ clang -o szld-clang szld.cc
$ ./szld-gcc
sizeof(ld) = 8
$ ./szld-clang
sizeof(ld) = 16
$ nm -C szld-gcc | grep 'f('
00000798 T f(long double)
$ nm -C szld-clang | grep 'f('
000005a8 T f(__float128)

My OpenBSD/macppc machine has gcc 4.2.1 using libstdc++, gcc 8.2.0 installed as
egcc using libestdc++, and clang 7.0.1 using the same libestdc++ as gcc 8.2.0. 
The linker is GNU ld 2.17.  I got a linker error because KDE's kdiagram, built
with clang, wanted to call something(__float128), but libestdc++, built with
gcc, defined something(long double).

My patch seems to work in clang 7.0.1 (built from devel/llvm in OpenBSD's ports
tree in about 36 hours by my PowerBook G4), but I'm less sure about git master.
 I can't run git master on my best machine (OpenBSD/amd64, 2 cores, 4G RAM).  I
used https://clang.llvm.org/get_started.html but learned the hard way that 4G
RAM is too small to build clang with debug info.  I was able to build git
master this way:

exec cmake \
  -DCMAKE_BUILD_TYPE=MinSizeRel -G Ninja ../llvm
ninja -j2 clang

But I can't run it:

pehcehwahn$ bin/clang-9                                                        
ksh: bin/clang-9: Cannot allocate memory

I now have a 142M bin/clang-9 linked to a 108M lib/libLLVM-9svn.so, but clang-9
might be too big, and I don't know how to make it smaller.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190131/cc679056/attachment.html>

More information about the llvm-bugs mailing list