flat assembler
Message board for the users of flat assembler.

Index > Windows > Removing used coff objects

Author
Thread Post new topic Reply to topic
zubi



Joined: 27 Apr 2006
Posts: 25
Location: Turkey
zubi 02 Jun 2006, 17:39
Working with MS Coff format static libraries, I need to do the following:

In order to prevent unused code to appear in final executables, I write each function in a separate file, resulting bunch of object files in the library. I also have to add an additional file to the library, let's call it the Main object, which has a data section where addresses of the functions with some extra information from other modules are stored (This is used to enable a call stack trace from the executable). Executables that use the library are required to use the Main object for initialization and to ensure that functions table is in the exe. Now, the problem is that when there is an executable that uses, say, only 1 of the functions in the library, the linker still puts all of the objects into the exe, just because those functions in the object files are referenced from the Main object. How can I prevent that?

One way of doing it might be making a copy of the library, removing the unused objects from it and linking the executable with options to force the linker not to generate errors due to undefined symbols. Well, I think this is a very ugly solution which may result in bugs that are hard to trace since errors that would have been generated for other undefined symbols are suppressed as well. Besides, at the compile time of an executable, the redundant objects may not be known in advance, as some of them may contain 'helper' functions which are not part of the library's 'interface' but used internally by the functions the program calls. So this actually is not a solution.

In short, I wish the symbol information to disappear from the Main object, while having the function address table be present. How can I achieve that, or maybe I should ask if it is at all possible? For that matter, is it possible to have those addresses hardcoded, pointing to a fixed location even if that location doesn't exist?

PS. Regarding the issue, I have seen a thread in the forum about COMDAT sections, where Mr. Grysztar said he might add official support for them in a future version. I was wondering about the future of COMDATs in Fasm.
Post 02 Jun 2006, 17:39
View user's profile Send private message MSN Messenger Reply with quote
saigon



Joined: 29 May 2006
Posts: 62
saigon 02 Jun 2006, 21:05
One solution I used in my interpreter was to scan the user source code to see which functions are used, then it creates an object file which has the reference to only the found functions, after that the file will be passed to the linker and you got your static lib.

If I remember correctly, the project was done in a high level language, so it might be hard to do it in FASM.

I assume you are creating a programming language, right?
If it's so, the best option is to scan the code through to find only the used functions.

I hope this helps, but I don't have any source code to show you an example.
Post 02 Jun 2006, 21:05
View user's profile Send private message Reply with quote
Quantum



Joined: 24 Jun 2005
Posts: 122
Quantum 03 Jun 2006, 16:02
2 zubi:
Quote:

In short, I wish the symbol information to disappear from the Main object, while having the function address table be present.

Those references point to external resources (because actual fucntions got stored in separate objects). That's why they call 'em externals. Externals are just symbols the linker whould try to resolve while linking together all thous modules. That's why your references are all symbolic - no fixed addresses could be stored until linkage stage. But you can get real addresses at runtime.

Your call stack tracing code should be rewritten to make this work without ugly hacks.
Post 03 Jun 2006, 16:02
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.