[libc-commits] [PATCH] D149863: [libc] Maintain proper alignment for the hermetic tests malloc

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu May 4 09:23:58 PDT 2023


jhuber6 created this revision.
jhuber6 added reviewers: sivachandra, lntue, michaelrj.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.

We use a bump pointer to implement malloc for the hermetic tests.
Currently, we bump the pointer up by any amount. This means that calling
`malloc(1)` will misalign the buffer so any following `malloc(8)`
accesses will not be aligned. This causes problems in architectures
which require alignment.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149863

Files:
  libc/test/UnitTest/HermeticTestUtils.cpp
  libc/test/src/__support/CMakeLists.txt


Index: libc/test/src/__support/CMakeLists.txt
===================================================================
--- libc/test/src/__support/CMakeLists.txt
+++ libc/test/src/__support/CMakeLists.txt
@@ -1,17 +1,14 @@
 add_custom_target(libc-support-tests)
 
-# This test fails with a misaigned address on NVPTX.
-if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
-  add_libc_test(
-    blockstore_test
-    SUITE
-      libc-support-tests
-    SRCS
-      blockstore_test.cpp
-    DEPENDS
-      libc.src.__support.blockstore
-  )
-endif()
+add_libc_test(
+  blockstore_test
+  SUITE
+    libc-support-tests
+  SRCS
+    blockstore_test.cpp
+  DEPENDS
+    libc.src.__support.blockstore
+)
 
 add_libc_test(
   endian_test
Index: libc/test/UnitTest/HermeticTestUtils.cpp
===================================================================
--- libc/test/UnitTest/HermeticTestUtils.cpp
+++ libc/test/UnitTest/HermeticTestUtils.cpp
@@ -62,6 +62,8 @@
 int atexit(void (*func)(void)) { return __llvm_libc::atexit(func); }
 
 void *malloc(size_t s) {
+  // Keep the bump pointer aligned on an eight byte boundary.
+  s = ((s + 8 - 1) / 8) * 8;
   void *mem = ptr;
   ptr += s;
   return mem;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149863.519525.patch
Type: text/x-patch
Size: 1183 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230504/64707eb4/attachment-0001.bin>


More information about the libc-commits mailing list