Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: alberthrocks on September 17, 2012, 05:33:15 pm

Title: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: alberthrocks on September 17, 2012, 05:33:15 pm
(Not to be confused with calculator linking)

I am currently developing two big projects, one public and one secret! They are both C based, and are very exciting to develop!
However... there are always concerning linking problems! The code can be perfectly valid, but it will never compile/link! There are also some interesting features that I would like to see in ndless, which if possible, I'd like to help with.

That said, here are some things that I would like to get fixed:
1) Standard C Library Collisions (or undefined references!)
This applies to both projects, though the public one's error messages were shorter and probably easier to fix:
Code: [Select]
nspire-ld obj/*.o -L./nrgbsdk/lib -lRGB -lgcc -nostdlib -lc -lm -o nrgbwabbit
/usr/local/arm/lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/libc.a(lib_a-svfscanf.o): In function `__ssvfscanf_r':
/home/albert/ndless/modern_toolchain/build/arm-none-eabi/newlib/libc/stdio/../../../../../newlib-1.20.0/newlib/libc/stdio/vfscanf.c:1584: undefined reference to `__aeabi_d2f'
/usr/local/arm/lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/libc.a(lib_a-syscalls.o): In function `_sbrk':
/home/albert/ndless/modern_toolchain/build/arm-none-eabi/newlib/libc/sys/arm/../../../../../../newlib-1.20.0/newlib/libc/sys/arm/syscalls.c:499: undefined reference to `end'
/usr/local/arm/lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/lib/libc.a(lib_a-strtod.o): In function `strtof':
/home/albert/ndless/modern_toolchain/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib-1.20.0/newlib/libc/stdlib/strtod.c:1194: undefined reference to `__aeabi_d2f'
collect2: ld returned 1 exit status
This does NOT link to the standard library and instead depends on the ndless syscalls and definitions. However, this causes problems, as seen above. When linking with the standard library, it ends up having multiple definition errors instead. Maybe there could be a define allowing the use of newlib instead?

2) New feature: ELF loader with dynamic libraries support
BFLT does *not* implement this at all. Only ELF can load dynamic libraries on the fly (dlopen, dlsym, etc.). This would be very useful for plugin support in my secret project, which works but is very limited without ELF support.

3) Multithreading
This may or may not be needed for SDLWabbitemu, but it would be nice to have. tangrs I believe made a proof of concept, and NUCLEUS OS indicates support for it. (Maybe there's a syscall out there?)

4) Secret project with secret changes requested to disable something with a define. :P (ExtendeD knows what I'm referring to - I am willing to create the patches for that if you don't have time!)

Thanks in advance!
Title: Re: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: Lionel Debroux on September 18, 2012, 01:04:29 am
ELF is very complicated. tangrs had made an ELF loader, but ELF files could be overly big in some simple cases.

And Nucleus is indeed a multi-threaded RTOS.
Title: Re: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: alberthrocks on September 18, 2012, 09:42:25 am
ELF is very complicated. tangrs had made an ELF loader, but ELF files could be overly big in some simple cases.
Yes indeed... but dynamically loading libraries is essential for any application that depends of plugins written in C.
I guess what I'm asking for is some implementation of dlopen(), dlsym(), and dlclose() for BFLT.

And Nucleus is indeed a multi-threaded RTOS.
Yup, as I thought: http://www.mentor.com/embedded-software/nucleus/kernel
Title: Re: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: ExtendeD on September 18, 2012, 05:00:47 pm
1) Try to remove the -nostdlib switch and any #include directive for the standard headers. Conflicts between newlib and os.h are an Ndless design flaw, sorry about that.

3) This may only be a matter of exporting the pthreads definition from the OS (for example phtread_create() an pthread_join() have already be found: https://www.unsads.com/scm/svn/nsptools/symbols/trunk/OS_cascx-3.1.0.idc [guest/guest]).
But the OS clock cursor will once again annoy us since interrupts must be able for these functions to work.
Title: Re: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: alberthrocks on September 18, 2012, 07:23:08 pm
1) Try to remove the -nostdlib switch and any #include directive for the standard headers. Conflicts between newlib and os.h are an Ndless design flaw, sorry about that.
In the end, this is what I did:
 - open Ndless-SDK/ndless/system/ldscript and add end = .;
 - open Ndless-SDK/ndless/system/osstub.c and comment out void _exit(void) { exit(-1); } and rebuild Ndless
 - build the object files with -nostdlib
 - at linking, remove -nostdlib
It builds successfully, but it doesn't load at all (and crashes)! Not sure what is happening now... I guess I'll have to find a way to hook up GDB to the nspire_emu.

3) This may only be a matter of exporting the pthreads definition from the OS (for example phtread_create() an pthread_join() have already be found: https://www.unsads.com/scm/svn/nsptools/symbols/trunk/OS_cascx-3.1.0.idc [guest/guest]).
But the OS clock cursor will once again annoy us since interrupts must be able for these functions to work.
Ah, interesting! I would assume that there would be more API functions that are hidden (like pthread_exit()), of course. And for the OS clock cursor, are you referring to the startup screen? Is there no way to disable that?

As always, thank you for your help! :)
Title: Re: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: Lionel Debroux on September 19, 2012, 01:38:01 am
Quote
And for the OS clock cursor, are you referring to the startup screen? Is there no way to disable that?
The clock cursor does indeed appear on the startup screen, but he's talking about the clock cursor which appears during the execution of Ndless programs unless they disable interrupts :)
It would certainly be possible to perform brain surgery on the OS for having it not display this clock any longer (even when interrupts are enabled), but none of us ever did, AFAICT.
Title: Re: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: ExtendeD on September 19, 2012, 07:42:21 am
Although it's just a matter of setting a simple OS switch. Ndless really requires developers to help me handle all these requests, I can't do it alone anymore.

- open Ndless-SDK/ndless/system/osstub.c and comment out void _exit(void) { exit(-1); } and rebuild Ndless

What is this one for?


It builds successfully, but it doesn't load at all (and crashes)! Not sure what is happening now...

Using newlib functions is not recommended as long as tangr's bFLT loader hasn't been merged into Ndless, since some of these functions require relocation, and you can't guess which ones.


I guess I'll have to find a way to hook up GDB to the nspire_emu.

This one is also at the top of the TODO list.
Lionel Debroux has already merge my GDB stub into the latest (but not released publicly?) update of nspire_emu. I'll do some non-regression tests on Ndless and update the SDK with it as soon as possible.

Once again sorry for the delay. Fill free to contribute a way or another to all these tasks, I can give update rights to the repository to anyone I trust willing to contribute if needed.
Title: Re: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: alberthrocks on September 19, 2012, 12:21:29 pm
Although it's just a matter of setting a simple OS switch. Ndless really requires developers to help me handle all these requests, I can't do it alone anymore.
I would be more than happy to help when I have time, if I know this OS switch. :)

- open Ndless-SDK/ndless/system/osstub.c and comment out void _exit(void) { exit(-1); } and rebuild Ndless

What is this one for?
This is a modification to the SVN checkout of ndless to fix the "multiple definition of _exit()" error (building *.c with -nostdlib, then nspire-ld without that option). It links but crashes (of course).

Using newlib functions is not recommended as long as tangr's bFLT loader hasn't been merged into Ndless, since some of these functions require relocation, and you can't guess which ones.
Yeah, that's probably the cause of these crashes.


I guess I'll have to find a way to hook up GDB to the nspire_emu.

This one is also at the top of the TODO list.
Lionel Debroux has already merge my GDB stub into the latest (but not released publicly?) update of nspire_emu. I'll do some non-regression tests on Ndless and update the SDK with it as soon as possible.
That's great! I'm looking forward to seeing that integrated! (And perhaps in a release of the graphical version too!)

Once again sorry for the delay. Fill free to contribute a way or another to all these tasks, I can give update rights to the repository to anyone I trust willing to contribute if needed.
No problem! I'm busy as well, so I can understand your situation. (Again, only work when you get the chance!) I would love to get update rights, though I would prefer getting an experimental branch on the Ndless SVN** so I can push my changes to my own SVN branch without some innocent user accidentally blowing up their calculator! ;) Do you have any particular coding standards? Also, is there anything I need to know to get familiar with the code structure?

** Actually, I could create a Google Code SVN instead and do management from there, if the code can be public. It would be easier for anyone to add people that are willing to contribute. Later, when the code becomes stable, I can simply commit my repo to the official source tree. Let me know your opinion/decision on this! :)
Title: Re: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: Lionel Debroux on September 20, 2012, 01:34:02 am
Maybe an external Git repository, containing a mirror of the SVN as the main branch and experimental branches ?
Title: Re: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: ExtendeD on September 22, 2012, 02:37:03 am
Sure, an experimental branch on another repository would be a good idea.
Title: Re: Nspire (Ndless) C Linking Frenzy (+requests for Ndless)
Post by: alberthrocks on September 23, 2012, 12:17:30 pm
I've set up a Google Code repository for Ndless!
http://code.google.com/p/ndless/

I've also set up a branch for one of my own changes. The tree can be found here (http://code.google.com/p/ndless/source/browse/?name=lua-disable-support) and changes here (http://code.google.com/p/ndless/source/list?name=lua-disable-support).