Skip to content

Commit 0348b35

Browse files
committed
Make plain reads and writes weak for testing
Signed-off-by: Diogo Behrens <[email protected]>
1 parent 99ce449 commit 0348b35

File tree

3 files changed

+81
-26
lines changed

3 files changed

+81
-26
lines changed

CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ add_compile_options(-Wall -Werror -Wextra)
1313

1414
set(TSANO_C ${CMAKE_CURRENT_SOURCE_DIR}/tsano.c)
1515

16-
add_custom_command(
17-
OUTPUT ${TSANO_C}
16+
add_custom_target(
17+
tsano.c
1818
COMMAND env tmplr ${TSANO_C}.in > ${TSANO_C}
1919
DEPENDS ${TSANO_C}.in)
20-
add_custom_target(update-tsano DEPENDS ${TSANO_C})
20+
add_custom_target(update-tsano DEPENDS tsano.c)
2121

22-
add_library(tsano SHARED ${TSANO_C} syscall.c)
23-
add_dependencies(tsano update-tsano)
22+
add_library(tsano SHARED tsano.c syscall.c)
2423

2524
install(TARGETS tsano DESTINATION lib)
2625
install(

tsano.c

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* expected compiler builtins and seq_cst barriers.
1111
******************************************************************************/
1212
#include <stdint.h>
13+
#include <stdlib.h>
1314
#include <string.h>
1415

1516

@@ -113,103 +114,130 @@ __tsan_memcpy(void *dst, const void *src, size_t len)
113114
{
114115
return memcpy(dst, src, len);
115116
}
116-
/* plain reads and writes */
117+
void *
118+
__tsan_memmove(void *dst, const void *src, size_t len)
119+
{
120+
return memmove(dst, src, len);
121+
}
122+
/* C++ new and delete */
123+
void *
124+
_Znwm(size_t n)
125+
{
126+
return malloc(n);
127+
}
128+
void *
129+
_Znam(size_t n)
130+
{
131+
return malloc(n);
132+
}
117133
void
134+
_ZdlPv(void *ptr)
135+
{
136+
return free(ptr);
137+
}
138+
void
139+
_ZdaPv(void *ptr)
140+
{
141+
return free(ptr);
142+
}
143+
144+
/* plain reads and writes */
145+
__attribute__((weak)) void
118146
__tsan_read1(void *a)
119147
{
120148
(void)a;
121149
}
122-
void
150+
__attribute__((weak)) void
123151
__tsan_read2(void *a)
124152
{
125153
(void)a;
126154
}
127-
void
155+
__attribute__((weak)) void
128156
__tsan_read4(void *a)
129157
{
130158
(void)a;
131159
}
132-
void
160+
__attribute__((weak)) void
133161
__tsan_read8(void *a)
134162
{
135163
(void)a;
136164
}
137-
void
165+
__attribute__((weak)) void
138166
__tsan_read16(void *a)
139167
{
140168
(void)a;
141169
}
142-
void
170+
__attribute__((weak)) void
143171
__tsan_write1(void *a)
144172
{
145173
(void)a;
146174
}
147-
void
175+
__attribute__((weak)) void
148176
__tsan_write2(void *a)
149177
{
150178
(void)a;
151179
}
152-
void
180+
__attribute__((weak)) void
153181
__tsan_write4(void *a)
154182
{
155183
(void)a;
156184
}
157-
void
185+
__attribute__((weak)) void
158186
__tsan_write8(void *a)
159187
{
160188
(void)a;
161189
}
162-
void
190+
__attribute__((weak)) void
163191
__tsan_write16(void *a)
164192
{
165193
(void)a;
166194
}
167-
void
195+
__attribute__((weak)) void
168196
__tsan_unaligned_read1(void *a)
169197
{
170198
(void)a;
171199
}
172-
void
200+
__attribute__((weak)) void
173201
__tsan_unaligned_read2(void *a)
174202
{
175203
(void)a;
176204
}
177-
void
205+
__attribute__((weak)) void
178206
__tsan_unaligned_read4(void *a)
179207
{
180208
(void)a;
181209
}
182-
void
210+
__attribute__((weak)) void
183211
__tsan_unaligned_read8(void *a)
184212
{
185213
(void)a;
186214
}
187-
void
215+
__attribute__((weak)) void
188216
__tsan_unaligned_read16(void *a)
189217
{
190218
(void)a;
191219
}
192-
void
220+
__attribute__((weak)) void
193221
__tsan_unaligned_write1(void *a)
194222
{
195223
(void)a;
196224
}
197-
void
225+
__attribute__((weak)) void
198226
__tsan_unaligned_write2(void *a)
199227
{
200228
(void)a;
201229
}
202-
void
230+
__attribute__((weak)) void
203231
__tsan_unaligned_write4(void *a)
204232
{
205233
(void)a;
206234
}
207-
void
235+
__attribute__((weak)) void
208236
__tsan_unaligned_write8(void *a)
209237
{
210238
(void)a;
211239
}
212-
void
240+
__attribute__((weak)) void
213241
__tsan_unaligned_write16(void *a)
214242
{
215243
(void)a;

tsano.c.in

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* expected compiler builtins and seq_cst barriers.
1111
******************************************************************************/
1212
#include <stdint.h>
13+
#include <stdlib.h>
1314
#include <string.h>
1415

1516
#define _tmpl_mute // ----------- simple empty macros to make clangd happy -----
@@ -122,11 +123,38 @@ __tsan_memcpy(void *dst, const void *src, size_t len)
122123
{
123124
return memcpy(dst, src, len);
124125
}
126+
void *
127+
__tsan_memmove(void *dst, const void *src, size_t len)
128+
{
129+
return memmove(dst, src, len);
130+
}
131+
/* C++ new and delete */
132+
void *
133+
_Znwm(size_t n)
134+
{
135+
return malloc(n);
136+
}
137+
void *
138+
_Znam(size_t n)
139+
{
140+
return malloc(n);
141+
}
142+
void
143+
_ZdlPv(void *ptr)
144+
{
145+
return free(ptr);
146+
}
147+
void
148+
_ZdaPv(void *ptr)
149+
{
150+
return free(ptr);
151+
}
152+
125153
/* plain reads and writes */
126154
_tmpl_map(nix, );
127155
_tmpl_begin(PFX = [[nix; unaligned_]], FUNC = [[read; write]],
128156
SZ = [[1; 2; 4; 8; 16]]);
129-
void
157+
__attribute__((weak)) void
130158
__tsan_PFXFUNCSZ(void *a)
131159
{
132160
(void)a;

0 commit comments

Comments
 (0)