Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
19 June, 2013, 01:25:13 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2 3   Go Down
  Print  
Author Topic: ELF Loader for Ndless - (now ready for non-dev use) -  (Read 3014 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
tangrs
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: Yesterday at 00:06:05
Date Registered: 13 July, 2011, 04:32:25
Location: Australia
Posts: 190

Topic starter
Total Post Ratings: +89

View Profile WWW
« on: 15 December, 2011, 11:41:52 »
+1

The ELF loader has reached a stage where most people can use it to load basic stuff.

When you run the program, it installs a hook. After that, you can load ELF files as if you'd load a normal Ndless binary.

More instructions on how to compile the loader and how to develop applications that take advantage of it are described in the README.

You can get the source code on Github.

Happy deving!

I'd also like to thank everyone who contributed to Ndless. I did borrow some of Ndless's code for use in this loader.

Original post:

I'm not sure if it's relevant here, but I'm developing an opensource ELF loader for Ndless.

I'm writing this because the current Ndless way of loading binaries doesn't work for code that relies on static initialization of pointers.

I.e. code like this doesn't work:


1
2
3
4
5
6
7
8
9
void foo() {
  //blah
}

int main() {
  static void (*var)() = foo; //Since it's static, the address will be inserted at link time (which is 0x8000+offset on my machine)
  var(); //The GOT based relocation code in Ndless currently does not update the static variable function pointer.
  return 0; //Crash
}

Unfortunately, there's no way to fix this because Ndless binaries are converted into a memory image before running. That means the relocation code doesn't know what to update in the .data section of the memory because it doesn't know what symbols exist and need updating and where they're located.

Loading from an ELF file works because the symbol definitions are there and the relocation code knows where to find the bits that need patching. That's why I wrote this ELF loader.

Anyway, the core code is there, just needs a lot of polishing up.

If anyone wants to help, the source code is available on Github https://github.com/tangrs/ndless-elfloader
I'm hoping eventually, it will be integrated into the program loader on Ndless.

Thanks for your time,
Apologies if this is the wrong forum to post.
« Last Edit: 17 January, 2012, 07:40:47 by tangrs » Logged
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 22:29:56
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1736


Total Post Ratings: +180

View Profile WWW
« Reply #1 on: 15 December, 2011, 12:09:01 »
0

Interesting Smiley

I don't however know much about this subject to give a good response Tongue
But thanks for sharing Smiley

(on a side note, did you get my pm of a few day's ago?)
Logged

tangrs
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: Yesterday at 00:06:05
Date Registered: 13 July, 2011, 04:32:25
Location: Australia
Posts: 190

Topic starter
Total Post Ratings: +89

View Profile WWW
« Reply #2 on: 15 December, 2011, 12:20:45 »
0

Interesting Smiley

I don't however know much about this subject to give a good response Tongue
But thanks for sharing Smiley

(on a side note, did you get my pm of a few day's ago?)

Yeah, I did. I couldn't respond because I'm a new user and can't send messages yet or something.
Logged
Lionel Debroux
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 22:15:45
Date Registered: 17 December, 2009, 09:37:25
Location: France
Posts: 1916

Total Post Ratings: +215

View Profile WWW
« Reply #3 on: 15 December, 2011, 12:23:11 »
0

Interesting indeed Smiley

The flip side of the coin of the power of ELF is its complexity, and the weight of a full-featured launcher. In the past, there were discussions about using BFLT, which is a much simpler format, easily derived from ELF, and fulfills the purpose you're describing.
Logged

Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.
tangrs
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: Yesterday at 00:06:05
Date Registered: 13 July, 2011, 04:32:25
Location: Australia
Posts: 190

Topic starter
Total Post Ratings: +89

View Profile WWW
« Reply #4 on: 15 December, 2011, 12:25:52 »
0

BFLT does look interesting. I'll look into it.

Out of curiosity, why was BFLT never used?

Edit: You're right. ELF is pretty complex. Out of the week I spent on the project, 4-5 days were spent just reading and re-reading manuals and example code Big smile
« Last Edit: 15 December, 2011, 12:29:34 by tangrs » Logged
Lionel Debroux
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Yesterday at 22:15:45
Date Registered: 17 December, 2009, 09:37:25
Location: France
Posts: 1916

Total Post Ratings: +215

View Profile WWW
« Reply #5 on: 15 December, 2011, 13:49:22 »
0

Quote
Out of curiosity, why was BFLT never used?
Well, I think it has been much more a matter of finding enough free time, than a matter of feasibility Smiley
Logged

Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.
tangrs
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: Yesterday at 00:06:05
Date Registered: 13 July, 2011, 04:32:25
Location: Australia
Posts: 190

Topic starter
Total Post Ratings: +89

View Profile WWW
« Reply #6 on: 17 December, 2011, 14:12:39 »
0

Quote
Out of curiosity, why was BFLT never used?
Well, I think it has been much more a matter of finding enough free time, than a matter of feasibility Smiley

Ahhh, I see. That makes sense.
Logged
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 17 June, 2013, 22:09:26
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 772

Total Post Ratings: +152

View Profile
« Reply #7 on: 18 December, 2011, 12:44:45 »
0

Interesting tangrs.

But integrating to Ndless an ELF loader seems to be a bit overkilled just to support static initializers.
It's true that this would be annoying for initialization of arrays, but there's a simple workaround for this with nl_relocdata().
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
tangrs
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: Yesterday at 00:06:05
Date Registered: 13 July, 2011, 04:32:25
Location: Australia
Posts: 190

Topic starter
Total Post Ratings: +89

View Profile WWW
« Reply #8 on: 18 December, 2011, 13:37:53 »
0

Interesting tangrs.

But integrating to Ndless an ELF loader seems to be a bit overkilled just to support static initializers.
It's true that this would be annoying for initialization of arrays, but there's a simple workaround for this with nl_relocdata().

Oh, I know for c there are workarounds easily but I'm also working on getting C++ code working on Ndless and vtables and the lot are a lot more difficult to relocate using workarounds. That was what the ELF loader was originally for haha.

Though I do agree it might be a bit of an overkill especially considering this is an embedded platform.

Thanks for the insights guys, you guys pointed out some things I overlooked Smiley
Logged
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 17 June, 2013, 22:09:26
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 772

Total Post Ratings: +152

View Profile
« Reply #9 on: 18 December, 2011, 17:23:31 »
0

I see. But you can probably keep your ELF loader in user space until you reach a stable C++ toolchain, I then may integrate both if you want.
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
alberthrocks
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Last Login: 11 June, 2013, 19:34:32
Date Registered: 01 May, 2010, 16:51:27
Posts: 743

Total Post Ratings: +88

View Profile
« Reply #10 on: 18 December, 2011, 18:43:27 »
0

I think an ELF loader would be amazing Cheesy It would allow C++ support, and (possibly) dynamic libraries! Cheesy (Although I don't think dynamic libraries would be good on the Nspire - a bundled, static package is more portable - it still will be useful for some other aspects and the thought of it being possible is nice Smiley

On a somewhat related note, is the Newlib issue on the wiki still relevant? I see that we are including newlib in the API building...
Logged

Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! Sad Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. Smiley

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler for "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it Tongue)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it Tongue)
wxWabbitemu: 40% done (NEED MOAR FEATURES Tongue)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming Tongue)
tangrs
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: Yesterday at 00:06:05
Date Registered: 13 July, 2011, 04:32:25
Location: Australia
Posts: 190

Topic starter
Total Post Ratings: +89

View Profile WWW
« Reply #11 on: 18 December, 2011, 23:27:57 »
0

I see. But you can probably keep your ELF loader in user space until you reach a stable C++ toolchain, I then may integrate both if you want.

Thanks, that would be great!

I think an ELF loader would be amazing Cheesy It would allow C++ support, and (possibly) dynamic libraries! Cheesy (Although I don't think dynamic libraries would be good on the Nspire - a bundled, static package is more portable - it still will be useful for some other aspects and the thought of it being possible is nice Smiley

On a somewhat related note, is the Newlib issue on the wiki still relevant? I see that we are including newlib in the API building...

Haha, dynamic libraries would be pretty interesting but would get pretty damn messy Big smile
Logged
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 17 June, 2013, 22:09:26
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 772

Total Post Ratings: +152

View Profile
« Reply #12 on: 19 December, 2011, 23:18:41 »
0

On a somewhat related note, is the Newlib issue on the wiki still relevant? I see that we are including newlib in the API building...

Yes It's still relevant.
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 17 June, 2013, 22:09:26
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 772

Total Post Ratings: +152

View Profile
« Reply #13 on: 27 December, 2011, 11:02:35 »
0

tangrs, I see on your blog that you actually have a C++ build chain that works more or less. Do C++ programs now runs with your ELF loader?
What are the "required functions" not implemented by Ndless that exception handling needs?
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
tangrs
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: Yesterday at 00:06:05
Date Registered: 13 July, 2011, 04:32:25
Location: Australia
Posts: 190

Topic starter
Total Post Ratings: +89

View Profile WWW
« Reply #14 on: 27 December, 2011, 12:27:15 »
0

tangrs, I see on your blog that you actually have a C++ build chain that works more or less. Do C++ programs now runs with your ELF loader?
What are the "required functions" not implemented by Ndless that exception handling needs?

Yes, the ELF loader loads most C++ programs. There's still more testing to do though but it works for the basic test programs I wrote.

The C++ buildchain is really a hit and miss kind of thing. I can't remember what kind of things the C++ compiler needed to handle exceptions - I remember that the linker was complaining about missing symbols related to C++ exceptions. I'll look into what exactly is needed for exceptions though.

Edit: Probably something like this would work.
« Last Edit: 27 December, 2011, 12:43:45 by tangrs » Logged
Pages: [1] 2 3   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.416 seconds with 32 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.