OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 25, 2024 10:19 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Ada and name mangling
PostPosted: Mon Jan 31, 2011 9:37 am 
Offline

Joined: Mon Jan 31, 2011 9:13 am
Posts: 5
Hello OSDev.org Community!

This is my first post on the forums, but I have been reading these threads for about two years now, give or take a bit. I find this place to be one of my most valuable resources to developing my own OS.
I've been programming for about ten years now, give or take a few again(I know, so vague!). I've experimented with a fairly large number of programming languages, and in the recent years have started researching OS development, and started keeping lots of notes.

I've followed all sorts of tutorials and even just played around with things myself, applying what I know and finding out the results. Learn by doing! That being said, I usually never bother asking anyone else for help, since usually the answer can be found in the error messages, the internet, books, or various other resources.

For the little OS fun I am working on right now, I am using GRUB-legacy and GRUB2 as a bootloader, a few lines of assembly code to get me into my kernel entry function/method/procedure/routine. I use this as a base/template to test out writing kernel code in different languages.

Sorry for all of the background info, here is the real reason I am posting:

I am trying to load an extremely short kernel written in Ada. It is basically an empty for loop.
I used:
Code:
gcc -c main.adb

to only compile the file.
Since, I like to also snoop around, I automatically checked the resulting object file with:
Code:
objdump -d main.o

to view the assembly code, and:
Code:
objdump -t main.o

to view the symbols.

I noticed immediately that the symbol that would indicate my kernels start was prefixed with '_ada_'. Which now finally brings me to my question. Is there an option in gcc or gnat to specifiy not using the prefix or keep it from name mangling?

I've read the various documentations for gcc / gnat / gnatmake / gnatbind and such, and I saw no such thing. Also, if there is no way of changing how the compiler outputs the symbol, would it be plausible to write a script to patch the symbol?

Thanks for any ideas or thoughts you might have on the matter!

-Kris

p.s. I've tried my hardest to find info on this and have had no luck. I've also never had to deal much with making sure things like this 'add up'.


Top
 Profile  
 
 Post subject: Re: Ada and name mangling
PostPosted: Mon Jan 31, 2011 10:21 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7614
Location: Germany
I know next to nothing about ADA or GNAT, but I found pragma Export_Function and pragma Export_Procedure. It looks as if they allow exporting an ADA function / procedure in a way that would allow C code to call them. (Implying no name mangling.)

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: Ada and name mangling
PostPosted: Mon Jan 31, 2011 10:37 am 
Offline

Joined: Mon Jan 31, 2011 9:13 am
Posts: 5
Thanks a bunch! I was looking at those myself, but wasn't sure if those are the proper use. I'll edit my source code and post back on the findings!

Thanks again,
~Kris

edit:
@Solar: Thank you! It turns out using those is the proper convention of exporting the proper symbols to keep ada procedure names from mangling. There is a downside to this though. I looked at all of the documentations of Export, as well as the pragma Linker things, and in order to export my main symbol correctly it has to be done in a very round-about way using a 'header file' to predefine the function, and then follow it with an export.

@everyone: I'm unsure if this interests anyone, but I will see about implementing this properly and will compare/post the print-outs of:
Code:
objdump -d

from a C, as well as Ada version of the code. I'm sure the results will be interesting, considering as the two kernels are now, implementing the same things.

The C version:
Code:
objdump -d main.o

Code:
Disassembly of section .text:

00000000 <main>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   eb fe                   jmp    3 <main+0x3>


The Ada version:
Code:
objdump -d main.o

Code:
Disassembly of section .text:

00000000 <_ada_main>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 08                sub    $0x8,%esp
   6:   eb fe                   jmp    6 <_ada_main+0x6>


Just curious but why is this in the code?
Code:
sub    $0x8,%esp


<_< Sorry I write walls of text.
~Kris


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 244 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group