Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 660
  • Last Modified:

Linux and C Programming "undefined reference to function"

Hi

I've been working on the linux kernel itself. Let' me describe the problem. It's kind of long-winded.

I have modified the open.c file by adding in the following lines

out:
      #include <linux/bsm/audit-CHDIR.c>
      return error;

and at the beginning of this modified open.c file, I've added

#ifdef CONFIG_BSM_AUDIT
#include <linux/bsm/audit.h>
#endif

Inside the audit-CHDIR.c file, we have the line

      audit(&header, &event);

and inside the audit.h file, we have the line

int audit(audit_header*, void*);

All is well so far, until I compile the code. Apparently, compilation works fine because the audit function is declared in the audit.h header file. but an error occurred during the linking stage ( i assume this error message only occurs at linking stage)

fs/fs.o(.text+0x764): In function `sys_chdir':
: undefined reference to `audit'

The reason I can think of is that there is no way for the build system to know where audit function is DEFINED. The compiler knows that audit function is DECLARED in the audit.h file, but the linker has no idea that audit function is defined in /usr/src/linux/kernel/audit.c. And I don't know how to let the linker know about this.

Thanks for your help.


0
feelite
Asked:
feelite
  • 2
1 Solution
 
gysbert1Commented:
You would probably need to add a depency on audit.o in the Makefile, this will translate to a make auto-rule which will compile auto.c and link it in. I only have the 2.6.5 kernel source handy right now, but in that you'd probably want to edit /usr/src/linux/kernel/Makefile, and add audit.o to the obj-y line right at the beginning of the file.
0
 
feeliteAuthor Commented:
hi, thanks for reply. (btw, i'm using 2.4 kernel, FC1)

The only change I made to /usr/src/linux/kernel/Makefile is the addition of the following lines

ifeq ($(CONFIG_BSM_AUDIT),y)
OX_OBJS += audit.o
endif

I suppose it tells something about looking for the audit.o while linking this kernel.o. However, I'm new to the GNU Make system, the manual at the official site does not talk about things like OX_OBJS and stuff.

Also, how does the make system know where to look for the audit.o?


The full /usr/src/linux/kernel/Makefile reads the following


#
# Makefile for the linux kernel.
#
# Note! Dependencies are done automagically by 'make dep', which also
# removes any old dependencies. DON'T put your own dependencies here
# unless it's something special (ie not a .c file).
#
# Note 2! The CFLAGS definitions are now in the main makefile...

O_TARGET := kernel.o

export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o printk.o cpufreq.o profile.o module.o

obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o profile.o \
          module.o exit.o itimer.o info.o time.o softirq.o resource.o \
          sysctl.o acct.o capability.o ptrace.o timer.o user.o \
          signal.o sys.o kmod.o context.o \
          futex.o pid.o kksymoops.o

obj-$(CONFIG_UID16) += uid16.o
obj-$(CONFIG_MODULES) += ksyms.o
obj-$(CONFIG_PM) += pm.o
obj-$(CONFIG_CPU_FREQ) += cpufreq.o
obj-$(CONFIG_IKCONFIG) += configs.o
obj-$(CONFIG_KALLSYMS) += kallsyms.o

ifeq ($(CONFIG_BSM_AUDIT),y)
OX_OBJS += audit.o
endif

ifneq ($(CONFIG_IA64),y)
# According to Alan Modra <alan@linuxcare.com.au>, the -fno-omit-frame-pointer is
# needed for x86 only.  Why this used to be enabled for all architectures is beyond
# me.  I suspect most platforms don't need this, but until we know that for sure
# I turn this off for IA-64 only.  Andreas Schwab says it's also needed on m68k
# to get a correct value for the wait-channel (WCHAN in ps). --davidm
#
# Some gcc's are building so that O(1) scheduler is triple faulting if we
# build -O2. (Turns out to be a CPU issue. Update your microcode if you hit it)
#
CFLAGS_sched.o := $(PROFILING) -fno-omit-frame-pointer
endif

include $(TOPDIR)/Rules.make

configs.o: $(TOPDIR)/scripts/mkconfigs configs.c
      $(CC) $(CFLAGS) $(CFLAGS_KERNEL) -DEXPORT_SYMTAB -c -o configs.o configs.c

$(TOPDIR)/scripts/mkconfigs: $(TOPDIR)/scripts/mkconfigs.c
      $(HOSTCC) $(HOSTCFLAGS) -o $(TOPDIR)/scripts/mkconfigs $(TOPDIR)/scripts/mkconfigs.c

configs.c: $(TOPDIR)/.config $(TOPDIR)/scripts/mkconfigs
      $(TOPDIR)/scripts/mkconfigs $(TOPDIR)/.config configs.c
0
 
gysbert1Commented:
GNU make defines a number of auto rules for making certain things, there are options to list them and override them but I can't remember how. One of the auto-rules tells make how to generate an object file from a c file, so if you have a .o dependency somewhere which doesn't exist, it will look for a corresponding .c and compile it to an object file automatically.

OX_OBJS is nothing specific to GNU make AFAIK, it is just a variable to which you have added audit.o. I don't have FC1 or 2.4.x anymore, but I can't see OX_OBJS being used in the 2.6 makefile, I would have thought you should say something like
obj-y += audit.o
but I don't know the kernel make system well at all.
BTW, this
http://www.gnu.org/software/make/manual/html_chapter/make.html
is a very good GNU make reference/tutorial IMHO.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now