Author Topic: strip ELF32 local non-section symbols?  (Read 14195 times)

Offline alexfru

  • Jr. Member
  • *
  • Posts: 17
strip ELF32 local non-section symbols?
« on: August 03, 2014, 07:33:44 AM »
So, I've coded up an initial version of the linker for my Smaller C compiler and it seems to be working well with ELF object files produced by NASM (I'm compiling/translating C code to ASM and then assembling that with NASM).

One of the things I want to be able to do is to use the compiler (and linker and all) in real-mode DOS using what's known as DOS conventional memory (below the 640KB point). But it looks like I might run out of memory when linking large object files simply because they contain lots of local symbol information that is useless for anything but debugging. Also, this info simply takes extra disk space, quite noticeable amount of it, actually.

For example, the main C file of my compiler when self-compiled can have some 5000-6000 local labels/symbols (auto-generated, e.g. L1, L2, ..., L5000) and only several hundred of global ones. Each symbol takes up 16 bytes in Elf32_Sym and some 6 bytes in the string table. So, 5K local symbols amount to ~110KB of useless data, which is more than the size of the actual code and data in the object file. A couple of files like that may fail to link with one another because of lack of memory.

It would seem like the symbol section's sh_info member (it contains the total number of local symbols and they physically precede global, weak and other kinds of symbols) could help me simply ignore all local symbols (don't even load those into RAM), but unfortunately among them can and do appear section symbols such as .text and .data, which do participate in linking and can't be thrown away.

So, the question is, is there a way to make NASM not store local symbols (other than those needed for linking (i.e. section symbols such as .text, .data, etc)) in the ELF files it produces? Am I missing an option or can such an option be easily added to NASM?

I might end up having a better workaround in my linker (right now I load all symbols from each ELF, but then downsize them). I could also make a small strip tool, but that would be an extra step in compiling.

Anyway, it would be nice to be able to get rid of the local non-section symbols in the first place.
« Last Edit: August 04, 2014, 01:27:16 AM by alexfru »

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: strip ELF32 local non-section symbols?
« Reply #1 on: August 03, 2014, 08:11:24 AM »
Hi!

I think this is the right solution:
I could also make a small strip tool

BYe.
Encryptor256's Investigation \ Research Department.

Offline gammac

  • Jr. Member
  • *
  • Posts: 71
  • Country: 00
Re: strip ELF32 local non-section symbols?
« Reply #2 on: August 03, 2014, 09:34:27 AM »
So, the question is, is there a way to make NASM not store local symbols (other than those needed for linking (i.e. section symbols such as .text, .data, etc)) in the ELF files it produces? Am I missing an option or can such an option be easily added to NASM?

Good question! I do not include windows.inc, because I hate those ~300k sized object files. Therefore I include all needed stuff (structure defs etc.) manually. :(
Please comment your code! It helps to help you.