Skip to content

Commit 99bb9a7

Browse files
authored
[compiler-rt][Profile][Darwin] Fix a test that expected an alignment … (#100469)
…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. -- ```
1 parent 3eaf9f7 commit 99bb9a7

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

compiler-rt/test/profile/ContinuousSyncMode/darwin-proof-of-concept.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
// Align counters and data to the maximum expected page size (16K).
1010
// RUN: %clang -g -o %t %s \
11-
// RUN: -Wl,-sectalign,__DATA,__pcnts,0x4000 \
12-
// RUN: -Wl,-sectalign,__DATA,__pdata,0x4000
11+
// RUN: -Wl,-sectalign,__DATA,__pcnts,0x1000 \
12+
// RUN: -Wl,-sectalign,__DATA,__pdata,0x1000
1313

1414
// Create a 'profile' using mmap() and validate it.
1515
// RUN: %run %t create %t.tmpfile
@@ -24,7 +24,7 @@
2424

2525
__attribute__((section("__DATA,__pcnts"))) int counters[] = {0xbad};
2626
extern int cnts_start __asm("section$start$__DATA$__pcnts");
27-
const size_t cnts_len = 0x4000;
27+
const size_t cnts_len = 0x1000;
2828

2929
__attribute__((section("__DATA,__pdata"))) int data[] = {1, 2, 3};
3030
extern int data_start __asm("section$start$__DATA$__pdata");
@@ -44,8 +44,8 @@ int create_tmpfile(char *path) {
4444
return EXIT_FAILURE;
4545
}
4646

47-
// Write the data first (at offset 0x4000, after the counters).
48-
if (data_len != pwrite(fd, &data, data_len, 0x4000)) {
47+
// Write the data first (at offset 0x1000, after the counters).
48+
if (data_len != pwrite(fd, &data, data_len, cnts_len)) {
4949
perror("write");
5050
return EXIT_FAILURE;
5151
}
@@ -55,8 +55,8 @@ int create_tmpfile(char *path) {
5555
// Requirements (on Darwin):
5656
// - &cnts_start must be page-aligned.
5757
// - The length and offset-into-fd must be page-aligned.
58-
int *counter_map = (int *)mmap(&cnts_start, 0x4000, PROT_READ | PROT_WRITE,
59-
MAP_FIXED | MAP_SHARED, fd, 0);
58+
int *counter_map = (int *)mmap(&cnts_start, cnts_len, PROT_READ | PROT_WRITE,
59+
MAP_FIXED | MAP_SHARED, fd, 0);
6060
if (counter_map != &cnts_start) {
6161
perror("mmap");
6262
return EXIT_FAILURE;
@@ -97,7 +97,7 @@ int validate_tmpfile(char *path) {
9797
}
9898

9999
// Verify that the rest of the counters (after counter 9) are 0.
100-
const int num_cnts = 0x4000 / sizeof(int);
100+
const int num_cnts = cnts_len / sizeof(int);
101101
for (int i = 10; i < num_cnts; ++i) {
102102
if (buf[i] != 0) {
103103
fprintf(stderr,
@@ -131,11 +131,12 @@ int main(int argc, char **argv) {
131131
fprintf(stderr, "__pcnts is not page-aligned: 0x%lx.\n", cnts_start_int);
132132
return EXIT_FAILURE;
133133
}
134-
if (data_start_int % pagesz != 0) {
135-
fprintf(stderr, "__pdata is not page-aligned: 0x%lx.\n", data_start_int);
134+
if (data_start_int % 0x1000 != 0) {
135+
fprintf(stderr, "__pdata is not correctly aligned: 0x%lx.\n",
136+
data_start_int);
136137
return EXIT_FAILURE;
137138
}
138-
if (cnts_start_int + 0x4000 != data_start_int) {
139+
if (cnts_start_int + 0x1000 != data_start_int) {
139140
fprintf(stderr, "__pdata not ordered after __pcnts.\n");
140141
return EXIT_FAILURE;
141142
}

0 commit comments

Comments
 (0)