HELP with linker script!!!
Sergei Organov
osv@topconrd.ru
Mon Apr 4 11:59:00 GMT 2005
Nick Clifton <nickc@redhat.com> writes:
[...]
> You put the symbols in the linker script, like this:
>
> .cached_bss : {
> __start_of_cacheable_bss = ABSOLUTE (.);
> *(.cached_bss)
> __end_of_cacheable_bss = ABSOLUTE (.);
> } > cachableRAM;
>
> Then you can reference them from your C code, like this:
>
> extern int __start_of_cacheable_bss;
> extern int __end_of_cacheable_bss;
>
> memset (& __start_of_cacheable_bss, 0,
> & __end_of_cacheable_bss - & __start_of_cacheable_bss);
>
> Note - read the section entitled "Source Code Reference" in the linker
> documentation for an explanation of why these variables are being
> accessed via the & operator.
Well, please correct me if I'm wrong, but I see two problems here.
1. The variables should better be of type 'char', otherwise pointer
arithmetic in the third parameter to memcpy() will bring wrong
result.
2. Even then it could be wrong. For example, on PowerPC using SYSV ABI
compiler is free to assume the two variables are in the small data
section and may generate incorrect assembly and relocation types for
the addresses, I'm afraid. Because of this I'd use slightly different
approach:
extern char __start_of_cacheable_bss[];
extern char __end_of_cacheable_bss[];
memset (__start_of_cacheable_bss, 0,
__end_of_cacheable_bss - __start_of_cacheable_bss);
The purpose of using arrays of unknown size is to prevent compiler
from assuming anything about the location of the variables.
--
Sergei.
More information about the Binutils
mailing list