Page 1 of 1

undefined reference to my irq function

Posted: Mon Jan 07, 2013 10:58 am
by dansmahajan
in irq.c..this is how my functions are declared
extern void irq0();
extern void irq1();
....
and their definitions are in my assembly file start.asm
global _irq0
global _irq1
..
_irq0:
cli
push byte 0
push byte 32
jmp irq_common_stub

_irq1:
cli
push byte 0
push byte 33
jmp irq_common_stub

and here is my linker script link.ld
ENTRY(_kmain)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}

where _kmain refers to my kernel's entry c main file

im using the mingw compliler and nasm assembler nad following are the commands im using to compiler the kernel
nasm -f win32 -o start.o start.asm

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o irq.o irq.c

ld -oformat -Tlink.ld start.o main.o irq.o
and im getting the following errors
irq.o : irq.c:(.text+0x10c): undefined reference to `irq0'
irq.o : irq.c:(.text+0x130): undefined reference to `irq1'

so what would could be the problem guys ??
p.s in linker script when i change the _kmain to start i get an error corresponding to undefined reference to _main

Re: undefined reference to my irq function

Posted: Mon Jan 07, 2013 11:09 am
by alix
Function names are different in the declaration from the definition. Didn't you see it :shock:?

Re: undefined reference to my irq function

Posted: Mon Jan 07, 2013 11:47 am
by bluemoon
gcc default not to generate underscore, as contrast with VC.

Re: undefined reference to my irq function

Posted: Mon Jan 07, 2013 12:43 pm
by dansmahajan
i've tried by removing the _ from the definition bt still its not working

Re: undefined reference to my irq function

Posted: Mon Jan 07, 2013 12:46 pm
by dansmahajan
also im able to call the function defined in C eg kmain bt not able to access the function defined in assembly which is declared as extern in c..

Re: undefined reference to my irq function

Posted: Mon Jan 07, 2013 12:52 pm
by Combuster
The typical other cause is that you didn't put your assembly code in a section.

What concerns me more however, is that your current approach is actually including windows libraries.

Re: undefined reference to my irq function

Posted: Mon Jan 07, 2013 1:07 pm
by dansmahajan
so how can i put the assembly code in the section

Re: undefined reference to my irq function

Posted: Mon Jan 07, 2013 1:22 pm
by dansmahajan
please if u could put some light on how my approach is including the windows lib...
im new in this so if u cud help me out here

Re: undefined reference to my irq function

Posted: Mon Jan 07, 2013 2:52 pm
by Griwes
And "u" could try to show us a bit of effort (like writing "you" instead of "u" et cetera).

Re: undefined reference to my irq function

Posted: Mon Jan 07, 2013 3:01 pm
by mutex

Code: Select all

objdump -x xxxxx.o
will you show what symobols that are inside the objects.

You should understand that nasm will create symbols with names _irq0 and _irq1 in the objectfile. If you dont tell gcc/gas to do the same it will look for the "extern" symbols without _ and there will be no match. Another option is to skip the _ in the nasm file. Depending on your preference.

Re: undefined reference to my irq function

Posted: Tue Jan 08, 2013 2:35 am
by Combuster
dansmahajan wrote:please if u could put some light on how my approach is including the windows lib...
It's caused by you not doing your homework. See the forum rules for hints :wink:

Re: undefined reference to my irq function

Posted: Mon Jan 21, 2013 11:10 am
by dansmahajan
i have tried the same procedure on the cross compiler but still i am getting the same error "Undefined reference to irq"
i have also tried the -fleading-underscore , -fnoleading-underscore but still problem is persisting...
so what should i do now ??

Re: undefined reference to my irq function

Posted: Sat Feb 16, 2013 8:48 am
by lcjuanpa
Hi dansmahajan

I suggest you that use objdum -t or nm programs to see the symbols table of your programs and delete those options such as -fleading-underscore , -fnoleading-underscore.