Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

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

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR49562
Status NEW
Importance P enhancement
Reported by John Paul Adrian Glaubitz (glaubitz@physik.fu-berlin.de)
Reported on 2021-03-12 09:50:08 -0800
Last modified on 2021-03-12 12:46:53 -0800
Version trunk
Hardware PC Linux
CC jrtc27@jrtc27.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk, ro@gcc.gnu.org
Fixed by commit(s)
Attachments
Blocks PR48650
Blocked by
See also
Test case:

glaubitz@gcc202:~$ cat test.c
#include <stdio.h>
#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:~$
Quuxplusone 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:~$
Quuxplusone commented 3 years ago

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