Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lesson 13: undefined reference to "_GLOBAL_OFFSET_TABLE" #16

Open
littlephone opened this issue Apr 17, 2017 · 8 comments
Open

lesson 13: undefined reference to "_GLOBAL_OFFSET_TABLE" #16

littlephone opened this issue Apr 17, 2017 · 8 comments

Comments

@littlephone
Copy link

littlephone commented Apr 17, 2017

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?

@littlephone
Copy link
Author

littlephone commented Apr 17, 2017

I tried removing option --oformat binary, it compiles successfully, but I encounters qemu flickering issue like last issue from other user

@iosmanthus
Copy link

iosmanthus commented Aug 22, 2017

@littlephone add --ignore-unresolved-symbol _GLOBAL_OFFSET_TABLE_ to ld's args

@TravorLZH
Copy link

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

@mpetch
Copy link

mpetch commented Feb 3, 2019

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.

@ghost
Copy link

ghost commented Oct 9, 2019

@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!

@TravorLZH
Copy link

TravorLZH commented Oct 9, 2019 via email

@ghost
Copy link

ghost commented Feb 24, 2020

Sorry, i left that and came back to make it in assembly...

@tai271828
Copy link

Today I tried with the flags suggested by @mpetch regarding the flags -fno-PIC (for gcc) and -no-PIE (for ld). #16 (comment) 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants