Problem with linking my kernel with libk.
Posted: Mon Aug 16, 2021 3:20 pm
In libk.a file, there are many functions including printf, memset and itoa. However, when I try to link it with the kernel from BOOTBOOT example (mykernel/c/ in BOOTBOOT repository) which I modified to use printf function from my libk instead of puts defined in this file, I get this error:
(I use same linker script and I also link it with font.psf just like in BOOTBOOT example)
This is weird. I wanted to know is this a problem with my libk, linker script or command so I wrote such simple program in asm:
I'm able to link this code with mentioned kernel without any problems, however, when I want to link my libk with it I get weird error. So this should be the problem with my libk, but I used it many times in my previous OS's and it worked...
"printf" and other required functions ARE in libk.a:
I tried many options. I compiled libk.a as PIC, like normal library, I tried different compiler and linker options but could not get this to work.
Here's my code: https://we.tl/t-o8GDiazQot
In order to compile it just run "make" command in root directory, but you need x86_64-elf cross compiler and toolchain.
(I use same linker script and I also link it with font.psf just like in BOOTBOOT example)
Code: Select all
x86_64-elf-gcc --sysroot=/home/<...>/sysroot -isystem=/usr/include -nostdlib -nostartfiles -T kernel.ld -nostdlib -lk -lgcc kernel/kernel.o rc/font.o utils/tty.o -o sielawix.kernel
x86_64-elf-strip -s -K mmio -K fb -K bootboot -K environment -K initstack sielawix.kernel
/usr/local/lib/gcc/x86_64-elf/10.0.0/../../../../x86_64-elf/bin/ld: kernel/kernel.o: in function `_start':
kernel.c:(.text+0x1b0): undefined reference to `printf'
/usr/local/lib/gcc/x86_64-elf/10.0.0/../../../../x86_64-elf/bin/ld: utils/tty.o: in function `tty_clear':
tty.c:(.text+0xc0): undefined reference to `memset'
/usr/local/lib/gcc/x86_64-elf/10.0.0/../../../../x86_64-elf/bin/ld: utils/tty.o: in function `tty_puti':
tty.c:(.text+0x56f): undefined reference to `itoa'
/usr/local/lib/gcc/x86_64-elf/10.0.0/../../../../x86_64-elf/bin/ld: utils/tty.o: in function `tty_putl':
tty.c:(.text+0x59f): undefined reference to `itoa64'
collect2: error: ld returned 1 exit status
Code: Select all
BITS 64
global printf
printf:
nop
nop
"printf" and other required functions ARE in libk.a:
Code: Select all
readelf -s sysroot/usr/lib/libk.a
File: sysroot/usr/lib/libk.a(printf.libk.o)
Symbol table '.symtab' contains 21 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS printf.c
2: 0000000000000000 0 SECTION LOCAL DEFAULT 1
3: 0000000000000000 0 SECTION LOCAL DEFAULT 3
4: 0000000000000000 0 SECTION LOCAL DEFAULT 4
5: 0000000000000000 0 SECTION LOCAL DEFAULT 5
6: 0000000000000000 0 SECTION LOCAL DEFAULT 7
7: 0000000000000000 0 SECTION LOCAL DEFAULT 8
8: 0000000000000000 0 SECTION LOCAL DEFAULT 9
9: 0000000000000000 0 SECTION LOCAL DEFAULT 11
10: 0000000000000000 0 SECTION LOCAL DEFAULT 12
11: 0000000000000000 0 SECTION LOCAL DEFAULT 14
12: 0000000000000000 0 SECTION LOCAL DEFAULT 16
13: 0000000000000000 0 SECTION LOCAL DEFAULT 15
14: 0000000000000000 1129 FUNC GLOBAL DEFAULT 1 vprintf
15: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND strlen
16: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND putchar
17: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND itoa
18: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND tty_puts
19: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND itoa64
20: 0000000000000470 148 FUNC GLOBAL DEFAULT 1 printf
.
.
.
Here's my code: https://we.tl/t-o8GDiazQot
In order to compile it just run "make" command in root directory, but you need x86_64-elf cross compiler and toolchain.