Problem porting newlib

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Problem porting newlib

Post by gerryg400 »

I have cross-compiled binutils/gcc/newlib. I've been using them to build my 64bit, -2GB kernel. Everything has been going well for months. I'm careful not to call malloc, printf and the like for the obvious reason and have my own kprintf and kmalloc etc.

The problem is that now I'm starting to port my apps. Some functions, like 'open' link okay, whenever I call 'printf' or 'malloc' and others I get messages like this

Code: Select all

/Users/gerryg/tools/newlib-build/x86_64-artix/newlib/libc/stdio/printf.c:29: relocation truncated to fit: R_X86_64_32 against `.text'
Does anyone have any idea what the problem might be?

I've just realised that I didn't supply any memory model (-mcmodel=kernel) to build newlib. Could that be the problem? Do I need 2 different builds of newlib? One for kernel space and one for user?
Thanks.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Combuster
Member
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: Problem porting newlib

Post by Combuster »

"relocation truncated to fit" means that linking could not be done properly because the value that needed to be written was too large for the space reserved for it. Does the relocation in question use an address that's more than 2GB away? Posting the relevant objdump output would also help.

Even though the message is listed as a "warning" it's actually an error: The result does not work. If you use the broken relocation your code will access/go somewhere it shouldn't.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Problem porting newlib

Post by gerryg400 »

Thanks Combuster. I just did a test.

I built my kernel WITH "-mcmodel=kernel" and my own little kernel library without WITHOUT "-mcmodel=kernel". I get the same error. In particular my own kprintf.o won't link. It uses global data (spinlocks and buffers).

So I suspect that the problem is that I am linking against a library with a different memory model than my main program. And I suppose it depends on the individual function whether this actually matters. I guess str*, mem* etc are okay because they don't use global data (and possible don't call any external function calls ). The problem functions, printf, malloc DO use globals, and in fact probably call functions (like Syscall) that I am supplying.

Do you think I need 2 versions of libc.a ? One for the kernel and one for the apps.

If so, is how will I tell newlib to build with "-mcmodel=kernel" ?
If a trainstation is where trains stop, what is a workstation ?
Post Reply