3

I'm trying to compile a 3rd party kernel module for RHEL 5.6 and it is failing due to function name conflicts with mutex_acquire and mutex_release. This kernel module compiles cleanly on RHEL 4.7 so something changed between kernels 2.6.9 and 2.6.18. Sadly, this kernel module is no longer supported by the vendor but I do have the source code for mutex.c and mutex.h which define these functions. Unfortunately there is an object file nivxi.o upon which no source code is distributed and this object file is calling mutex_acquire and mutex_release so I cannot just simply alter their names.

As an aside, I originally attempted to just modify the names slightly and the compile errors went away but when it went to make the .ko kernel module it complained that it couldn't find mutex_acquire or mutex_release; presumably due to nivxi.o

How do I force the compiler/linker to use the function definitions in my local .c/.h files even though they trounce over like-named functions elsewhere?

mutex.h

NIVXICC void mutex_acquire(mutex_t *mutex);
NIVXICC void mutex_release(mutex_t *mutex);

nivxicc.h (just incase this is pertinent)

#ifndef NIVXICC_H
#define NIVXICC_H
#define NIVXICC __attribute__((regparm(0))) __attribute__((cdecl))
#endif

/usr/include/lockdep.h (conflicting definition)

#ifdef CONFIG_DEBUG_LOCK_ALLOC
# ifdef CONFIG_PROVE_LOCKING
#  define mutex_acquire(l, s, t, i)             lock_acquire(l, s, t, 0, 2, i)
# else
#  define mutex_acquire(l, s, t, i)             lock_acquire(l, s, t, 0, 1, i)
# endif
# define mutex_release(l, n, i)                 lock_release(l, n, i)
#else
# define mutex_acquire(l, s, t, i)              do { } while (0)
# define mutex_release(l, n, i)                 do { } while (0)
#endif

Error

# make
make -C /lib/modules/2.6.18-238.el5/build SUBDIRS=/usr/local/nivxi/src KBUILD_VERBOSE=1 modules
make[1]: Entering directory `/usr/src/kernels/2.6.18-238.el5-i686'
test -e include/linux/autoconf.h -a -e include/config/auto.conf || (            \
        echo;                                                           \
        echo "  ERROR: Kernel configuration is invalid.";               \
        echo "         include/linux/autoconf.h or include/config/auto.conf are missing.";      \
        echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";  \
        echo;                                                           \
        /bin/false)
mkdir -p /usr/local/nivxi/src/.tmp_versions
rm -f /usr/local/nivxi/src/.tmp_versions/*
make -f scripts/Makefile.build obj=/usr/local/nivxi/src
gcc -m32 -Wp,-MD,/usr/local/nivxi/src/.vxi.o.d  -nostdinc -isystem \
/usr/lib/gcc/i386-redhat-linux/4.1.2/include -D__KERNEL__ -Iinclude \
-include include/linux/autoconf.h -Wall -Wundef -Wstrict-prototypes \
-Wno-trigraphs -fno-strict-aliasing -fno-common -Wstrict-prototypes \
-Wundef -Werror-implicit-function-declaration \
-fno-delete-null-pointer-checks -fwrapv -Os -pipe -msoft-float \
-fno-builtin-sprintf -fno-builtin-log2 -fno-builtin-puts \
-mpreferred-stack-boundary=2  -march=i686 -mtune=generic -mtune=generic \
-mregparm=3 -ffreestanding -Iinclude/asm-i386/mach-generic \
-Iinclude/asm-i386/mach-default -fomit-frame-pointer -g -fno-stack-protector \
-Wdeclaration-after-statement -Wno-pointer-sign -DVXI_MAJOR=0 \
-DREMAP_PAGE_RANGE_VMA -D__DEBUG__ -DMODULE -D"KBUILD_STR(s)=#s" \
-D"KBUILD_BASENAME=KBUILD_STR(vxi)" -D"KBUILD_MODNAME=KBUILD_STR(vximod)" \
-c -o /usr/local/nivxi/src/.tmp_vxi.o /usr/local/nivxi/src/vxi.c

    In file included from /usr/local/nivxi/src/vxi.c:13:
    /usr/local/nivxi/src/mutex.h:59:42: error: macro "mutex_acquire" requires 4 arguments, but only 1 given
    In file included from /usr/local/nivxi/src/vxi.c:13:
    /usr/local/nivxi/src/mutex.h:59: warning: ‘regparm’ attribute only applies to function types
    /usr/local/nivxi/src/mutex.h:59: warning: ‘cdecl’ attribute only applies to function types
    /usr/local/nivxi/src/mutex.h:61:42: error: macro "mutex_release" requires 3 arguments, but only 1 given
    /usr/local/nivxi/src/mutex.h:61: warning: ‘regparm’ attribute only applies to function types
    /usr/local/nivxi/src/mutex.h:61: warning: ‘cdecl’ attribute only applies to function types
    /usr/local/nivxi/src/vxi.c:128:31: error: macro "mutex_acquire" requires 4 arguments, but only 1 given
    /usr/local/nivxi/src/vxi.c:133:31: error: macro "mutex_release" requires 3 arguments, but only 1 given
    /usr/local/nivxi/src/vxi.c:146:31: error: macro "mutex_acquire" requires 4 arguments, but only 1 given
    /usr/local/nivxi/src/vxi.c:158:31: error: macro "mutex_release" requires 3 arguments, but only 1 given
    /usr/local/nivxi/src/vxi.c: In function ‘vxi_mmap’:
    /usr/local/nivxi/src/vxi.c:243: error: implicit declaration of function ‘remap_page_range’
    make[2]: *** [/usr/local/nivxi/src/vxi.o] Error 1
    make[1]: *** [_module_/usr/local/nivxi/src] Error 2
    make[1]: Leaving directory `/usr/src/kernels/2.6.18-238.el5-i686'
    make: *** [default] Error 2
2
  • Rename nivxicc's mutex functions (and doing so across its entire source, not just the .h file) and that should do it.
    – user611775
    Feb 16, 2011 at 0:37
  • @user can't, see last sentence of 1st paragraph and all of 2nd paragraph of my Question
    – SiegeX
    Feb 16, 2011 at 1:35

1 Answer 1

3

The problem will not be in your object file as macros have file-scope and are replaced by the preprocessor. Thus after being compiled, the macro no longer exists as far as your nivxi.o file is concerned.

The issue is probably in your mutex.h file. I would look at the top and you will likely see an #include <lockdep.h> line. Thus once the preprocessor gets down to your function definition, it treats mutex_acquire as a token to be replaced (with the wrong number of arguments).

The easiest way to solve your problem will be to #undef mutex_acquire and #undef mutex_release at the beginning of mutex.h. This will prevent the preprocessor from replacing the tokens in your mutex.h. Since defines have file-scope, you don't need to worry about this propagating beyond your application

3
  • Thanks for the reply. Unfortunately, an #undef CONFIG_DEBUG_LOCK_ALLOC won't work because you'll notice the #else clause that still defines a mutex_acquire and mutex_release regardless. Also, although these are macro's in the <linux/lockdep.h> header, they are first-class function declarations in "mutex.h" which is why nivxi.o has them linked in and is complaining. The only kludge fix I've found so far is to alter <linux/lockdep.h> and wrap that macro block with #ifndef NOLOCKDEP and then issue -DNOLOCKDEP as a compiler flag.
    – SiegeX
    Feb 15, 2011 at 21:52
  • Ah, I missed the nested defines. I've edited the solution above. This should keep your modifications contained to within your module
    – Seth
    Feb 16, 2011 at 1:55
  • Thanks, this did the trick without having to alter the <linux/lockdep.h> header
    – SiegeX
    Feb 16, 2011 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.