undefined reference to my irq function

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
dansmahajan
Member
Member
Posts: 62
Joined: Mon Jan 07, 2013 10:38 am

undefined reference to my irq function

Post 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
User avatar
alix
Posts: 12
Joined: Tue Nov 13, 2012 3:56 pm

Re: undefined reference to my irq function

Post by alix »

Function names are different in the declaration from the definition. Didn't you see it :shock:?
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: undefined reference to my irq function

Post by bluemoon »

gcc default not to generate underscore, as contrast with VC.
dansmahajan
Member
Member
Posts: 62
Joined: Mon Jan 07, 2013 10:38 am

Re: undefined reference to my irq function

Post by dansmahajan »

i've tried by removing the _ from the definition bt still its not working
dansmahajan
Member
Member
Posts: 62
Joined: Mon Jan 07, 2013 10:38 am

Re: undefined reference to my irq function

Post 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..
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: undefined reference to my irq function

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
dansmahajan
Member
Member
Posts: 62
Joined: Mon Jan 07, 2013 10:38 am

Re: undefined reference to my irq function

Post by dansmahajan »

so how can i put the assembly code in the section
dansmahajan
Member
Member
Posts: 62
Joined: Mon Jan 07, 2013 10:38 am

Re: undefined reference to my irq function

Post 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
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: undefined reference to my irq function

Post by Griwes »

And "u" could try to show us a bit of effort (like writing "you" instead of "u" et cetera).
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
mutex
Member
Member
Posts: 131
Joined: Sat Jul 07, 2007 7:49 pm

Re: undefined reference to my irq function

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: undefined reference to my irq function

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
dansmahajan
Member
Member
Posts: 62
Joined: Mon Jan 07, 2013 10:38 am

Re: undefined reference to my irq function

Post 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 ??
lcjuanpa
Posts: 8
Joined: Fri Feb 15, 2013 9:24 pm

Re: undefined reference to my irq function

Post 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.
Post Reply