[compiler-rt] [compiler-rt][Profile][Darwin] Fix a test that expected an alignment … (PR #100469)
Jon Roelofs via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 25 10:13:13 PDT 2024
https://github.com/jroelofs updated https://github.com/llvm/llvm-project/pull/100469
>From 33bf86926edff480d1e6b12a3f9e41b9ba163765 Mon Sep 17 00:00:00 2001
From: Jon Roelofs <jonathan_roelofs at apple.com>
Date: Wed, 24 Jul 2024 14:01:30 -0700
Subject: [PATCH 1/2] [compiler-rt][Profile][Darwin] Fix a test that expected
an alignment greater than the maximum for a segment
This test was failing with:
--
Exit Code: 1
Command Output (stderr):
--
ld: warning: reducing alignment of section __DATA,__pcnts from 0x4000 to 0x1000 because it exceeds segment maximum alignment
ld: warning: reducing alignment of section __DATA,__pdata from 0x4000 to 0x1000 because it exceeds segment maximum alignment
__pdata not ordered after __pcnts.
--
---
.../darwin-proof-of-concept.c | 20 +++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/compiler-rt/test/profile/ContinuousSyncMode/darwin-proof-of-concept.c b/compiler-rt/test/profile/ContinuousSyncMode/darwin-proof-of-concept.c
index 85caca9a56b40..cf3bb0cd5d463 100644
--- a/compiler-rt/test/profile/ContinuousSyncMode/darwin-proof-of-concept.c
+++ b/compiler-rt/test/profile/ContinuousSyncMode/darwin-proof-of-concept.c
@@ -8,8 +8,8 @@
// Align counters and data to the maximum expected page size (16K).
// RUN: %clang -g -o %t %s \
-// RUN: -Wl,-sectalign,__DATA,__pcnts,0x4000 \
-// RUN: -Wl,-sectalign,__DATA,__pdata,0x4000
+// RUN: -Wl,-sectalign,__DATA,__pcnts,0x1000 \
+// RUN: -Wl,-sectalign,__DATA,__pdata,0x1000
// Create a 'profile' using mmap() and validate it.
// RUN: %run %t create %t.tmpfile
@@ -24,7 +24,7 @@
__attribute__((section("__DATA,__pcnts"))) int counters[] = {0xbad};
extern int cnts_start __asm("section$start$__DATA$__pcnts");
-const size_t cnts_len = 0x4000;
+const size_t cnts_len = 0x1000;
__attribute__((section("__DATA,__pdata"))) int data[] = {1, 2, 3};
extern int data_start __asm("section$start$__DATA$__pdata");
@@ -44,8 +44,8 @@ int create_tmpfile(char *path) {
return EXIT_FAILURE;
}
- // Write the data first (at offset 0x4000, after the counters).
- if (data_len != pwrite(fd, &data, data_len, 0x4000)) {
+ // Write the data first (at offset 0x1000, after the counters).
+ if (data_len != pwrite(fd, &data, data_len, cnts_len)) {
perror("write");
return EXIT_FAILURE;
}
@@ -55,7 +55,7 @@ int create_tmpfile(char *path) {
// Requirements (on Darwin):
// - &cnts_start must be page-aligned.
// - The length and offset-into-fd must be page-aligned.
- int *counter_map = (int *)mmap(&cnts_start, 0x4000, PROT_READ | PROT_WRITE,
+ int *counter_map = (int *)mmap(&cnts_start, cnts_len, PROT_READ | PROT_WRITE,
MAP_FIXED | MAP_SHARED, fd, 0);
if (counter_map != &cnts_start) {
perror("mmap");
@@ -97,7 +97,7 @@ int validate_tmpfile(char *path) {
}
// Verify that the rest of the counters (after counter 9) are 0.
- const int num_cnts = 0x4000 / sizeof(int);
+ const int num_cnts = cnts_len / sizeof(int);
for (int i = 10; i < num_cnts; ++i) {
if (buf[i] != 0) {
fprintf(stderr,
@@ -131,11 +131,11 @@ int main(int argc, char **argv) {
fprintf(stderr, "__pcnts is not page-aligned: 0x%lx.\n", cnts_start_int);
return EXIT_FAILURE;
}
- if (data_start_int % pagesz != 0) {
- fprintf(stderr, "__pdata is not page-aligned: 0x%lx.\n", data_start_int);
+ if (data_start_int % 0x1000 != 0) {
+ fprintf(stderr, "__pdata is not correctly aligned: 0x%lx.\n", data_start_int);
return EXIT_FAILURE;
}
- if (cnts_start_int + 0x4000 != data_start_int) {
+ if (cnts_start_int + 0x1000 != data_start_int) {
fprintf(stderr, "__pdata not ordered after __pcnts.\n");
return EXIT_FAILURE;
}
>From d6354576a154bf9a3653e2d064ae13736d0cee48 Mon Sep 17 00:00:00 2001
From: Jon Roelofs <jonathan_roelofs at apple.com>
Date: Thu, 25 Jul 2024 10:12:57 -0700
Subject: [PATCH 2/2] clang-format
---
.../profile/ContinuousSyncMode/darwin-proof-of-concept.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/test/profile/ContinuousSyncMode/darwin-proof-of-concept.c b/compiler-rt/test/profile/ContinuousSyncMode/darwin-proof-of-concept.c
index cf3bb0cd5d463..3ed7c1894b6d1 100644
--- a/compiler-rt/test/profile/ContinuousSyncMode/darwin-proof-of-concept.c
+++ b/compiler-rt/test/profile/ContinuousSyncMode/darwin-proof-of-concept.c
@@ -56,7 +56,7 @@ int create_tmpfile(char *path) {
// - &cnts_start must be page-aligned.
// - The length and offset-into-fd must be page-aligned.
int *counter_map = (int *)mmap(&cnts_start, cnts_len, PROT_READ | PROT_WRITE,
- MAP_FIXED | MAP_SHARED, fd, 0);
+ MAP_FIXED | MAP_SHARED, fd, 0);
if (counter_map != &cnts_start) {
perror("mmap");
return EXIT_FAILURE;
@@ -132,7 +132,8 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
if (data_start_int % 0x1000 != 0) {
- fprintf(stderr, "__pdata is not correctly aligned: 0x%lx.\n", data_start_int);
+ fprintf(stderr, "__pdata is not correctly aligned: 0x%lx.\n",
+ data_start_int);
return EXIT_FAILURE;
}
if (cnts_start_int + 0x1000 != data_start_int) {
More information about the llvm-commits
mailing list