[compiler-rt] r365805 - [profile][test] Fix Profile-* :: instrprof-merge.c etc. on SPARC

Rainer Orth via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 11:26:24 PDT 2019


Author: ro
Date: Thu Jul 11 11:26:24 2019
New Revision: 365805

URL: http://llvm.org/viewvc/llvm-project?rev=365805&view=rev
Log:
[profile][test] Fix Profile-* :: instrprof-merge.c etc. on SPARC

While working on https://reviews.llvm.org/D40900 (which effectively is about enabling compiler-rt on sparc these days), I came across two failing profile testcases:

  Profile-sparc :: instrprof-merge-match.test
  Profile-sparc :: instrprof-merge.c
  Profile-sparcv9 :: instrprof-merge-match.test
  Profile-sparcv9 :: instrprof-merge.c

All of them crashed with a SIGBUS in __llvm_profile_merge_from_buffer:

  Thread 2 received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 1 (LWP 1)]
  0x00012368 in __llvm_profile_merge_from_buffer (
      ProfileData=0x2384c <main.Buffer> "\377lprofR\201", ProfileSize=360)
      at /vol/llvm/src/llvm/local/projects/compiler-rt/lib/profile/InstrProfilingMerge.c:95
  95        SrcDataEnd = SrcDataStart + Header->DataSize;

where Header is insufficiently aligned for a strict-alignment target like SPARC.

Fixed by forcing the alignment to uint64_t, the members of struct __llvm_profile_header,
in the callers.

Tested on sparcv9-sun-solaris2.11.

https://reviews.llvm.org/D64498

Added:
    compiler-rt/trunk/test/profile/profile_test.h
Modified:
    compiler-rt/trunk/test/profile/Inputs/instrprof-merge-match.c
    compiler-rt/trunk/test/profile/instrprof-merge.c

Modified: compiler-rt/trunk/test/profile/Inputs/instrprof-merge-match.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Inputs/instrprof-merge-match.c?rev=365805&r1=365804&r2=365805&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/Inputs/instrprof-merge-match.c (original)
+++ compiler-rt/trunk/test/profile/Inputs/instrprof-merge-match.c Thu Jul 11 11:26:24 2019
@@ -1,6 +1,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
+#include "../profile_test.h"
 
 int __llvm_profile_runtime = 0;
 uint64_t __llvm_profile_get_size_for_buffer(void);
@@ -20,7 +21,7 @@ extern uint64_t libEntry(char *Buffer, u
 
 int main(int argc, const char *argv[]) {
   const uint64_t MaxSize = 10000;
-  static char Buffer[MaxSize];
+  static char ALIGNED(sizeof(uint64_t)) Buffer[MaxSize];
 
   uint64_t Size = __llvm_profile_get_size_for_buffer();
   if (Size > MaxSize)

Modified: compiler-rt/trunk/test/profile/instrprof-merge.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-merge.c?rev=365805&r1=365804&r2=365805&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/instrprof-merge.c (original)
+++ compiler-rt/trunk/test/profile/instrprof-merge.c Thu Jul 11 11:26:24 2019
@@ -8,6 +8,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include "profile_test.h"
 
 int __llvm_profile_runtime = 0;
 uint64_t __llvm_profile_get_size_for_buffer(void);
@@ -41,7 +42,7 @@ int main(int argc, const char *argv[]) {
     return 1;
 
   const uint64_t MaxSize = 10000;
-  static char Buffer[MaxSize];
+  static ALIGNED(sizeof(uint64_t)) char Buffer[MaxSize];
 
   uint64_t Size = __llvm_profile_get_size_for_buffer();
   if (Size > MaxSize)

Added: compiler-rt/trunk/test/profile/profile_test.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/profile_test.h?rev=365805&view=auto
==============================================================================
--- compiler-rt/trunk/test/profile/profile_test.h (added)
+++ compiler-rt/trunk/test/profile/profile_test.h Thu Jul 11 11:26:24 2019
@@ -0,0 +1,20 @@
+//===-- profile_test.h.h ----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains definitions for the profile tests.
+//===----------------------------------------------------------------------===//
+#ifndef PROFILE_TEST_H
+#define PROFILE_TEST_H
+
+#if defined(_MSC_VER)
+# define ALIGNED(x) __declspec(align(x))
+#else  // _MSC_VER
+# define ALIGNED(x) __attribute__((aligned(x)))
+#endif
+
+#endif  // PROFILE_TEST_H




More information about the llvm-commits mailing list