title: Howto resolve a function name conflict when compiling a kernel module
body: <p>I'm trying to compile a 3rd party kernel module for RHEL 5.6 and it is failing due to function name conflicts with <code>mutex_acquire</code> and <code>mutex_release</code>.  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 <code>mutex.c</code> and <code>mutex.h</code> which define these functions.  Unfortunately there is an object file <code>nivxi.o</code> upon which no source code is distributed and this object file is calling <code>mutex_acquire</code> and <code>mutex_release</code> so I cannot just simply alter their names. </p>
  
  <p>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 <code>mutex_acquire</code> or <code>mutex_release</code>; presumably due to <code>nivxi.o</code></p>
  
  <p>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?</p>
  
  <h3>mutex.h</h3>
  
  <pre><code>NIVXICC void mutex_acquire(mutex_t *mutex);
  NIVXICC void mutex_release(mutex_t *mutex);
  </code></pre>
  
  <h3>nivxicc.h (just incase this is pertinent)</h3>
  
  <pre><code>#ifndef NIVXICC_H
  #define NIVXICC_H
  #define NIVXICC __attribute__((regparm(0))) __attribute__((cdecl))
  #endif
  </code></pre>
  
  <h3>/usr/include/lockdep.h (conflicting definition)</h3>
  
  <pre><code>#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
  </code></pre>
  
  <h3>Error</h3>
  
  <pre><code># 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 &amp;&amp; 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
  </code></pre>