using void variables as linker-script symbol refs

David Howells dhowells@redhat.com
Fri Oct 10 20:25:00 GMT 2003


I've got a situation in which I'd like to use something like the following to
refer to constants defined in the linker script:

	extern const void _stext, _etext;

	#define __kernel_size ((unsigned long)&_etext - (unsigned long)&_stext)

Rather than:

	extern int _stext, _etext;

Or:

	extern int _stext[], _etext[];

Or:

	struct __not_really_a_struct;
	struct __not_really_a_struct _stext, _etext;

This has a couple of advantages:

 (1) You can't accidentally read/set such variables directly.

 (2) GCC doesn't assume they can be referenced by register-relative means, if
     the CPU has a special data pointer (such as a small-data pointer).

Any thoughts? Or is this just a straight forward shooting offence?

David



More information about the Gcc mailing list