This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Define data at fixed location in link output


How can I reserve and define a block of data at a fixed location in the
linker output?

I want to be able to run a self-check for an executable (a shared library,
BTW) when
it is loaded.
So my idea is to let the linker allocate something like a checksum at the
very end
of the binary which it produces.  The self-check would include all bytes of
the
module body, i.e. all bytes up to the last byte just before this fixed data
block.
I would have to link twice, once with dummy checksum data, then calculate
the
checksum, and compile again with real checksum data for the data block. The
module body (meaning everything except the checksum itself) must of course
remain unchanged between the two compiles.
Is there a way how I can make the compiler / linker do this
a) for a shared library
b) for a stand-alone executable?
(just in case there would be differences between the two)

As a quick test, I tried to add a statement
   static const unsigned char chksum[] =
{ 's','o','m','e','t','h','i','n','g' };
to the end of the last module which appears in the list of modules to link
in
the makefile.
However, the string appeared somewhere far before the end.

Best regards, Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]