public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Define data at fixed location in link output
@ 2002-03-11  3:35 Martin Witzel
  0 siblings, 0 replies; only message in thread
From: Martin Witzel @ 2002-03-11  3:35 UTC (permalink / raw)
  To: help-gcc

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-03-11 11:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-11  3:35 Define data at fixed location in link output Martin Witzel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).