Discussion:
DynASM with multiple objects in the same binary
Luke Gorrie
2014-06-22 11:18:29 UTC
Permalink
Howdy,

I'm looking for a neat way to combine multiple independent DynASM objects
(.o) in the same executable.

Here is how my DynASM code looks now:
https://github.com/lukego/snabbswitch/blob/tlb/src/core/tlb.dasc

I'd like to be able to add more similar files, but I have two problems:

First, dynasm_x86.h is defining a whole bunch of functions (dynasm_init,
etc) so I will get a linker error if I try to include this from another
file too.

Second, 90% of tlb_make() would ideally be a shared library function that
all DynASM-based files can call to do the common tasks like init, assembly,
copying into an executable page of memory, etc.

Anybody happen to have already solved this or have some tips?

Cheers,
-Luke
Cosmin Apreutesei
2014-06-22 19:21:26 UTC
Permalink
Post by Luke Gorrie
First, dynasm_x86.h is defining a whole bunch of functions (dynasm_init,
etc) so I will get a linker error if I try to include this from another file
too.
Would making these functions private work? The following should keep
them from going into the symbol table:

#define DASM_FDEF __attribute__((visibility("hidden")))
Post by Luke Gorrie
Second, 90% of tlb_make() would ideally be a shared library function that
all DynASM-based files can call to do the common tasks like init, assembly,
copying into an executable page of memory, etc.
How about wrapping these up in private functions too, which you can
put in a common header file:

DASM_FDEF dasm_State* dasm_new(const char* actionlist, int
maxsection, int maxglobals);
DASM_FDEF dasm_build_and_run(dasm_State*);

and call them up like this:

Dst = dasm_new(actions, DASM_MAXSECTION, myglobals__MAX);

| ... asm stuff generating dasm_put(Dst, ...) ...

dasm_build_and_run(Dst);


Hope I'm not talking out of my armpit, my C is rusty but my DynASM is fresh :)
Loading...