RavenBlog |
|
Comments on Wednesday 24 March 2004: |
Ignore this post if you're not a programmer. In the openssl library, there is a function in rsa_lib.c that looks like this: int RSA_size(const RSA *r)In my code, there is a function call that looks like this: int size=RSA_size(rsa);When the program is compiled and run, the resulting executable is 220K. Now, if I replace that single line of my code with this: int size=(BN_num_bytes(rsa->n));Then when the program is compiled and run, the resulting executable is 84K. I consider it unlikely that an extra function call going onto the stack and off again is 136K of compiled code. What's happening here? Neither call has been replaced by a macro, but for some reason the RSA_size function causes some twenty-odd extra RSA functions to end up in the executable (this gleaned from the .map file). Also of note, both of these functions cause some extra code to end up in the executable even if the function from which they are called is discarded from the executable due to not being called itself (and the "/opt:ref" linker option). This differs from BF_cfb64_encrypt (a function in the same library), which is discarded if the function that calls it is discarded, as it should be. Any programmery people got an explanation for this odd behaviour? Visual C++ 5 being the compiler, and openssl 0.9.7d using no assembly language being the statically compiled library. [09:11] |
Digi |
I've no experience with that library, or that compiler, but is it possible that the use of that function is causing VC++ 5 to link a whole load of other stuff, without telling you about it in any very obvious way? "Ooh, he wants that function. Then he wants all these libraries too! Probably, anyway. I won't ask, wouldn't want to bother him". Any relevant #ifdef's you're not mentioning? Seems pretty far fetched, but like you say, it's not the code. Unless, maybe the code you've got here isn't quite the code you have in the program, because you just typed it, instead of copy-pasting it. I expect you spent about two hours on this, before Bloging, so again, pretty far fetched that you'd do something like that. What happens when you cut out all the other code from the program, and just test this bit? Same disparity in size? How about a diffrent version of VC++? Be intresting to know what caused it, when you find out. |
RavenBlack |
Can't really test just that bit without it being a lot of effort. I tried changing the compiler and linker to those of VC++6 and doing a command-line compile, which had the same result. I've changed library from openssl to libtomcrypt, which is *less* bad, but still has things getting linked in that shouldn't be. In this instance, calling a function with a const structure full of function pointers from the same library (within a function that's never called) causes the effect. Calling the function without the struct, or using the struct without the function (both within my never-called function), does not. |
AttackOfTheSpam |
Oooh.... numbery things... |