LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 48650 - [Sparc] Stage2 fails on Linux CI with "error: cannot apply asm label to function after its first use"
Summary: [Sparc] Stage2 fails on Linux CI with "error: cannot apply asm label to funct...
Status: NEW
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: Sparc (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Unassigned LLVM Bugs
URL: http://lab.llvm.org:8014/#/builders/1...
Keywords:
Depends on: 49562
Blocks:
  Show dependency tree
 
Reported: 2021-01-04 02:48 PST by John Paul Adrian Glaubitz
Modified: 2021-03-12 12:46 PST (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments
Preprocessed source for sanitizer_platform_limits_posix.cpp (426.40 KB, text/plain)
2021-03-10 09:06 PST, John Paul Adrian Glaubitz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description John Paul Adrian Glaubitz 2021-01-04 02:48:09 PST
The stage2 build fails on clang-sparc64-linux-multistage with:

FAILED: projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.sparc.dir/sanitizer_stackdepot.cpp.o 
/var/lib/buildbot/workers/debian-stadler-sparc64/clang-sparc64-linux-multistage/stage1.install/bin/clang++ -DHAVE_RPC_XDR_H=1 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/compiler-rt/lib/sanitizer_common -I/var/lib/buildbot/workers/debian-stadler-sparc64/clang-sparc64-linux-multistage/llvm/compiler-rt/lib/sanitizer_common -Iinclude -I/var/lib/buildbot/workers/debian-stadler-sparc64/clang-sparc64-linux-multistage/llvm/llvm/include -I/var/lib/buildbot/workers/debian-stadler-sparc64/clang-sparc64-linux-multistage/llvm/compiler-rt/lib/sanitizer_common/.. -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -std=c++14 -Wno-unused-parameter -O3   -m32 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -Wframe-larger-than=570 -Wglobal-constructors -DSANITIZER_SUPPORTS_WEAK_HOOKS=0 -UNDEBUG -std=c++14 -MD -MT projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.sparc.dir/sanitizer_stackdepot.cpp.o -MF projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.sparc.dir/sanitizer_stackdepot.cpp.o.d -o projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonSymbolizerNoHooks.sparc.dir/sanitizer_stackdepot.cpp.o -c /var/lib/buildbot/workers/debian-stadler-sparc64/clang-sparc64-linux-multistage/llvm/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
In file included from /var/lib/buildbot/workers/debian-stadler-sparc64/clang-sparc64-linux-multistage/llvm/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp:17:
In file included from /var/lib/buildbot/workers/debian-stadler-sparc64/clang-sparc64-linux-multistage/llvm/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h:16:
In file included from /usr/include/stdio.h:870:
/usr/include/bits/stdio-ldbl.h:26:20: error: cannot apply asm label to function after its first use
__LDBL_REDIR_DECL (vfprintf)
~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/usr/include/sys/cdefs.h:467:26: note: expanded from macro '__LDBL_REDIR_DECL'
  extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
                         ^           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

See: http://lab.llvm.org:8014/#/builders/113/builds/37

The issue has existed for a while but I never actually reported it.
Comment 1 John Paul Adrian Glaubitz 2021-03-10 09:06:59 PST
Created attachment 24615 [details]
Preprocessed source for sanitizer_platform_limits_posix.cpp
Comment 2 Dimitry Andric 2021-03-10 09:40:27 PST
Ah yes, the preprocessed output has:

  5288  extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
  5289         __gnuc_va_list __arg);
... (this is just the declaration, no 'use' yet
  5626  # 1 "/usr/include/bits/stdio.h" 1 3 4
  5627  # 38 "/usr/include/bits/stdio.h" 3 4
  5628  extern __inline __attribute__ ((__gnu_inline__)) int
  5629  vprintf (const char *__restrict __fmt, __gnuc_va_list __arg)
  5630  {
  5631    return vfprintf (stdout, __fmt, __arg);
  5632  }
... so there is the first 'use'
  5735  # 1 "/usr/include/bits/stdio-ldbl.h" 1 3 4
  5736  # 23 "/usr/include/bits/stdio-ldbl.h" 3 4
  5737  extern __typeof (fprintf) fprintf __asm ("" "__nldbl_" "fprintf");
  5738  extern __typeof (printf) printf __asm ("" "__nldbl_" "printf");
  5739  extern __typeof (sprintf) sprintf __asm ("" "__nldbl_" "sprintf");
  5740  extern __typeof (vfprintf) vfprintf __asm ("" "__nldbl_" "vfprintf");
... and here is the part it is complaining about.

The initial declaration is in stdio.h itself, the inline definition of vprintf (which 'uses' vfprintf) in bits/stdio.h, and the asm stuff is in bits/stdio-ldbl.h.

But note, the __asm label thing is done via a __LDBL_REDIR_DECL macro from sys/cdefs.h, and this is only applied in case of:

#if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH

I think this is the reason you only see it on sparc64, as that doesn't have long double math, at least according to the glibc sources:

sysdeps/unix/sysv/linux/sparc/sparc32/bits/long-double.h
21:#if !defined __NO_LONG_DOUBLE_MATH && __WORDSIZE == 32
24:#  define __NO_LONG_DOUBLE_MATH        1

sysdeps/unix/sysv/linux/sparc/sparc64/bits/long-double.h
21:#if !defined __NO_LONG_DOUBLE_MATH && __WORDSIZE == 32
24:#  define __NO_LONG_DOUBLE_MATH        1
Comment 3 John Paul Adrian Glaubitz 2021-03-10 09:51:38 PST
Hmm, that sounds more like a bug in glibc then. Although I don't understand the connection between long double math and the __asm label.
Comment 4 Dimitry Andric 2021-03-10 10:42:23 PST
(In reply to John Paul Adrian Glaubitz from comment #3)
> Hmm, that sounds more like a bug in glibc then. Although I don't understand
> the connection between long double math and the __asm label.

Ah, sys/cdefs.h has this part dealing with it:

#if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
# define __LDBL_COMPAT 1
# ifdef __REDIRECT
#  define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
#  define __LDBL_REDIR(name, proto) \
  __LDBL_REDIR1 (name, proto, __nldbl_##name)
#  define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
#  define __LDBL_REDIR_NTH(name, proto) \
  __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
#  define __LDBL_REDIR1_DECL(name, alias) \
  extern __typeof (name) name __asm (__ASMNAME (#alias));
#  define __LDBL_REDIR_DECL(name) \
  extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
#  define __REDIRECT_LDBL(name, proto, alias) \
  __LDBL_REDIR1 (name, proto, __nldbl_##alias)
#  define __REDIRECT_NTH_LDBL(name, proto, alias) \
  __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
# endif
#endif
#if !defined __LDBL_COMPAT || !defined __REDIRECT
# define __LDBL_REDIR1(name, proto, alias) name proto
# define __LDBL_REDIR(name, proto) name proto
# define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
# define __LDBL_REDIR_NTH(name, proto) name proto __THROW
# define __LDBL_REDIR_DECL(name)
# ifdef __REDIRECT
#  define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
#  define __REDIRECT_NTH_LDBL(name, proto, alias) \
  __REDIRECT_NTH (name, proto, alias)
# endif
#endif

I.e, if long double math is optional (I guess this might be glibc compile time option, but I'm unsure), *and* the platform/arch does not support long double, it defines a bunch of redirection macros. These macros appear to want to alias "foo" to "__nldbl_foo", so any calls to long double functions would end up at stubs that know how to handle them. (I'm unsure whether that will just abort at runtime, or pretend that double is the same as long double.)

Otherwise (if the arch does support long double) these redirection macros are no-ops, and effectively empty.

bits/stdio-ldbl.h then has a __LDBL_REDIR_DECL (vfprintf) line, which uses the above macro, together with a bunch of other stdio functions.

It seems to me a solution could be to move the #include <bits/stdio-ldbl.h> up a bit, so instead of:

/* If we are compiling with optimizing read this file.  It contains
   several optimizing inline functions and macros.  */
#ifdef __USE_EXTERN_INLINES
# include <bits/stdio.h>
#endif
#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
# include <bits/stdio2.h>
#endif
#ifdef __LDBL_COMPAT
# include <bits/stdio-ldbl.h>
#endif

you would get:

/* If we are compiling with optimizing read this file.  It contains
   several optimizing inline functions and macros.  */
#ifdef __LDBL_COMPAT
# include <bits/stdio-ldbl.h>
#endif
#ifdef __USE_EXTERN_INLINES
# include <bits/stdio.h>
#endif
#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
# include <bits/stdio2.h>
#endif
Comment 5 John Paul Adrian Glaubitz 2021-03-10 11:15:11 PST
Reported as a bug in glibc: https://sourceware.org/bugzilla/show_bug.cgi?id=27558
Comment 6 John Paul Adrian Glaubitz 2021-03-10 12:17:42 PST
(In reply to Dimitry Andric from comment #4)
> It seems to me a solution could be to move the #include <bits/stdio-ldbl.h>
> up a bit, so instead of:
> 
> /* If we are compiling with optimizing read this file.  It contains
>    several optimizing inline functions and macros.  */
> #ifdef __USE_EXTERN_INLINES
> # include <bits/stdio.h>
> #endif
> #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
> # include <bits/stdio2.h>
> #endif
> #ifdef __LDBL_COMPAT
> # include <bits/stdio-ldbl.h>
> #endif
> 
> you would get:
> 
> /* If we are compiling with optimizing read this file.  It contains
>    several optimizing inline functions and macros.  */
> #ifdef __LDBL_COMPAT
> # include <bits/stdio-ldbl.h>
> #endif
> #ifdef __USE_EXTERN_INLINES
> # include <bits/stdio.h>
> #endif
> #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
> # include <bits/stdio2.h>
> #endif

This fixes the issue for me although I'm now running into another (unrelated) problem which seems to be a result of a missing libatomic in LDFLAGS:

[9/4273] Linking CXX shared library lib/clang/13.0.0/lib/linux/libclang_rt.ubsan_minimal-sparc.so
FAILED: lib/clang/13.0.0/lib/linux/libclang_rt.ubsan_minimal-sparc.so 
: && /home/glaubitz/llvm-project/build/./bin/clang++ -fPIC -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Werror=return-type -fdiagnostics-color -Wall -std=c++14 -Wno-unused-parameter -g  -Wl,-z,defs -Wl,-z,nodelete   -m32 -nodefaultlibs -Wl,-z,text -nostdlib++ -Wl,-rpath-link,/home/glaubitz/llvm-project/build/tools/clang/stage2-bins/./lib -shared -Wl,-soname,libclang_rt.ubsan_minimal-sparc.so -o lib/clang/13.0.0/lib/linux/libclang_rt.ubsan_minimal-sparc.so projects/compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.sparc.dir/ubsan_minimal_handlers.cpp.o  -Wl,-rpath,"\$ORIGIN/../lib"  -lgcc_s  -lc && :
/usr/bin/ld: projects/compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.sparc.dir/ubsan_minimal_handlers.cpp.o: in function `report_this_error(void*)':
/home/glaubitz/llvm-project/compiler-rt/lib/ubsan_minimal/../sanitizer_common/sanitizer_atomic_clang.h:80: undefined reference to `__atomic_compare_exchange_4'
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
Comment 7 Rainer Orth 2021-03-11 01:36:51 PST
(In reply to John Paul Adrian Glaubitz from comment #6)

> This fixes the issue for me although I'm now running into another
> (unrelated) problem which seems to be a result of a missing libatomic in
> LDFLAGS:
> 
> [9/4273] Linking CXX shared library
> lib/clang/13.0.0/lib/linux/libclang_rt.ubsan_minimal-sparc.so
> FAILED: lib/clang/13.0.0/lib/linux/libclang_rt.ubsan_minimal-sparc.so 
[...]
> /usr/bin/ld:
> projects/compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.sparc.dir/
> ubsan_minimal_handlers.cpp.o: in function `report_this_error(void*)':
> /home/glaubitz/llvm-project/compiler-rt/lib/ubsan_minimal/../
> sanitizer_common/sanitizer_atomic_clang.h:80: undefined reference to
> `__atomic_compare_exchange_4'
> clang-13: error: linker command failed with exit code 1 (use -v to see
> invocation)

This is a known issue: cf. Bug 42535.  On Solaris/SPARC, only SPARC V9 CPUs are
supported and I avoid the issue by relying on that: https://reviews.llvm.org/D86621.  No idea about the Linux/sparc situation, though.
Comment 8 John Paul Adrian Glaubitz 2021-03-12 04:03:35 PST
(In reply to Rainer Orth from comment #7)
> This is a known issue: cf. Bug 42535.  On Solaris/SPARC, only SPARC V9 CPUs
> are
> supported and I avoid the issue by relying on that:
> https://reviews.llvm.org/D86621.  No idea about the Linux/sparc situation,
> though.

This fixes the problem for me:

diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake
index 1edab43e7c0d..94ed0b5e1d19 100644
--- a/compiler-rt/cmake/base-config-ix.cmake
+++ b/compiler-rt/cmake/base-config-ix.cmake
@@ -189,7 +189,7 @@ macro(test_targets)
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
       test_target_arch(s390x "" "")
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
-      test_target_arch(sparc "" "-m32")
+      test_target_arch(sparc "" "-mcpu=v9" "-m32")
       test_target_arch(sparcv9 "" "-m64")
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
       # Gcc doesn't accept -m32/-m64 so we do the next best thing and use

@jrtc27: Would you be fine with this change?
Comment 9 John Paul Adrian Glaubitz 2021-03-12 08:29:06 PST
Hmm, there are more issues with the sanitizer on Linux/sparc64. I also had to properly define pc and sp on Linux:

diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake
index 1edab43e7c0d..94ed0b5e1d19 100644
--- a/compiler-rt/cmake/base-config-ix.cmake
+++ b/compiler-rt/cmake/base-config-ix.cmake
@@ -189,7 +189,7 @@ macro(test_targets)
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
       test_target_arch(s390x "" "")
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
-      test_target_arch(sparc "" "-m32")
+      test_target_arch(sparc "" "-mcpu=v9" "-m32")
       test_target_arch(sparcv9 "" "-m64")
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
       # Gcc doesn't accept -m32/-m64 so we do the next best thing and use
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 25c0751c9a38..c9bf318bfccb 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -1883,6 +1883,12 @@ SignalContext::WriteFlag SignalContext::GetWriteFlag() const {
   // From OpenSolaris $SRC/uts/sun4/os/trap.c (get_accesstype).
 #if SANITIZER_SOLARIS
   uptr pc = ucontext->uc_mcontext.gregs[REG_PC];
+#elif SANITIZER_LINUX
+#if defined (__arch64__)
+  uptr pc = ucontext->uc_mcontext.mc_gregs[MC_PC];
+#else
+  uptr pc = ucontext->uc_mcontext.gregs[REG_PC];
+#endif
 #else
   // Historical BSDism here.
   struct sigcontext *scontext = (struct sigcontext *)context;
@@ -2086,6 +2092,15 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
   ucontext_t *ucontext = (ucontext_t *)context;
   *pc = ucontext->uc_mcontext.gregs[REG_PC];
   *sp = ucontext->uc_mcontext.gregs[REG_O6] + STACK_BIAS;
+# elif SANITIZER_LINUX
+  ucontext_t *ucontext = (ucontext_t*)context;
+# if defined (__arch64__)
+  *pc = ucontext->uc_mcontext.mc_gregs[MC_PC];
+  *sp = ucontext->uc_mcontext.mc_gregs[MC_O6] + STACK_BIAS;
+# else
+  *pc = ucontext->uc_mcontext.gregs[REG_PC];
+  *sp = ucontext->uc_mcontext.gregs[REG_O6] + STACK_BIAS;
+# endif
 #else
   // Historical BSDism here.
   struct sigcontext *scontext = (struct sigcontext *)context;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
index 35a690cba5c8..0cafa3be234d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
@@ -240,7 +240,7 @@ namespace __sanitizer {
   // Use pre-computed size of struct ustat to avoid <sys/ustat.h> which
   // has been removed from glibc 2.28.
 #if defined(__aarch64__) || defined(__s390x__) || defined(__mips64) ||     \
-    defined(__powerpc64__) || defined(__arch64__) || defined(__sparcv9) || \
+    defined(__powerpc64__) || (defined(__arch64__) && defined(__sparc__)) || \
     defined(__x86_64__) || SANITIZER_RISCV64
 #define SIZEOF_STRUCT_USTAT 32
 #elif defined(__arm__) || defined(__i386__) || defined(__mips__) \

And there are more issues:

FAILED: projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoHooks.sparc.dir/sanitizer_linux.cpp.o
/home/glaubitz/llvm-project/stage1.install/bin/clang++ -DHAVE_RPC_XDR_H=1 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/compiler-rt/lib/sanitizer_common -I/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common -Iinclude -I/home/glaubitz/llvm-project/llvm/include -I/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/.. -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Werror=return-type -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -std=c++14 -Wno-unused-parameter -O3   -mcpu=v9 -m32 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -Wframe-larger-than=570 -Wglobal-constructors -DSANITIZER_SUPPORTS_WEAK_HOOKS=0 -UNDEBUG -std=c++14 -MD -MT projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoHooks.sparc.dir/sanitizer_linux.cpp.o -MF projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoHooks.sparc.dir/sanitizer_linux.cpp.o.d -o projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoHooks.sparc.dir/sanitizer_linux.cpp.o -c /home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1890:35: error: no member named 'gregs' in 'mcontext_t'
  uptr pc = ucontext->uc_mcontext.gregs[REG_PC];
            ~~~~~~~~~~~~~~~~~~~~~ ^
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:2101:31: error: no member named 'gregs' in 'mcontext_t'
  *pc = ucontext->uc_mcontext.gregs[REG_PC];
        ~~~~~~~~~~~~~~~~~~~~~ ^
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:2102:31: error: no member named 'gregs' in 'mcontext_t'
  *sp = ucontext->uc_mcontext.gregs[REG_O6] + STACK_BIAS;
        ~~~~~~~~~~~~~~~~~~~~~ ^
3 errors generated.
(...)
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h:1438:3: note: expanded from macro 'CHECK_SIZE_AND_OFFSET'
  COMPILER_CHECK(sizeof(((__sanitizer_##CLASS *)NULL)->MEMBER) == \
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h:332:30: note: expanded from macro 'COMPILER_CHECK'
#define COMPILER_CHECK(pred) static_assert(pred, "")
                             ^             ~~~~
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp:1061:1: error: static_assert failed due to requirement 'sizeof (((__sanitizer::__sanitizer_dirent64 *)__null)->d_off) == sizeof (((dirent64 *)__null)->d_off)' ""
CHECK_SIZE_AND_OFFSET(dirent64, d_off);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h:1438:3: note: expanded from macro 'CHECK_SIZE_AND_OFFSET'
  COMPILER_CHECK(sizeof(((__sanitizer_##CLASS *)NULL)->MEMBER) == \
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h:332:30: note: expanded from macro 'COMPILER_CHECK'
#define COMPILER_CHECK(pred) static_assert(pred, "")
                             ^             ~~~~
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp:1061:1: error: static_assert failed due to requirement '__builtin_offsetof(__sanitizer::__sanitizer_dirent64, d_off) == __builtin_offsetof(dirent64, d_off)' ""
CHECK_SIZE_AND_OFFSET(dirent64, d_off);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h:1440:3: note: expanded from macro 'CHECK_SIZE_AND_OFFSET'
  COMPILER_CHECK(offsetof(__sanitizer_##CLASS, MEMBER) ==         \

It seems like clang automatically defaults mcpu=v9 to 64 bits.
Comment 10 John Paul Adrian Glaubitz 2021-03-12 09:12:35 PST
OK, it seems that clang handles the combination of "-m32" and "-mcpu=v9" incorrectly:

glaubitz@gcc202:~/llvm-project/build$ clang++ -DHAVE_RPC_XDR_H=1 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/compiler-rt/lib/sanitizer_common -I/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common -Iinclude -I/home/glaubitz/llvm-project/llvm/include -I/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/.. -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Werror=return-type -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -std=c++14 -Wno-unused-parameter -O3 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -Wframe-larger-than=570 -Wglobal-constructors -UNDEBUG -std=c++14 -MD -MT projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.sparc.dir/sanitizer_linux.cpp.o -MF projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.sparc.dir/sanitizer_linux.cpp.o.d -o projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.sparc.dir/sanitizer_linux.cpp.o -c /home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp -mcpu=v9 -m32
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:1890:35: error: no member named 'gregs' in 'mcontext_t'
  uptr pc = ucontext->uc_mcontext.gregs[REG_PC];
            ~~~~~~~~~~~~~~~~~~~~~ ^
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:2101:31: error: no member named 'gregs' in 'mcontext_t'
  *pc = ucontext->uc_mcontext.gregs[REG_PC];
        ~~~~~~~~~~~~~~~~~~~~~ ^
/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp:2102:31: error: no member named 'gregs' in 'mcontext_t'
  *sp = ucontext->uc_mcontext.gregs[REG_O6] + STACK_BIAS;
        ~~~~~~~~~~~~~~~~~~~~~ ^
3 errors generated.
glaubitz@gcc202:~/llvm-project/build$ g++ -DHAVE_RPC_XDR_H=1 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/compiler-rt/lib/sanitizer_common -I/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common -Iinclude -I/home/glaubitz/llvm-project/llvm/include -I/home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/.. -fPIC -fvisibility-inlines-hidden -Werror=date-time  -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override  -Werror=return-type -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -std=c++14 -Wno-unused-parameter -O3 -fPIC -fno-builtin -fno-exceptions -fomit-frame-pointer -funwind-tables -fno-stack-protector -fvisibility=hidden -fno-lto -O3 -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -nostdinc++ -fno-rtti -Wframe-larger-than=570  -UNDEBUG -std=c++14 -MD -MT projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.sparc.dir/sanitizer_linux.cpp.o -MF projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.sparc.dir/sanitizer_linux.cpp.o.d -o projects/compiler-rt/lib/sanitizer_common/CMakeFiles/RTSanitizerCommon.sparc.dir/sanitizer_linux.cpp.o -c /home/glaubitz/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp -mcpu=v9 -m32glaubitz@gcc202:~/llvm-project/build$
Comment 11 John Paul Adrian Glaubitz 2021-03-12 12:46:21 PST
This fixes it provided that #49562 is fixed:

diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake
index 1edab43e7c0d..0ff9930e2616 100644
--- a/compiler-rt/cmake/base-config-ix.cmake
+++ b/compiler-rt/cmake/base-config-ix.cmake
@@ -189,8 +189,12 @@ macro(test_targets)
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
       test_target_arch(s390x "" "")
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
-      test_target_arch(sparc "" "-m32")
-      test_target_arch(sparcv9 "" "-m64")
+      if (CMAKE_SIZEOF_VOID_P EQUAL 4)
+        test_target_arch(sparc "" "-mcpu=v9" "-m32")
+        append("-latomic" CMAKE_LD_FLAGS)
+      else()
+        test_target_arch(sparcv9 "" "-m64")
+      endif()
     elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mipsel|mips64el")
       # Gcc doesn't accept -m32/-m64 so we do the next best thing and use
       # -mips32r2/-mips64r2. We don't use -mips1/-mips3 because we want to match