Author Topic: Using symbols from another file  (Read 6906 times)

Offline markr

  • Jr. Member
  • *
  • Posts: 2
Using symbols from another file
« on: August 03, 2014, 01:56:33 PM »
Is there any way to use symbols from another file without statically linking them to produce a single binary?

The particular scenario I'm trying to solve is where you have a bootloader and a kernel, with the bootloader being a flat binary. It would be useful for the bootloader to be able to access kernel data structures after loading the kernel to initialize it. They can't be statically linked, as they have different base addresses, but the bootloader still needs access to kernel symbols.

For data only, you could have a shared assembly file with the kernel's BSS at a fixed address, but this doesn't handle changes in kernel size well.

If I make the kernel flat binary, NASM's [map] directive outputs the appropriate information, but not in a format that can easily be fed into the bootloader.

If I make the kernel ELF, the information is in the kernel file itself, but I don't know how to make use of that information when assembling the bootloader.

Offline Rob Neff

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 429
  • Country: us
Re: Using symbols from another file
« Reply #1 on: August 03, 2014, 02:48:33 PM »
If I make the kernel flat binary, NASM's [map] directive outputs the appropriate information, but not in a format that can easily be fed into the bootloader.

To me it sounds like you've answered your own question here.  I would think writing a small script that parses the needed information in that map file into the appropriate format would satisfy your requirements.

Offline markr

  • Jr. Member
  • *
  • Posts: 2
Re: Using symbols from another file
« Reply #2 on: August 03, 2014, 07:28:07 PM »
To me it sounds like you've answered your own question here.  I would think writing a small script that parses the needed information in that map file into the appropriate format would satisfy your requirements.
Yes, that would work. I had asked in case there was a neater solution; it seems ironic to be parsing a text file, when there are dedicated formats like ELF that are designed to contain (re)location information.

Another solution would be to have the bootloader parse an ELF kernel. In many ways, that would be the "right" thing to do, but it seems overkill. I think for now I will give my kernel a small custom header as a lightweight compromise. Using a header (ELF or custom) has the advantage that the bootloader does not need to be reassembled when the kernel changes; when I originally posted the question, I hadn't fully realised the advantage of that.