| Strange Object Loading in GCC or anything other then GCC >;-) |
[24 Jul 2002|09:24am] |
Does anyone know how to get gcc to compile a function totally inline and relative to itself. For example:
int isBob( char *txt) { static char *bob = "Bob"; char *tmp = bob;
for (;;) { if (*tmp != *txt) return -1; if (!*tmp && !*txt) return 0; tmp++; txt++; } }
By default here, gcc will generate a .S and put the string "Bob" into the .data section, and put the function in the .code section. (As this makes sense for 99.9999% of the time :D)
The function requires no external symbols. How, do I put the function into a straight binary function. So it could be loaded and called directly.
IE: Take a dos example,
mov ax, 4C01h int 21h
If we converted that to machine code, we would get something like (where that 0x?? is the opcode for mov :), and probably some push's and pop's that go around the c function call. char quit_fn[] = { 0x??, 0x01, 0x4C, 0xCD, 0x21 };
The application is a server program, can transfer small self-contained function fragments to a client program, and have it call the "binary function block" directly. ie: (*quit_fn)(); or something like that :)
So, the question is, how do I do this? :)
http://startpage.zefga.net/LJ/gcc_as_symb.bz2 in case some code is needed to help clarify what I'm trying to do. :)
Thanks for any help -eurijk! >;-)
|
|