ld acting extremely weird with multiple input files
Posted: Sat Jun 25, 2011 6:33 am
Yesterday I decided to split a part of my project into multiple files, since the main file was becoming too big
I moved the IDE driver to its own file, and since both that and my main file used both used IO functions like outb I moved those to their own file too
Now, recompiling it, ld is acting extremely weird, it is skipping over functions in one of my input files (outb in io.o)
My build script:
If i move io.o to before sysldr.o, it skips the entire file, if i move it before ide.o, it skips about half of it
And, taking a look at my link map, i see this:
outb is missing! and yes, it is (obviously) defined in io.c
objdump also shows that outb is in io.o, so its all compiled properly
ld throws these errors:
Some code if it helps:
io.h
io.c
I moved the IDE driver to its own file, and since both that and my main file used both used IO functions like outb I moved those to their own file too
Now, recompiling it, ld is acting extremely weird, it is skipping over functions in one of my input files (outb in io.o)
My build script:
Code: Select all
i586-elf-gcc -c sysldr.c ide.c io.c
i586-elf-ld -T link.ld -o sysldr.bin -Map sysldr.map sysldr.o ide.o io.o
And, taking a look at my link map, i see this:
Code: Select all
.text 0x0000a464 0xa7 io.o
0x0000a480 inb
0x0000a4a8 outl
0x0000a4be inl
0x0000a4e6 insl
objdump also shows that outb is in io.o, so its all compiled properly
ld throws these errors:
Code: Select all
ide.c:(.text+0x1c2): undefined reference to `outb'
ide.c:(.text+0x1fc): undefined reference to `outb'
ide.c:(.text+0x233): undefined reference to `outb'
ide.c:(.text+0x26a): undefined reference to `outb'
io.h
Code: Select all
void outb(unsigned short port, unsigned char val);
unsigned char inb(unsigned short port);
void outl(unsigned short port, unsigned long val);
unsigned long inl(unsigned short port);
void insl(unsigned short port, void *buffer, unsigned long len);
Code: Select all
void outb(unsigned short port, unsigned char val)
{
asm volatile( "outb %0, %1" : : "a"(val), "Nd"(port) );
}
unsigned char inb(unsigned short port)
{
unsigned char ret;
asm volatile( "inb %1, %0" : "=a"(ret) : "Nd"(port) );
return ret;
}
void outl(unsigned short port, unsigned long val)
{
asm volatile( "outl %0, %1" : : "a"(val), "Nd"(port) );
}
unsigned long inl(unsigned short port)
{
unsigned long ret;
asm volatile( "inl %1, %0" : "=a"(ret) : "Nd"(port) );
return ret;
}
void insl(unsigned short port, void *buffer, unsigned long len)
{
asm volatile( "rep insl" : : "Nd"(port), "D"(buffer), "c"(len) );
}