Author Topic: Multiple source files and Binary output  (Read 20274 times)

Debbie Wiles

  • Guest
Multiple source files and Binary output
« on: December 17, 2004, 08:56:57 AM »
Hi all

I'm currently trying to split a large source file into smaller, more manageable units and want to be able to assemble to object files and link to produce initially a .com file (for testing) then a binary file as part of my OS loader.

I am able to create OMF object files easily, and MS Link 5.63 appears to link successfully, but the resultin file, even though it's the same size as the original created from a single file does not execute correctly. When I added the ..start directive to tell the linker where to start execution, Tlink was not able to find the entry point.

I also tried adding org 100h, which didn't work (I didn't expect it to), and I tried adding resb 100h, as the docs tell me to, but that just added 256 bytes of nothing to the start of the file.

After trying several combinations of everything in the docs and everything I can think of I'm close to giving up or even, God forbid, using a more restrictive tool (not sure yet what will do what I want).

Can anyone tell me how to use multiple files with nasm source code to produce a binary executable? I don't care what linker I have to use, as I have never used one before so they are all the same to me. I am also not overly concerned what object model I will have to use, as, again, that is new to me, and whatever works for this job will work for anything.

I have a 130k source file that produces a 9.4k COM file in nasm (a lot of that is commenting), and with further code to identify newer processors that will be over 200k. By the time I add all the other code for my OS loader, I'll have over 1M of source file, which will be rather unmanageable if I can't split it into modules.

TIA

Debs

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Multiple source files and Binary output
« Reply #1 on: December 17, 2004, 11:04:58 PM »
Hi Debs!

Jeez! You Brits sure know how to party! :)

I'm not much experienced with linkers, especially trying to get a .com file out of 'em (which I take it is what you're doing?). I know that some linkers are fussy about section names (case and underscores, etc.), and possibly "class" as well. Perhaps asking for a .map file and seeing what the linker is using for sections would help figure out what's happening...

Anthony Williams' "Alink" is more or less "designed" for use with Nasm, and might be friendlier(?). Available here on SF. I've also used "val" and David Lindauer's "valx" (from his cc386 package, IIRC). There's been some talk about Pelle's "polink", but I think that may be 32-bit only(?).

But Nasm *should* work with MS link (the 5.63 version - the "incremental" versions, not for 16-bit) or Tlink...

The parameter to "absolute" may be a "critical expression" (able to be evaluated on the first pass), and may not like an external symbol. A "critical expression" doesn't *really* need to be evaluated on the first pass, but on the next-to-last pass. Using the "-O" switch to enable multiple passes helps with forward references in *some* cases - I doubt it'll help with an external symbol (if that's what you've got). You might be stuck with "%define my_new_var _start + N", in order to reuse the memory...

Best,
Frank

Debbie Wiles

  • Guest
Re: Multiple source files and Binary output
« Reply #2 on: December 18, 2004, 01:10:52 AM »
I HATE WINDOWS! It's crashed twice while writing a reply...

Hi Frank :)

Yeah, that was quite some party :) Started with an argument with my partner at the time, followed by a bottle of absinthe... By the time I sobered up I was living with someone else in France (2 months later) and had abandoned all ideas of driving to Egypt :)

Anyway, back to the matter at hand before my system crashes again.

I've tried Alink and still don't get a decent working com file. I'm going about it differently now, a workaround that isn't ideal but does work. I separated out some of the code into a separate file which I have included in the original with an INCLUDE directive, and that works. It will allow me to use multiple source files, just justn't give me the option of creating reusable objects or a library of my code.

As I've got quite a bit of new code to add to the original CPU ID code, after which I've got to add the processor initialisation code and then other stuff for my 2nd stage loader, I need to have multiple files. If I find a way of doing it with object files and a linker, I'll post a tip here for others, as there is nobody about who has been able to say more than we know.

Incidentally, I use -O2 for most assemblies, and occasionally increase that to -O99 to make sure there are no major problems with placement and use of jumps in my code. without -O it won't assemble anyway, as I have no intention of hand coding all the NEAR and FAR etc that would be needed to optimise jumps.

I'm gonna keep it short and sign off there before windoze can crash again...

Stay happy

Debs

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Multiple source files and Binary output
« Reply #3 on: December 18, 2004, 01:39:22 AM »
The workaround for the crashing problem is Linux. I've been "up" 22 days... and the last reboot was to play with a bootsector!

There's been a change in the way the "-O" switch is interpreted. "-O2" and "-O3" are no longer special-cased - you get just the number of passes you specify. So "2" and "3" aren't really enough to do anything - I use "-O999" usually (if I use it at all).

Hope you can find the answer to the linker problem - we *should* be able to do that!

Best,
Frank