llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.86k stars 11.91k forks source link

WORDSIZE is incorrectly defined as 64 on Linux SPARC with -mcpu=v9 and -m32 #48906

Closed glaubitz closed 2 years ago

glaubitz commented 3 years ago
Bugzilla Link 49562
Version trunk
OS Linux
Blocks llvm/llvm-project#47994
CC @jrtc27,@zygoloid,@rorth

Extended Description

Test case:

glaubitz@gcc202:~$ cat test.c

include

include <bits/wordsize.h>

int main () {

if __WORDSIZE == 32

    printf("Hello 32-bit World!\n");

elif __WORDSIZE == 64

    printf("Hello 64-bit World!\n");

endif

    return 0;

}

With gcc:

glaubitz@gcc202:~$ gcc test.c -o test -m32 -mcpu=v9 glaubitz@gcc202:~$ file test test: ELF 32-bit MSB pie executable, SPARC32PLUS, V8+ Required, total store ordering, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, BuildID[sha1]=e29c566d1d767ede628ff31e5a32df089341caea, for GNU/Linux 3.2.0, not stripped glaubitz@gcc202:~$ ./test Hello 32-bit World! glaubitz@gcc202:~$

With clang:

glaubitz@gcc202:~$ llvm-project/stage1.install/bin/clang test.c -o test -m32 -mcpu=v9 glaubitz@gcc202:~$ file test test: ELF 32-bit MSB executable, SPARC32PLUS, V8+ Required, total store ordering, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 3.2.0, not stripped glaubitz@gcc202:~$ ./test Hello 64-bit World! glaubitz@gcc202:~$

glaubitz commented 3 years ago

Reported in glibc as https://sourceware.org/bugzilla/show_bug.cgi?id=27574

glaubitz commented 3 years ago

On a sparc64, in bits/wordsize.h, we have:

if defined arch64 || defined __sparcv9

define __WORDSIZE 64

define __WORDSIZE_TIME64_COMPAT32 1

else

define __WORDSIZE 32

define __WORDSIZE32_SIZE_ULONG 0

define __WORDSIZE32_PTRDIFF_LONG 0

define __WORDSIZE_TIME64_COMPAT32 0

endif

for -mcpu=v9 and -m32, gcc defines:

glaubitz@gcc202:~$ echo | gcc -E -dM -mcpu=v9 -m32 - |grep v9

define __sparc_v9__ 1

glaubitz@gcc202:~$

while clang defines:

glaubitz@gcc202:~$ echo | /home/glaubitz/llvm-project/stage1.install/bin/clang -E -dM -mcpu=v9 -m32 - |grep v9

define __sparc_v9__ 1

define __sparcv9 1

define sparcv9 1

glaubitz@gcc202:~$

brad0 commented 2 years ago

This should be resolved with 14.0.0 and newer.