Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
On 12.08.2012 15:57, Rainer Stratmann wrote: Am Sunday 12 August 2012 15:46:00 schrieb Sven Barth: I know there is a smiley, but: Only because Jonas sees no gain in implementing something in the compiler that would help you in your specific case does not mean that Jonas doesn't add anything that causes not much work. That my suggestions would help only me in my specific case is your subjective opinion. It might be my suggestive opinion, but it's not only mine ;) Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Am Sunday 12 August 2012 15:46:00 schrieb Sven Barth: > I know there is a smiley, but: Only because Jonas sees no gain in > implementing something in the compiler that would help you in your > specific case does not mean that Jonas doesn't add anything that causes > not much work. That my suggestions would help only me in my specific case is your subjective opinion. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
On 12.08.2012 15:37, Rainer Stratmann wrote: Am Sunday 12 August 2012 15:25:17 schrieb Mark Morgan Lloyd: Hey, Jonas, when are you introducing the optimisation that a call at the end of a procedure can be replaced by a jmp? :-) Jonas only introduces something if it causes not much work :-) I know there is a smiley, but: Only because Jonas sees no gain in implementing something in the compiler that would help you in your specific case does not mean that Jonas doesn't add anything that causes not much work. Besides his continous high quality work at the compiler one of his biggest works so to see was to enable FPC to generate ByteCode which can be executed by the JVM or even converted to Dalvik ByteCode. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Am Sunday 12 August 2012 15:29:44 schrieb Jonas Maebe: > Florian already implemented that quite a while ago :) I suggest to drop the > topic though, because Rainer does not appear to be open to taking another > approach It depends on the approach. If you have a better solution would you take another approach? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Am Sunday 12 August 2012 15:25:17 schrieb Mark Morgan Lloyd: > Hey, Jonas, when are you introducing the optimisation that a call at the > end of a procedure can be replaced by a jmp? :-) Jonas only introduces something if it causes not much work :-) Jmp will be opcode $E9. http://css.csail.mit.edu/6.858/2012/readings/i386/JMP.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
On 12 Aug 2012, at 15:25, Mark Morgan Lloyd wrote: > Rainer Stratmann wrote: > >> For the above mentioned purpose it works perfect since some days. >> I got all caller adresses and even more I got all text snippets (pchar to >> the snippet!). If you know something about assembler language then it is not >> a huge effort to get this information from the compiled code. > > Hey, Jonas, when are you introducing the optimisation that a call at the end > of a procedure can be replaced by a jmp? :-) Florian already implemented that quite a while ago :) I suggest to drop the topic though, because Rainer does not appear to be open to taking another approach (and he has said he does not enable optimizations). Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Rainer Stratmann wrote: For the above mentioned purpose it works perfect since some days. I got all caller adresses and even more I got all text snippets (pchar to the snippet!). If you know something about assembler language then it is not a huge effort to get this information from the compiled code. Hey, Jonas, when are you introducing the optimisation that a call at the end of a procedure can be replaced by a jmp? :-) -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Am Sunday 12 August 2012 09:49:36 schrieb Jorge Aldo G. de F. Junior: > Why do you need to "Get all caller addresses of a given function procedure" > ? If you read the thread you will now. Because I need an easy handling multi language interface. > This can be solved with static code analysis - as long as there is no > procedural variables involved How can it be done easily? I think we discuss it already in the mentioned thread. > - but its weird to have such a > necessity... For the above mentioned purpose it works perfect since some days. I got all caller adresses and even more I got all text snippets (pchar to the snippet!). If you know something about assembler language then it is not a huge effort to get this information from the compiled code. > Sounds like the project started with the wrong > assumptions... The project has already started 20 years ago... So there can not be very much wrong if it is still working. > Thats my two cents... > > 2012/8/11 Rainer Stratmann : > > Am Saturday 11 August 2012 19:18:39 schrieb Jorge Aldo G. de F. Junior: > >> Sorry for posting without bringing a solution, but i am curious, why > >> do you need this ? > >> > >> Doesnt sound like good programming practice... > > > > See Thread: > > "Get all caller adresses of a given function/procedure before executing" > > We did not find a solution there I feel comfortable with so I decide to > > check the code directly. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Why do you need to "Get all caller addresses of a given function procedure" ? This can be solved with static code analysis - as long as there is no procedural variables involved - but its weird to have such a necessity... Sounds like the project started with the wrong assumptions... Thats my two cents... 2012/8/11 Rainer Stratmann : > Am Saturday 11 August 2012 19:18:39 schrieb Jorge Aldo G. de F. Junior: >> Sorry for posting without bringing a solution, but i am curious, why >> do you need this ? >> >> Doesnt sound like good programming practice... > > See Thread: > "Get all caller adresses of a given function/procedure before executing" > We did not find a solution there I feel comfortable with so I decide to check > the code directly. > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Am Saturday 11 August 2012 19:18:39 schrieb Jorge Aldo G. de F. Junior: > Sorry for posting without bringing a solution, but i am curious, why > do you need this ? > > Doesnt sound like good programming practice... See Thread: "Get all caller adresses of a given function/procedure before executing" We did not find a solution there I feel comfortable with so I decide to check the code directly. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Am Saturday 11 August 2012 17:34:44 schrieb Marco van de Voort: > In our previous episode, Rainer Stratmann said: > > But not the 80x86 CPU. It is still the same opcode for a call ($E8). > > Maybe not the call, but changing or adding address encoding is quite > realistic. > > I assume you tested your code for PIC cases (which are quite common on > *nix?) The call ($E8) itself operates with a relative adress as I found out and write already and documented in the piece of code shown in a previous mail. > http://en.wikipedia.org/wiki/Position-independent_code > > FPC supports PIC > > And of course finding a perfect starting point so that you don't find false > positives when you find $E8 inside the address (change 1 in 256 obviously) If there is a $E8 then also the calculated absolute adress from the following 4 bytes must point to the searching text translate function. So errors are likely rare. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Sorry for posting without bringing a solution, but i am curious, why do you need this ? Doesnt sound like good programming practice... 2012/8/11 Marco van de Voort : > In our previous episode, Rainer Stratmann said: >> > > There are not many different ways for a call. >> > > >> > > http://css.csail.mit.edu/6.858/2011/readings/i386/CALL.htm >> > >> > Yes, so the amount of effort may increase drastically. New CPU may bring >> > new ways too. >> >> But not the 80x86 CPU. It is still the same opcode for a call ($E8). > > Maybe not the call, but changing or adding address encoding is quite > realistic. > > I assume you tested your code for PIC cases (which are quite common on > *nix?) > > http://en.wikipedia.org/wiki/Position-independent_code > > FPC supports PIC > > And of course finding a perfect starting point so that you don't find false > positives when you find $E8 inside the address (change 1 in 256 obviously) > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
In our previous episode, Rainer Stratmann said: > > > There are not many different ways for a call. > > > > > > http://css.csail.mit.edu/6.858/2011/readings/i386/CALL.htm > > > > Yes, so the amount of effort may increase drastically. New CPU may bring > > new ways too. > > But not the 80x86 CPU. It is still the same opcode for a call ($E8). Maybe not the call, but changing or adding address encoding is quite realistic. I assume you tested your code for PIC cases (which are quite common on *nix?) http://en.wikipedia.org/wiki/Position-independent_code FPC supports PIC And of course finding a perfect starting point so that you don't find false positives when you find $E8 inside the address (change 1 in 256 obviously) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Am Saturday 11 August 2012 14:46:53 schrieb Martin: > On 11/08/2012 13:32, Rainer Stratmann wrote: > > Am Saturday 11 August 2012 14:15:11 schrieb Martin: > >> If that changes, then your code fails. > > > > I can easily adopt the code then. > > There are not many different ways for a call. > > > > http://css.csail.mit.edu/6.858/2011/readings/i386/CALL.htm > > Yes, so the amount of effort may increase drastically. New CPU may bring > new ways too. But not the 80x86 CPU. It is still the same opcode for a call ($E8). By now since 36 Years. http://en.wikipedia.org/wiki/Intel_8086 What do you mean with drastically? At the moment there is no unsolved whish to this topic. > And with each added way, the already existing risk of false positives > (the byte sequence can occur as subset of another statement, and then it > isn't a call at all) does increase. Note that it is only added to the table if also the adress is equal. I am aware of 2 byte opcodes, but I see no obstacle in this. If there are very unlikely more results then expected it will not be a problem. The search through the whole program is mainly for me if adding new text snippets or a complete new language. I will be able to solve most requirements, because I am an experienced programmer. On assembler language, too. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
On 11/08/2012 13:32, Rainer Stratmann wrote: Am Saturday 11 August 2012 14:15:11 schrieb Martin: If that changes, then your code fails. I can easily adopt the code then. There are not many different ways for a call. http://css.csail.mit.edu/6.858/2011/readings/i386/CALL.htm Yes, so the amount of effort may increase drastically. New CPU may bring new ways too. And with each added way, the already existing risk of false positives (the byte sequence can occur as subset of another statement, and then it isn't a call at all) does increase. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Am Saturday 11 August 2012 14:15:11 schrieb Martin: > > I do not read all discussions. > > Which exactly headline has it? > > Does it affect the possibility to get the information I want? > > Re: [fpc-devel] Re: Class field reordering The searched procedure/function is not a class procedure or function. > No it does not help on your topic. It is about assuming that behaviour > based on the current compiler implementation will never change Where do I say that? > You assume the compiler will always use the same asm-opcode for the > call. No. > Or at least you assume that if it changes, you can change it too. Yes, very quickly! > But future compilers (or maybe even the current, depending on > optimization ?) may use different asm opcodes within the same exe, to > make the call, and they may mix different ways of encoding the address. I switched off optimizations. I think I am able to handle more than one way to find a call to a function/procedure. But at this time I found only one way in my program so far. So there was no need to search for other ways... > If that changes, then your code fails. I can easily adopt the code then. There are not many different ways for a call. http://css.csail.mit.edu/6.858/2011/readings/i386/CALL.htm ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
On 11/08/2012 13:00, Rainer Stratmann wrote: Am Saturday 11 August 2012 13:52:58 schrieb Martin: On 11/08/2012 12:48, Rainer Stratmann wrote: Am Saturday 11 August 2012 13:40:44 schrieb Rainer Stratmann: procedure i_realy_know_what_i_am_doing( p_opcode : pbyte ; count : longint ; proc_adr : pointer ); Better: i_really_know_what_i_am_doing You have read the long discussion thread, about what happens to the cracker classes in the next fpc release, when the class-field-order optimization is introduced? I do not read all discussions. Which exactly headline has it? Does it affect the possibility to get the information I want? Re: [fpc-devel] Re: Class field reordering No it does not help on your topic. It is about assuming that behaviour based on the current compiler implementation will never change You assume the compiler will always use the same asm-opcode for the call. Or at least you assume that if it changes, you can change it too. But future compilers (or maybe even the current, depending on optimization ?) may use different asm opcodes within the same exe, to make the call, and they may mix different ways of encoding the address. If that changes, then your code fails. - So if you do know what you do, hen you do know you are taking a risk ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Am Saturday 11 August 2012 13:52:58 schrieb Martin: > On 11/08/2012 12:48, Rainer Stratmann wrote: > > Am Saturday 11 August 2012 13:40:44 schrieb Rainer Stratmann: > >> procedure i_realy_know_what_i_am_doing( p_opcode : pbyte ; count : > >> longint ; proc_adr : pointer ); > > > > Better: i_really_know_what_i_am_doing > > You have read the long discussion thread, about what happens to the > cracker classes in the next fpc release, when the class-field-order > optimization is introduced? I do not read all discussions. Which exactly headline has it? Does it affect the possibility to get the information I want? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
On 11/08/2012 12:48, Rainer Stratmann wrote: Am Saturday 11 August 2012 13:40:44 schrieb Rainer Stratmann: procedure i_realy_know_what_i_am_doing( p_opcode : pbyte ; count : longint ; proc_adr : pointer ); Better: i_really_know_what_i_am_doing You have read the long discussion thread, about what happens to the cracker classes in the next fpc release, when the class-field-order optimization is introduced? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get all caller adresses of a given function/procedure before executing
Am Saturday 11 August 2012 13:40:44 schrieb Rainer Stratmann: > procedure i_realy_know_what_i_am_doing( p_opcode : pbyte ; count : longint > ; proc_adr : pointer ); Better: i_really_know_what_i_am_doing ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Get all caller adresses of a given function/procedure before executing
The code below finds all caller adresses in a program to a known procedure/function adress. With this I can get all caller adresses to the translate function. Moreover - with another piece of code (not shown here) I got also the text snippets itself, because they are loaded immediately before executing the translate function with MOV textsnippetadr , EAX. procedure i_realy_know_what_i_am_doing( p_opcode : pbyte ; count : longint ; proc_adr : pointer ); const call_opcode = $e8; caller_adr_pc_offset = 5; var p_reladress : pdword; // call works with a relative adress after the opcode x , caller_adress , jmp_adr_abs : dword; begin for x := 1 to count do begin if p_opcode^ = call_opcode then begin p_reladress := pdword( p_opcode + 1 ); // after opcode = relative adress to procedure/function to call caller_adress := dword( p_opcode + caller_adr_pc_offset ); jmp_adr_abs := caller_adress + p_reladress^; // absolute adress = programcounter + 5 + relative adress if jmp_adr_abs = dword( proc_adr ) then add_caller_adress_to_table( caller_adress ); // if call proc_adr then found! end; inc( p_opcode ); end; end; ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal