OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 5:11 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Linking Non-Executable Intermediate Files Together
PostPosted: Thu May 07, 2015 7:44 pm 
Offline

Joined: Wed May 06, 2015 12:13 pm
Posts: 3
Right now I've got a minimal OS up and running, so before I move on I decided to work on my build environment (cleanliness is godliness).

Right now I'm almost satisified with how things build, here's a quick overview

./build.sh
- Passes control to /stdcpp/build.sh, which builds my "standard" library (it's not really standard if its mine :P)
-- If an error occours, build stops and prints out errors
- Passes control to /kernel/build.sh, which builds my kernel, linking to all required .o files

.asm are compiled to .ao, .c to .o, and .cpp to .opp. If globally usable, files are placed into a ./out/ directory.

The problem is that I've got a library file that needs both a .cpp and .asm. I can get it to work by linking the kernel to both the .ao and .opp, but I'd rather combine the .ao and .opp so that I can have full functionality while only linking to one file. (This would maintain the globally usability)

The concept is to compile the parts in the source structure, link the resulting parts, and send the single, usable output to ./out/

I gave it a try by running the following command
Code:
i686-elf-ld stdo.ao stdo.opp -o ${BUILD}/out/stdo.lo -ffreestanding -O2 -nostdlib -shared

std.ao and std.opp are results of asm and cpp portions that cannot stand alone. std.lo is the output in which they are linked together, so it can stand alone.

Unfortunately doing this builds fine, but it breaks the OS, so I'd imagine that I'm missing something low-level.

TLDR I've got two static library files resulting from nasm and gcc that need to be linked together to be used. Since they aren't executable I cannot (I assume) link using
Code:
gcc -T linker.ld -o file.elf -ffreestanding -O2 -nostdlib file.o file1.o -lgcc
that I picked up from the barebones tutorial.

How do I go about linking them together so I can then link to the single file everywhere it is used?


Top
 Profile  
 
 Post subject: Re: Linking Non-Executable Intermediate Files Together
PostPosted: Thu May 07, 2015 7:48 pm 
Offline
Member
Member

Joined: Thu Mar 25, 2010 11:26 pm
Posts: 1801
Location: Melbourne, Australia
Can't you use i686-elf-ar to link arbitrary object files together into a library ?

_________________
If a trainstation is where trains stop, what is a workstation ?


Top
 Profile  
 
 Post subject: Re: Linking Non-Executable Intermediate Files Together
PostPosted: Thu May 07, 2015 8:03 pm 
Offline

Joined: Wed May 06, 2015 12:13 pm
Posts: 3
I'm not very familiar with the gcc toolchain, thanks for the pointer!

For reference, the final command was
Code:
i686-elf-ar -q archive.lo input.ao input2.opp

Where archive.lo is the resulting "linked" file, and input.ao / input2.opp are the input independent files.


Top
 Profile  
 
 Post subject: Re: Linking Non-Executable Intermediate Files Together
PostPosted: Fri May 08, 2015 5:23 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1070
Location: Germany
Using ar is the right way to produce a static library, but I just want to add something to the original question on how to combine two object files into one: I think you'd want the -r option for ld, and probably -shared is the reason why it didn't work any more (unless you really support shared libraries in your "minimal" OS).

_________________
Developer of tyndur - community OS of Lowlevel (German)


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 63 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