Package: wrk
Version: 4.0.1-2
Severity: normal
Tags: sid
User: [email protected]
Usertags: mips-patch

Hello,

Package wrk_4.0.1-2 FTBFS on mips and mipsel with following message:
/«PKGBUILDDIR»/src/stats.c:24: undefined reference to `__sync_fetch_and_add_8'
/«PKGBUILDDIR»/src/stats.c:28: undefined reference to 
`__sync_val_compare_and_swap_8'

mips:
https://buildd.debian.org/status/fetch.php?pkg=wrk&arch=mips&ver=4.0.1-2&stamp=1438099809

mipsel:
https://buildd.debian.org/status/fetch.php?pkg=wrk&arch=mipsel&ver=4.0.1-2&stamp=1438028452

I have attached a patch that resolves this issue on mips and mipsel.
Could you please include this patch?

I suspect that this solution can be used for powerpc also, if powepc arch is 
included in patch, but I do not have powerpc machine to test this.

Thank you!

Regards,
Jurica
diff -upNr wrk-4.0.1-orig/debian/rules wrk-4.0.1/debian/rules
--- wrk-4.0.1-orig/debian/rules	2015-04-17 00:48:57.000000000 +0000
+++ wrk-4.0.1/debian/rules	2015-10-14 13:48:53.000000000 +0000
@@ -1,5 +1,12 @@
 #!/usr/bin/make -f
 
+DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
+
+ifeq ($(DEB_HOST_ARCH),$(filter $(DEB_HOST_ARCH),mips mipsel))
+	LIBS += -latomic
+	export LIBS
+endif
+
 export DEB_BUILD_MAINT_OPTIONS = hardening=+all
 
 %:
diff -upNr wrk-4.0.1-orig/src/stats.c wrk-4.0.1/src/stats.c
--- wrk-4.0.1-orig/src/stats.c	2015-03-24 10:03:52.000000000 +0000
+++ wrk-4.0.1/src/stats.c	2015-10-14 13:54:30.000000000 +0000
@@ -21,12 +21,12 @@ void stats_free(stats *stats) {
 
 int stats_record(stats *stats, uint64_t n) {
     if (n >= stats->limit) return 0;
-    __sync_fetch_and_add(&stats->data[n], 1);
-    __sync_fetch_and_add(&stats->count, 1);
+    __atomic_fetch_add(&stats->data[n], 1, __ATOMIC_SEQ_CST);
+    __atomic_fetch_add(&stats->count, 1, __ATOMIC_SEQ_CST);
     uint64_t min = stats->min;
     uint64_t max = stats->max;
-    while (n < min) min = __sync_val_compare_and_swap(&stats->min, min, n);
-    while (n > max) max = __sync_val_compare_and_swap(&stats->max, max, n);
+    while (n < min) min = __atomic_compare_exchange(&stats->min, &min, &n, false,__ATOMIC_SEQ_CST,__ATOMIC_SEQ_CST);
+    while (n > max) max = __atomic_compare_exchange(&stats->max, &max, &n, false,__ATOMIC_SEQ_CST,__ATOMIC_SEQ_CST);
     return 1;
 }
 

Reply via email to