os-tutorial
os-tutorial copied to clipboard
lesson 13: undefined reference to "_GLOBAL_OFFSET_TABLE"
when I was using ld to link kernel.o and kernel_entry.o, the error below happens
make \n kernel.o: In function ' dummy_test_entrypoint': \n kernel.c (.text+0x9): undefined reference to '_GLOBAL_OFFSET_TABLE_' \n
Any workarounds?
I tried removing option --oformat binary
, it compiles successfully, but I encounters qemu flickering issue like last issue from other user
@littlephone add --ignore-unresolved-symbol _GLOBAL_OFFSET_TABLE_
to ld
's args
You need to build a cross compiler from source in order to build this project. The default one in Linux won't work for you. You can see OSDev Wiki
Do not add --ignore-unresolved-symbol _GLOBAL_OFFSET_TABLE_
to LD. You hid the problem, but didn't solve it. Add -fno-PIC
to your C FLAGS for compiling and -no-PIE
when you link. On OSDev forum we've seen some questions of kernels not working and this was the root cause. It is preferable to use a cross compiler as Travor suggested.
@mpetch , I tried using -fno-noPIC and -fno-PIE. I did not get any error on compiling but while linking i got this error:-
ld: -f may not be used without -shared
Please help!
@motosoftos, Did you use a cross compiler or the built-in one. Most of the time when the system compiler or linker pops up error, it is preferable to build a cross compiler from source. You may refer the instructions at https://wiki.osdev.org/GCC_Cross-Compiler
From: motosoftos [email protected] Sent: Wednesday, October 9, 2019 16:28 To: cfenollosa/os-tutorial Cc: Travor Liu; Manual Subject: Re: [cfenollosa/os-tutorial] lesson 13: undefined reference to "_GLOBAL_OFFSET_TABLE" (#16)
@mpetchhttps://github.com/mpetch , I tried using -fno-noPIC and -fno-PIE. I did not get any error on compiling but while linking i got this error:-
ld: -f may not be used without -shared
Please help!
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/cfenollosa/os-tutorial/issues/16?email_source=notifications&email_token=AF5X74PK3GPKTDS3FUGLGWDQNWI35A5CNFSM4DH377O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAXCS7Y#issuecomment-539896191, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AF5X74P7OSYXFUGOHNZSDNLQNWI35ANCNFSM4DH377OQ.
Sorry, i left that and came back to make it in assembly...
Today I tried with the flags suggested by @mpetch regarding the flags -fno-PIC
(for gcc
) and -no-PIE
(for ld
). https://github.com/cfenollosa/os-tutorial/issues/16#issuecomment-460016961 It works like a charm! Thank you @mpetch .
The following are my commands fwiw. Please note you have to pass -m32
for gcc
and -m elf_i386
for the i386 qemu in the lesson13 of the tutorial:
$ gcc -ffreestanding -c kernel.c -m32 -fno-PIC -o kernel.o
$ ld -no-PIE -m elf_i386 -o kernel.bin -Ttext 0x1000 kernel_entry.o kernel.o --oformat binary
ld: warning: cannot find entry symbol _start; defaulting to 0000000000001000
Compiled and linked with my Ubuntu Mate 18.04 x86 laptop.