|
|
 | | From: | Not Really Me | | Subject: | scatter loading required? | | Date: | Wed, 19 Jan 2005 09:20:24 -0700 |
|
|
 | Using CW for ARM developer suite V1.2.
The piece of code below works correctly if there is no split memory specified in the link command. Linked at 0x05000000 there are no problems.
If the code is linked at RO Base 0x05000000 and RW Base 0x02000000, the load is not initialized correctly. The wrong data gets copied to the RW base and a data error occurs on the 4th printf. Is this a bug, or does it need to have scatter loading specified?
I have tried a scatter load file, but I don't think it was correct. If it needs a scatter file please show an example that should work.
Thanks, Scott
/* * File: main.c * Purpose: sample program * */ #include #include
#define SIZE 4
const char *sprintffmt[SIZE] = /* sprintf format strings */ { "%s\n", /* 0 */ "%s%s\n", /* 1 */ "%s%s%s\n", /* 2 */ "%s%s\n"}; /* 3 */
#define INDEX 0 /* Output buffer filename */ char buff[]; /* output stream buffer */
int main() { // sprintffmt[INDEX] = "%s";
strcpy(buff, "This is a test\n");
printf("\nAddr of sprintffmt = %x \n", sprintffmt ); // 0x02000000 printf("\nAddr of sprintffmt = %x \n", &sprintffmt[INDEX] ); // 0x02000000 printf("\nAddr of sprintffmt = %x \n", sprintffmt[INDEX] );
printf(sprintffmt[INDEX], buff);
return 0; }
|
|
 | | From: | Not Really Me | | Subject: | Re: scatter loading required? | | Date: | Wed, 19 Jan 2005 14:57:13 -0700 |
|
|
 | Hans-Bernhard Broeker wrote: > Not Really Me wrote: > >> The piece of code below works correctly if there is no split memory >> specified in the link command. Linked at 0x05000000 there are no >> problems. > > Seeing this line appear at file scope: > >> char buff[]; /* output stream buffer */ > > I rather seriously doubt that.
Sorry, caught by a cut and paste error in my haste to put the post together. In this simple test the array got allocated at the end of the variables, so it worked fine without hitting anything else. The original code is built and run regularly on at least 8 different compiler/processor combinations.
The problem as described still exits.
Scott
|
|
 | | From: | MW Ron | | Subject: | Re: scatter loading required? | | Date: | Thu, 20 Jan 2005 14:41:31 -0500 |
|
|
 | In article <3583aoF4kbss8U1@individual.net>, "Not Really Me" wrote:
>Hans-Bernhard Broeker wrote: >> Not Really Me wrote: >> >>> The piece of code below works correctly if there is no split memory >>> specified in the link command. Linked at 0x05000000 there are no >>> problems. >> >> Seeing this line appear at file scope: >> >>> char buff[]; /* output stream buffer */
what are you trying to do with this line, it is an empty array, you can't write to it later on.
>> I rather seriously doubt that. > >Sorry, caught by a cut and paste error in my haste to put the post together. >In this simple test the array got allocated at the end of the variables, so >it worked fine without hitting anything else.
Are you saying you had a pointer that was allocated or you had a C99 local array that was allocated later on?
>The original code is built >and run regularly on at least 8 different compiler/processor combinations. > >The problem as described still exits.
We probably need to have you file a full bug report with example project and source code/headers so we can duplicate this.
It still sounds like a corrupted memory due to overwriting something.
Ron
-- Metrowerks Community Forum is a free online resource for developers to discuss CodeWarrior topics with other users and Metrowerks' staff -- http://www.metrowerks.com/community --
Ron Liechty - MWRon@metrowerks.com - http://www.metrowerks.com
|
|
 | | From: | Not Really Me | | Subject: | Re: scatter loading required? | | Date: | Thu, 20 Jan 2005 14:13:58 -0700 |
|
|
 | Sorry, caught by a cross post problem. Here is an update:
Vadim Borshchev wrote: > Could you please consider crossposting: > http://www.uwasa.fi/~ts/http/crospost.html > > So, what is your corrected code that exhibits the problem? > > Vadim
Tauno Voipio wrote: > > Now, repair your cut-and-paste so that it compiles > and exhibits the undesired behaviour as posted, without > any modifications, and post the code.
Sorry, here is the corrected code. FWIW the code runs fine on Visual C also.
If the code is linked at RO Base 0x05000000 and RW Base 0x02000000, the load is not initialized correctly. The wrong data gets copied (by the C runtime initialization) to the RW base and a data error occurs on the 4th printf. Is this a bug, or does it need to have scatter loading specified?
Without a RW Base specified the output is:
Addr of sprintffmt = 05001a84
Addr of &sprintffmt[INDEX] = 05001a84
Addr of sprintffmt[INDEX] = 05001908 This is a test
With the RW Base specified as 0x02000000 the output should be:
Addr of sprintffmt = 02000000
Addr of &sprintffmt[INDEX] = 02000000
Addr of sprintffmt[INDEX] = 05001908 This is a test
If I run the second test directly after the first it works fine!. If I power off the board to erase all the ram and run only the second test I get:
Addr of sprintffmt = 02000000
Addr of &sprintffmt[INDEX] = 02000000
Addr of sprintffmt[INDEX] = 4bf7c776 Followed by a Data Abort error from Codewarrior.
Somehow the first load makes the second test work correctly. The first test does not need to be run, only loaded.
BTW, the debugger is an ARM MultiICE under CodeWarrior.
/* * File: main.c * Purpose: sample program * */ #include #include
#define SIZE 4
const char *sprintffmt[SIZE] = /* sprintf format strings */ { "%s\n", /* 0 */ "%s%s\n", /* 1 */ "%s%s%s\n", /* 2 */ "%s%s\n"}; /* 3 */
#define INDEX 0 /* Output buffer filename */ char buff[128]; /* output stream buffer */
int main() { strcpy(buff, "This is a test\n");
printf("\nAddr of sprintffmt = %p \n", sprintffmt ); printf("\nAddr of &sprintffmt[INDEX] = %p \n", &sprintffmt[INDEX] ); printf("\nAddr of sprintffmt[INDEX] = %p \n", sprintffmt[INDEX] );
printf(sprintffmt[INDEX], buff);
return 0; }
|
|
 | | From: | MW Ron | | Subject: | Re: scatter loading required? | | Date: | Fri, 21 Jan 2005 12:35:14 -0500 |
|
|
 | In article <35al6tF4kh5npU1@individual.net>, "Not Really Me" wrote:
>Sorry, caught by a cross post problem. Here is an update: > >Vadim Borshchev wrote: >> Could you please consider crossposting: >> http://www.uwasa.fi/~ts/http/crospost.html >> >> So, what is your corrected code that exhibits the problem? >> >> Vadim > >Tauno Voipio wrote: >> >> Now, repair your cut-and-paste so that it compiles >> and exhibits the undesired behaviour as posted, without >> any modifications, and post the code. > >Sorry, here is the corrected code. FWIW the code runs fine on Visual C >also. > >If the code is linked at RO Base 0x05000000 and RW Base 0x02000000, the load >is not initialized correctly. The wrong data gets copied (by the C runtime >initialization) to the RW base and a data error occurs on the 4th printf. >Is this a bug, or does it need to have scatter loading specified? > >Without a RW Base specified the output is: > >Addr of sprintffmt = 05001a84 > >Addr of &sprintffmt[INDEX] = 05001a84 > >Addr of sprintffmt[INDEX] = 05001908 >This is a test > >With the RW Base specified as 0x02000000 the output should be: > >Addr of sprintffmt = 02000000 > >Addr of &sprintffmt[INDEX] = 02000000 > >Addr of sprintffmt[INDEX] = 05001908 >This is a test > >If I run the second test directly after the first it works fine!. If I >power off the board to erase all the ram and run only the second test I get: > >Addr of sprintffmt = 02000000 > >Addr of &sprintffmt[INDEX] = 02000000 > >Addr of sprintffmt[INDEX] = 4bf7c776 >Followed by a Data Abort error from Codewarrior. > >Somehow the first load makes the second test work correctly. The first test >does not need to be run, only loaded. > >BTW, the debugger is an ARM MultiICE under CodeWarrior. > >/* > * File: main.c > * Purpose: sample program > * > */ >#include >#include > >#define SIZE 4 > >const char *sprintffmt[SIZE] = /* sprintf format strings */ > { "%s\n", /* 0 */ > "%s%s\n", /* 1 */ > "%s%s%s\n", /* 2 */ > "%s%s\n"}; /* 3 */ > > >#define INDEX 0 /* Output buffer filename */ >char buff[128]; /* output stream buffer */ > >int main() >{ > strcpy(buff, "This is a test\n"); > > printf("\nAddr of sprintffmt = %p \n", sprintffmt ); > printf("\nAddr of &sprintffmt[INDEX] = %p \n", &sprintffmt[INDEX] ); > printf("\nAddr of sprintffmt[INDEX] = %p \n", sprintffmt[INDEX] ); > > printf(sprintffmt[INDEX], buff); > > return 0; >} > >
I see this behavior in our other tools too, I don't think it is a code error. I will push this on to our ARM engineer and file it as a bug.
Ron
-- Metrowerks Community Forum is a free online resource for developers to discuss CodeWarrior topics with other users and Metrowerks' staff -- http://www.metrowerks.com/community --
Ron Liechty - MWRon@metrowerks.com - http://www.metrowerks.com
|
|
 | | From: | MW Ron | | Subject: | Re: scatter loading required? | | Date: | Thu, 20 Jan 2005 14:54:25 -0500 |
|
|
 | In article <357fj7F4hvlesU1@individual.net>, "Not Really Me" wrote:
> strcpy(buff, "This is a test\n");
Oh yeah this is why most C people say not to use strcpy
Ron
-- Metrowerks Community Forum is a free online resource for developers to discuss CodeWarrior topics with other users and Metrowerks' staff -- http://www.metrowerks.com/community --
Ron Liechty - MWRon@metrowerks.com - http://www.metrowerks.com
|
|
|