How to calculate a value "on the fly" for use with gcc compiler option?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to calculate a value "on the fly" for use with gcc compiler option?

Jörg Förstner
How to calculate a value "on the fly" for use with gcc compiler option?

Hi,

I've a problem converting one important feature of our old make-build-process to the new cmake-build-process.

The problem:
In our old build process, each object file was binary different from one build run to another.
This problem was caused by gcc using randomly generated symbol names.

The solution with make:
We use gcc's option "-frandom-seed=<value>", which uses a given value as a starting point for it's random number generator.

As every file shall have a unique random seed, we calculate the MD5 checksum of each source file "on the fly".
This checksum is then used as a value for the option "-frandom-seed".

Here's how the current compile rule in the old Makefile looks like:
  $(CC) -frandom-seed=$(shell md5sum $< | sed 's/\(.*\) .*/\1/') $(CCFLAGS) -c $< -o $@

I tried to do this in cmake, but I only have this command:
ADD_DEFINITIONS(
  "-frandom-seed=$(shell md5sum $< | sed 's/\(.*\) .*/\1/')"
)

But how can I determine the current filename and replace "$<" by the filename?
How can this be made using cmake?

Best Regards,
Joerg


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate a value "on the fly" for use with gcc compiler option?

Tyler Roscoe
On Fri, Jul 17, 2009 at 08:32:38PM +0200, Jörg Förstner wrote:
> We use gcc's option "-frandom-seed=<value>", which uses a given value as a starting point for it's random number generator.
> As every file shall have a unique random seed, we calculate the MD5 checksum of each source file "on the fly".
> This checksum is then used as a value for the option "-frandom-seed".

This sounds pretty crazy. Not really relevant to your question, but why
do you need to do all this? Are you trying obfuscate your object files
to prevent decompilation or something?

> Here's how the current compile rule in the old Makefile looks like:
>   $(CC) -frandom-seed=$(shell md5sum $< | sed 's/\(.*\) .*/\1/') $(CCFLAGS) -c $< -o $@
>
> I tried to do this in cmake, but I only have this command:
> ADD_DEFINITIONS(
>   "-frandom-seed=$(shell md5sum $< | sed 's/\(.*\) .*/\1/')"
> )
>
> But how can I determine the current filename and replace "$<" by the filename?
> How can this be made using cmake?

I would move all the md5sum and sed complexity into a script and then
just iterate over your source files, sending each to the script and
getting the appropriate output. Something like this:

foreach (_file ${src_files})
    execute_process (my_md5sum_sed_script ${_file}
        OUTPUT_VARIABLE _seed)
    add_definitions (...)
endforeach ()


hth,
tyler
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to calculate a value "on the fly" for use with gcc compiler option?

Jörg Förstner
In reply to this post by Jörg Förstner
Hi Tyler,

> [...] why do you need to do all this?

I need this to binary compare the built libraries of two releases.
If a library of the current release build is binary equal to the library of the previous release build, I can be sure that there had been no change at all.

Unfortunately without the option "-frandom-seed", the object files and libraries of subsequent builds are binary different, even when no source file had been changed.

Cheers,
Joerg


> -----Ursprüngliche Nachricht-----
> Von: Tyler Roscoe [mailto:[hidden email]]
> Gesendet: Freitag, 17. Juli 2009 21:35
> An: Jörg Förstner
> Cc: [hidden email]
> Betreff: Re: [CMake] How to calculate a value "on the fly"
> for use with gcc compiler option?
>
> On Fri, Jul 17, 2009 at 08:32:38PM +0200, Jörg Förstner wrote:
> > We use gcc's option "-frandom-seed=<value>", which uses a
> given value as a starting point for it's random number generator.
> > As every file shall have a unique random seed, we calculate
> the MD5 checksum of each source file "on the fly".
> > This checksum is then used as a value for the option
> "-frandom-seed".
>
> This sounds pretty crazy. Not really relevant to your
> question, but why
> do you need to do all this? Are you trying obfuscate your object files
> to prevent decompilation or something?
>
> > Here's how the current compile rule in the old Makefile looks like:
> >   $(CC) -frandom-seed=$(shell md5sum $< | sed 's/\(.*\)
> .*/\1/') $(CCFLAGS) -c $< -o $@
> >
> > I tried to do this in cmake, but I only have this command:
> > ADD_DEFINITIONS(
> >   "-frandom-seed=$(shell md5sum $< | sed 's/\(.*\) .*/\1/')"
> > )
> >
> > But how can I determine the current filename and replace
> "$<" by the filename?
> > How can this be made using cmake?
>
> I would move all the md5sum and sed complexity into a script and then
> just iterate over your source files, sending each to the script and
> getting the appropriate output. Something like this:
>
> foreach (_file ${src_files})
>     execute_process (my_md5sum_sed_script ${_file}
>         OUTPUT_VARIABLE _seed)
>     add_definitions (...)
> endforeach ()
>
>
> hth,
> tyler
>
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake