undefined reference to my irq function
-
- Member
- Posts: 62
- Joined: Mon Jan 07, 2013 10:38 am
undefined reference to my irq function
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
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
Function names are different in the declaration from the definition. Didn't you see it ?
Re: undefined reference to my irq function
gcc default not to generate underscore, as contrast with VC.
-
- Member
- Posts: 62
- Joined: Mon Jan 07, 2013 10:38 am
Re: undefined reference to my irq function
i've tried by removing the _ from the definition bt still its not working
-
- Member
- Posts: 62
- Joined: Mon Jan 07, 2013 10:38 am
Re: undefined reference to my irq function
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..
- Combuster
- 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
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.
What concerns me more however, is that your current approach is actually including windows libraries.
-
- Member
- Posts: 62
- Joined: Mon Jan 07, 2013 10:38 am
Re: undefined reference to my irq function
so how can i put the assembly code in the section
-
- Member
- Posts: 62
- Joined: Mon Jan 07, 2013 10:38 am
Re: undefined reference to my irq function
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
im new in this so if u cud help me out here
- Griwes
- 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
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
<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
Re: undefined reference to my irq function
Code: Select all
objdump -x xxxxx.o
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.
- Combuster
- 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
It's caused by you not doing your homework. See the forum rules for hintsdansmahajan wrote:please if u could put some light on how my approach is including the windows lib...
-
- Member
- Posts: 62
- Joined: Mon Jan 07, 2013 10:38 am
Re: undefined reference to my irq function
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 ??
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
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.
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.