public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/27574] New: glibc should probably not define __WORDSIZE=64 for __sparcv9
@ 2021-03-12 18:04 glaubitz at physik dot fu-berlin.de
  2024-01-17 13:12 ` [Bug libc/27574] " adhemerval.zanella at linaro dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: glaubitz at physik dot fu-berlin.de @ 2021-03-12 18:04 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27574

            Bug ID: 27574
           Summary: glibc should probably not define __WORDSIZE=64 for
                    __sparcv9
           Product: glibc
           Version: 2.31
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: glaubitz at physik dot fu-berlin.de
                CC: adhemerval.zanella at linaro dot org, drepper.fsp at gmail dot com,
                    jrtc27 at jrtc27 dot com
  Target Milestone: ---

I stumbled about an issue where gcc and clang slightly deviate from each other
when handling 32-bit support in the driver.

The following test case demonstrates the issue:

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:~$

The reason is that glibc defines __WORDSIZE=64 when __sparcv9 is 1:

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:~$

However, when using -mv8plus on gcc - which is clearly a 32-bit target - the
compiler still defines __sparcv9:

glaubitz@gcc202:~$ echo | gcc -E -dM -mv8plus - |grep v9
#define __sparc_v9__ 1
glaubitz@gcc202:~$

So, I think the test in bits/wordsize.h in glibc is incorrect and should rather
test for __arch64__ && __sparc__.

See: https://bugs.llvm.org/show_bug.cgi?id=49562

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/27574] glibc should probably not define __WORDSIZE=64 for __sparcv9
  2021-03-12 18:04 [Bug libc/27574] New: glibc should probably not define __WORDSIZE=64 for __sparcv9 glaubitz at physik dot fu-berlin.de
@ 2024-01-17 13:12 ` adhemerval.zanella at linaro dot org
  2024-01-18  4:59 ` sam at gentoo dot org
  2024-01-22 13:02 ` adhemerval.zanella at linaro dot org
  2 siblings, 0 replies; 4+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2024-01-17 13:12 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27574

--- Comment #1 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
I think it does make sense on sparc64 wordsize to check even define __WORDSIZE
to 64 (since there is no support for x32-like ABI).  It should be only:

#define __WORDSIZE     32
#define __WORDSIZE_TIME64_COMPAT32     0
#define __WORDSIZE32_SIZE_ULONG        0
#define __WORDSIZE32_PTRDIFF_LONG      0

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/27574] glibc should probably not define __WORDSIZE=64 for __sparcv9
  2021-03-12 18:04 [Bug libc/27574] New: glibc should probably not define __WORDSIZE=64 for __sparcv9 glaubitz at physik dot fu-berlin.de
  2024-01-17 13:12 ` [Bug libc/27574] " adhemerval.zanella at linaro dot org
@ 2024-01-18  4:59 ` sam at gentoo dot org
  2024-01-22 13:02 ` adhemerval.zanella at linaro dot org
  2 siblings, 0 replies; 4+ messages in thread
From: sam at gentoo dot org @ 2024-01-18  4:59 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27574

Sam James <sam at gentoo dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gentoo dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/27574] glibc should probably not define __WORDSIZE=64 for __sparcv9
  2021-03-12 18:04 [Bug libc/27574] New: glibc should probably not define __WORDSIZE=64 for __sparcv9 glaubitz at physik dot fu-berlin.de
  2024-01-17 13:12 ` [Bug libc/27574] " adhemerval.zanella at linaro dot org
  2024-01-18  4:59 ` sam at gentoo dot org
@ 2024-01-22 13:02 ` adhemerval.zanella at linaro dot org
  2 siblings, 0 replies; 4+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2024-01-22 13:02 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27574

Adhemerval Zanella <adhemerval.zanella at linaro dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |2.39
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
Fixed on 2.39.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-22 13:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12 18:04 [Bug libc/27574] New: glibc should probably not define __WORDSIZE=64 for __sparcv9 glaubitz at physik dot fu-berlin.de
2024-01-17 13:12 ` [Bug libc/27574] " adhemerval.zanella at linaro dot org
2024-01-18  4:59 ` sam at gentoo dot org
2024-01-22 13:02 ` adhemerval.zanella at linaro dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).