Fixing the compilation errors for liblockdep
cover Fixing the compilation errors for liblockdep
The patch tries to fix the compilation errors in liblockdep which were introduced due to recent changes in kernel. I am not familiar with the internal working of lockdep, so please suggest if I have done anything wrong while fixing liblockdep errors.
Vishal Thanki (2):
liblockdep: Fix compile errors
liblockdep: Remove -lpthread compiler option
tools/lib/lockdep/lockdep.c | 2 +- tools/lib/lockdep/run_tests.sh | 4 ++-- tools/lib/lockdep/uinclude/linux/jhash.h | 20 ++++++++++++++++++++ tools/lib/lockdep/uinclude/linux/kernel.h | 1 + tools/lib/lockdep/uinclude/linux/lockdep.h | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 tools/lib/lockdep/uinclude/linux/jhash.h
Signature · 1 line
2.4.11
PATCH 1/2 liblockdep: Fix compile errors
Following commit caused failures.
dfaaf3fa0: (Use __jhash_mix() for iterate_chain_key()) Fixed by adding jhash.h with minimal stuff required
75dd602a5: (lockdep: Fix lock_chain::base size) Fixed by adding ARRAY_SIZE macro definition and changing the MAX_LOCK_DEPTH value to similar defined in linux/sched.h
--- tools/lib/lockdep/lockdep.c | 2 +- tools/lib/lockdep/uinclude/linux/jhash.h | 20 ++++++++++++++++++++ tools/lib/lockdep/uinclude/linux/kernel.h | 1 + tools/lib/lockdep/uinclude/linux/lockdep.h | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tools/lib/lockdep/uinclude/linux/jhash.h
tools/lib/lockdep/lockdep.c +1 -1
@@ -4,5 +4,5 @@#define hlist_for_each_entry_rcu hlist_for_each_entry#define hlist_add_head_rcu hlist_add_head#define hlist_del_rcu hlist_del - +#define prandom_u32 rand#include "../../../kernel/locking/lockdep.c"
tools/lib/lockdep/uinclude/linux/jhash.h new file +20 -0
@@ -0,0 +1,20 @@ +#ifndef _LINUX_JHASH_H +#define _LINUX_JHASH_H + +static inline __u32 rol32 (__u32 word,unsigned int shift) +{ +return (word << shift) | (word >> ((-shift) &31 )); +} + +/* __jhash_mix -- mix 3 32-bit values reversibly. */ +#define __jhash_mix (a, b, c) \ +{ \ + a -= c; a ^= rol32(c, 4); c += b; \ + b -= a; b ^= rol32(a, 6); a += c; \ + c -= b; c ^= rol32(b, 8); b += a; \ + a -= c; a ^= rol32(c, 16); c += b; \ + b -= a; b ^= rol32(a, 19); a += c; \ + c -= b; c ^= rol32(b, 4); b += a; \ +} + +#endif /* _LINUX_JHASH_H */
tools/lib/lockdep/uinclude/linux/kernel.h +1 -0
@@ -44,4 +44,5 @@#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })#endif +#define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0]))#endif
tools/lib/lockdep/uinclude/linux/lockdep.h +1 -1
@@ -8,7 +8,7 @@#include <linux/utsname.h> #include <linux/compiler.h> -#define MAX_LOCK_DEPTH 2000UL +#define MAX_LOCK_DEPTH 48UL#define asmlinkage#define __visible
Signature · 1 line
2.4.11
Re: [PATCH 1/2] liblockdep: Fix compile errors
Quoted 2 lines · Vishal Thanki
dfaaf3fa0: (Use__jhash_mix()foriterate_chain_key()) Fixed by addingjhash.hwith minimal stuff required
Can we, instead of copying it over, include jhash.h directly (just like we do for hash.h)?
Thanks,
Sasha
Re: [PATCH 1/2] liblockdep: Fix compile errors
Quoted 8 lines · Sasha Levin
Quoted 2 lines · Vishal Thanki
dfaaf3fa0: (Use__jhash_mix()foriterate_chain_key()) Fixed by addingjhash.hwith minimal stuff requiredCan we, instead of copying it over, include
jhash.hdirectly (just like we do forhash.h)?
That was the first thing I tried, but then it caused more compilation errors due to nested header dependencies and I ended up taking the only required stuff. Better ideas are welcome.
Thanks,
Vishal
Quoted 2 lines
Thanks,
Sasha
Re: [PATCH 1/2] liblockdep: Fix compile errors
Quoted 5 lines · Vishal Thanki
Quoted 4 lines · Sasha Levin
Quoted 2 lines · Vishal Thanki
dfaaf3fa0: (Use__jhash_mix()foriterate_chain_key()) Fixed by addingjhash.hwith minimal stuff required
Quoted 7 lines
Quoted 4 lines
Can we, instead of copying it over, include
jhash.hdirectly (just like we do forhash.h)?That was the first thing I tried, but then it caused more compilation errors due to nested header dependencies and I ended up taking the only required stuff. Better ideas are welcome.
I just gave it a quick go and didn't see anything beyond needing to take in linux/unaligned/packed_struct.h as well. What sort of errors did you hit?
Thanks,
Sasha
Re: [PATCH 1/2] liblockdep: Fix compile errors
Quoted 10 lines · Sasha Levin
Quoted 9 lines · Vishal Thanki
Quoted 8 lines · Sasha Levin
Quoted 2 lines · Vishal Thanki
dfaaf3fa0: (Use__jhash_mix()foriterate_chain_key()) Fixed by addingjhash.hwith minimal stuff requiredCan we, instead of copying it over, include
jhash.hdirectly (just like we do forhash.h)?
Quoted 8 lines
Quoted 3 lines
That was the first thing I tried, but then it caused more compilation errors due to nested header dependencies and I ended up taking the only required stuff. Better ideas are welcome.
I just gave it a quick go and didn't see anything beyond needing to take in
linux/unaligned/packed_struct.has well. What sort of errors did you hit?
Yes, you are right about just adding the linux/unaligned/packed_struct.h should work. However I hit the following errors when I did that:
CC lockdep.o
In file included from ./uinclude/linux/jhash.h:27:0,
from ../../../kernel/locking/lockdep.c:49,
from lockdep.c:8:
./uinclude/linux/unaligned/packed_struct.h:7:29: error: conflicting types for
‘__packed’
struct __una_u32 { u32 x; } __packed;
^
./uinclude/linux/unaligned/packed_struct.h:6:29: note: previous declaration of
‘__packed’ was here
struct __una_u16 { u16 x; } __packed;
^
./uinclude/linux/unaligned/packed_struct.h:8:29: error: conflicting types for
‘__packed’
struct __una_u64 { u64 x; } __packed;
^
./uinclude/linux/unaligned/packed_struct.h:6:29: note: previous declaration of
‘__packed’ was here
struct __una_u16 { u16 x; } __packed;
^which I overlooked and had nothing to do with header dependencies, pardon my ignorance.
I think gcc on my machine (version 5.3.1 on Fedora 22) throws the above error which I think can be fixed by adding a define in uinclude/linux/compile.h like following:
#define __packed __attribute__((__packed__))
After fixing, I hit following warning:
In file included from ../../../kernel/locking/lockdep.c:49:0,
from lockdep.c:8:./uinclude/linux/jhash.h: In function ‘jhash’:./uinclude/linux/jhash.h:37:16: warning: implicit declaration of function ‘rol32’ [-Wimplicit-function-declaration]
a -= c; a ^= rol32(c, 4); c += b; \
which can be fixed by adding the inline definition of rol32 from kernel's biopts.h file to uinclude/linux/bitops.h file (which is empty as of now).
I will rework the patch with the fixes and send again.
Thanks,
Vishal
PATCH 2/2 liblockdep: Remove -lpthread compiler option
In reply to Vishal ThankiWith -lpthread option, the test for ABBA_2threads was failing, and test passed if it was removed. Since -pthread compiler option is sufficient for linking to pthread libraries, this patch removes -lpthread.
--- tools/lib/lockdep/run_tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/lockdep/run_tests.sh +2 -2
@@ -4,7 +4,7 @@ make &> /dev/null for i in `ls tests/*.c`; do testname=$(basename "$i" .c) - gcc -o tests/$testname -pthread -lpthread $i liblockdep.a -Iinclude -D__USE_LIBLOCKDEP &> /dev/null + gcc -o tests/$testname -pthread $i liblockdep.a -Iinclude -D__USE_LIBLOCKDEP &> /dev/null echo -ne "$testname... " if [ $(timeout 1 ./tests/$testname | wc -l) -gt 0 ]; then echo "PASSED!"
@@ -18,7 +18,7 @@ done for i in `ls tests/*.c`; do testname=$(basename "$i" .c) - gcc -o tests/$testname -pthread -lpthread -Iinclude $i &> /dev/null + gcc -o tests/$testname -pthread -Iinclude $i &> /dev/null echo -ne "(PRELOAD) $testname... " if [ $(timeout 1 ./lockdep ./tests/$testname | wc -l) -gt 0 ]; then echo "PASSED!"
Signature · 1 line
2.4.11