[PATCH] Fix build with gcc LTO

Ralph Boehme slow at samba.org
Wed Jun 1 14:24:55 UTC 2016


Hi!

Attached is a simple patch that fixes a build problem when building
with gcc LTO. Simple fix, took me ages to find it...

Please review & push if ok.

Cheerio!
-slow
-------------- next part --------------
From c1f39390a5f1ac2383e6b88655eb88357917f627 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Wed, 1 Jun 2016 15:42:13 +0200
Subject: [PATCH] talloc: rename local timeval function copies

timeval_current() and timeval_elapsed() are public functions from
libsamba-util. Redeclaring them as static functions here triggers linker
error when building with gcc link-time-optimisation (LTO).

This shows the error after reverting this patch:
[slow at kazak lto]$ make -j
WAF_MAKE=1 python ./buildtools/bin/waf build
Waf: Entering directory `/home/slow/git/samba/lto/bin'
        Selected embedded Heimdal build
[ 174/4259] Generating ctdb-samba-version-header
[ 174/4259] Generating ctdb-samba-version-header
[ 521/4259] Generating source4/torture/local/proto.h
[2565/4259] Compiling lib/talloc/testsuite.c
[4125/4259] Linking default/source4/torture/smbtorture
/tmp/ccvL9UCe.ltrans3.ltrans.o:<artificial>:function smbsrv_accept.lto_priv.11: error: undefined reference to 'timeval_current.lto_priv.630'
/tmp/ccvL9UCe.ltrans4.ltrans.o:<artificial>:function smbsrv_recv_smb2_request: error: undefined reference to 'timeval_current.lto_priv.630'
/tmp/ccvL9UCe.ltrans4.ltrans.o:<artificial>:function smb2srv_negprot_backend: error: undefined reference to 'timeval_current.lto_priv.630'
/tmp/ccvL9UCe.ltrans4.ltrans.o:<artificial>:function smb2srv_negprot_backend: error: undefined reference to 'timeval_current.lto_priv.630'
/tmp/ccvL9UCe.ltrans9.ltrans.o:<artificial>:function test_smb2_oplock_batch22: error: undefined reference to 'timeval_elapsed.lto_priv.628'
/tmp/ccvL9UCe.ltrans9.ltrans.o:<artificial>:function test_smb2_bench_oplock: error: undefined reference to 'timeval_elapsed.lto_priv.628'
/tmp/ccvL9UCe.ltrans9.ltrans.o:<artificial>:function test_smb2_bench_oplock: error: undefined reference to 'timeval_elapsed.lto_priv.628'
/tmp/ccvL9UCe.ltrans9.ltrans.o:<artificial>:function test_smb2_bench_oplock: error: undefined reference to 'timeval_elapsed.lto_priv.628'
collect2: error: ld returned 1 exit status
...

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 lib/talloc/testsuite.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c
index 5eab839..dd49df1 100644
--- a/lib/talloc/testsuite.c
+++ b/lib/talloc/testsuite.c
@@ -36,16 +36,16 @@
 
 #include "talloc_testsuite.h"
 
-static struct timeval timeval_current(void)
+static struct timeval private_timeval_current(void)
 {
 	struct timeval tv;
 	gettimeofday(&tv, NULL);
 	return tv;
 }
 
-static double timeval_elapsed(struct timeval *tv)
+static double private_timeval_elapsed(struct timeval *tv)
 {
-	struct timeval tv2 = timeval_current();
+	struct timeval tv2 = private_timeval_current();
 	return (tv2.tv_sec - tv->tv_sec) + 
 	       (tv2.tv_usec - tv->tv_usec)*1.0e-6;
 }
@@ -835,7 +835,7 @@ static bool test_speed(void)
 
 	printf("test: speed\n# TALLOC VS MALLOC SPEED\n");
 
-	tv = timeval_current();
+	tv = private_timeval_current();
 	count = 0;
 	do {
 		void *p1, *p2, *p3;
@@ -848,15 +848,15 @@ static bool test_speed(void)
 			talloc_free(p1);
 		}
 		count += 3 * loop;
-	} while (timeval_elapsed(&tv) < 5.0);
+	} while (private_timeval_elapsed(&tv) < 5.0);
 
-	fprintf(stderr, "talloc: %.0f ops/sec\n", count/timeval_elapsed(&tv));
+	fprintf(stderr, "talloc: %.0f ops/sec\n", count/private_timeval_elapsed(&tv));
 
 	talloc_free(ctx);
 
 	ctx = talloc_pool(NULL, 1024);
 
-	tv = timeval_current();
+	tv = private_timeval_current();
 	count = 0;
 	do {
 		void *p1, *p2, *p3;
@@ -869,13 +869,13 @@ static bool test_speed(void)
 			talloc_free(p1);
 		}
 		count += 3 * loop;
-	} while (timeval_elapsed(&tv) < 5.0);
+	} while (private_timeval_elapsed(&tv) < 5.0);
 
 	talloc_free(ctx);
 
-	fprintf(stderr, "talloc_pool: %.0f ops/sec\n", count/timeval_elapsed(&tv));
+	fprintf(stderr, "talloc_pool: %.0f ops/sec\n", count/private_timeval_elapsed(&tv));
 
-	tv = timeval_current();
+	tv = private_timeval_current();
 	count = 0;
 	do {
 		void *p1, *p2, *p3;
@@ -888,8 +888,8 @@ static bool test_speed(void)
 			free(p3);
 		}
 		count += 3 * loop;
-	} while (timeval_elapsed(&tv) < 5.0);
-	fprintf(stderr, "malloc: %.0f ops/sec\n", count/timeval_elapsed(&tv));
+	} while (private_timeval_elapsed(&tv) < 5.0);
+	fprintf(stderr, "malloc: %.0f ops/sec\n", count/private_timeval_elapsed(&tv));
 
 	printf("success: speed\n");
 
-- 
2.5.0



More information about the samba-technical mailing list