public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "glaubitz at physik dot fu-berlin.de" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/27574] New: glibc should probably not define __WORDSIZE=64 for __sparcv9
Date: Fri, 12 Mar 2021 18:04:17 +0000	[thread overview]
Message-ID: <bug-27574-131@http.sourceware.org/bugzilla/> (raw)

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.

             reply	other threads:[~2021-03-12 18:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12 18:04 glaubitz at physik dot fu-berlin.de [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-27574-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).