Skip to content

Commit

Permalink
test: Align internal buffer for custom malloc()
Browse files Browse the repository at this point in the history
Some test code implements malloc() and free() using a static buffer.
I found test failures on RISC-V due to unaligned pointers from malloc().
Let's align the buffer at least 8.

Signed-off-by: Namhyung Kim <[email protected]>
  • Loading branch information
namhyung committed Dec 14, 2023
1 parent 314274b commit ced96bb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/s-malloc-fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void (*real_free)(void *ptr);

#define MALLOC_BUFSIZE (128 * 1024 * 1024)
/* this is needed for optimized binaries */
static char buf[MALLOC_BUFSIZE];
static char buf[MALLOC_BUFSIZE] __attribute__((aligned(8)));

void *malloc(size_t sz)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/s-malloc-hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void (*real_free)(void *ptr);

#define MALLOC_BUFSIZE (128 * 1024 * 1024)
/* this is needed for optimized binaries */
static char buf[MALLOC_BUFSIZE];
static char buf[MALLOC_BUFSIZE] __attribute__((aligned(8)));

void *malloc(size_t sz)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/s-malloc-tsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void (*real_free)(void *ptr);

#define MALLOC_BUFSIZE (128 * 1024 * 1024)
/* this is needed for optimized binaries */
static char buf[MALLOC_BUFSIZE];
static char buf[MALLOC_BUFSIZE] __attribute__((aligned(8)));

void *malloc(size_t sz)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/s-malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int free_count;

void *malloc(size_t size)
{
static char buf[MALLOC_BUFSIZE];
static char buf[MALLOC_BUFSIZE] __attribute__((aligned(16)));
static unsigned alloc_size;
void *ptr;

Expand Down

0 comments on commit ced96bb

Please sign in to comment.