ADS 1.2 Scatter Load used for Static Initialization | developer.brewmp.com ADS 1.2 Scatter Load used for Static Initialization | developer.brewmp.com

Developer

ADS 1.2 Scatter Load used for Static Initialization

Does anyone know of anyone who has successfully written a scatter file for ADS 1.2 that allows proper initialization of Global static variables in C++? Is it even possible? If not, does anyone have any ideas on how to mimic the behaviour of a final member in java in C++ without using proper global initialization?

ie:

Java

final int[] myArray = new int[2];
myArray = newInt[3]; // This line fails

C++

int* const myArray = new int[2]; // Can't do this line with ADS
int* const myArray = NULL; // Can only do this
myArray = new int[3]; // This line fails

http://brewforums.qualcomm.com/showthread.php?t=12804
The new elf2mod should allow you to use static data, including globals.
As for your BREW equivalent to Java's final array, I think justint myArray[2];should work if I am understanding what you are trying to do (an array that can't be changed, but the values in the array can be.)

http://brewforums.qualcomm.com/showthread.php?t=12804
The new elf2mod should allow you to use static data, including globals.
As for your BREW equivalent to Java's final array, I think justint myArray[2];should work if I am understanding what you are trying to do (an array that can't be changed, but the values in the array can be.)

Hehe I didnt make what I'm doing very clear now did I?
Unfortunately the little approach you had at last cant be used... at least not the way we are tackling things.
ALso, the problem with elf2mod is that we still have issues with constructors being called for staticly initialized data.
So elf2mod lets you HAVE globals, but constructing them in a C++ manner still doesn't work.

Hehe I didnt make what I'm doing very clear now did I?
Unfortunately the little approach you had at last cant be used... at least not the way we are tackling things.
ALso, the problem with elf2mod is that we still have issues with constructors being called for staticly initialized data.
So elf2mod lets you HAVE globals, but constructing them in a C++ manner still doesn't work.

What are you doing? "int myArray[2];" is the most natural translation. And when were you planning on freeing the memory?
Are you trying to create a global array of objects with constructors? Theoretically (at least with GCC, I'm not familiar with ADS) it should be possible to get the compiler to automatically insert calls to the constructor at the module entry point, but there's no place it can insert destructors. You could call them directly, I imagine it's probably about as difficult a task as writing elf2mod from scratch.
I think your best bet would be to use a non-const pointer, or a pointer-like class with a strangely named operator=. Or you could move the array to a class member and have a global pointer to one instance of that class.

What are you doing? "int myArray[2];" is the most natural translation. And when were you planning on freeing the memory?
Are you trying to create a global array of objects with constructors? Theoretically (at least with GCC, I'm not familiar with ADS) it should be possible to get the compiler to automatically insert calls to the constructor at the module entry point, but there's no place it can insert destructors. You could call them directly, I imagine it's probably about as difficult a task as writing elf2mod from scratch.
I think your best bet would be to use a non-const pointer, or a pointer-like class with a strangely named operator=. Or you could move the array to a class member and have a global pointer to one instance of that class.

Lets try this instead:
class MyClass
{
public:
static MyClass instance;
;
MyClass:MyClass instance;
The instance variable will not call the constructor for a MyClass object, it will remain uninitialized memory. Is there any way to make this work in ADS 1.2?

Lets try this instead:
class MyClass
{
public:
static MyClass instance;
;
MyClass:MyClass instance;
The instance variable will not call the constructor for a MyClass object, it will remain uninitialized memory. Is there any way to make this work in ADS 1.2?

In addition to all this, I still get "corrupt" static objects when compiling with ADS.
Basically objects get initialized to something other than NULL even though I explicitly initialize them to NULL.
This ends up breaking games at very strange times (usually during initialization)

In addition to all this, I still get "corrupt" static objects when compiling with ADS.
Basically objects get initialized to something other than NULL even though I explicitly initialize them to NULL.
This ends up breaking games at very strange times (usually during initialization)

Check out
http://brew.wardco.com/index.html
the "Update: 29 Apr 07:" section on top of that page.
I think this might contain the answer to your question, but its for GCC :(

Check out
http://brew.wardco.com/index.html
the "Update: 29 Apr 07:" section on top of that page.
I think this might contain the answer to your question, but its for GCC :(

the random intialization issue is cause by a bug in elf2mod that ".rss" and ".reloc" overlap each other. So some( not all) un-initialized static variables are intialized to a random value. The consequences is that you cannot have a static varialbs that are initialized to zero.
The only poster linker that works is the lightblue post linker(http://lightblue.tigris.org/) at this moment. You don't need to compile the lightblue library, just use the pre-compiled post linker( lbmg.exe) that comes with the 0.87 distribution.

the random intialization issue is cause by a bug in elf2mod that ".rss" and ".reloc" overlap each other. So some( not all) un-initialized static variables are intialized to a random value. The consequences is that you cannot have a static varialbs that are initialized to zero.
The only poster linker that works is the lightblue post linker(http://lightblue.tigris.org/) at this moment. You don't need to compile the lightblue library, just use the pre-compiled post linker( lbmg.exe) that comes with the 0.87 distribution.

unfortunately Lightblue doesn't work with ADS 1.2.... at least according to their site.

unfortunately Lightblue doesn't work with ADS 1.2.... at least according to their site.

actually, it did.
The only issue is that on ads1.2 , the constructor of the global objects are not called, which you can always find a way to workaround.

actually, it did.
The only issue is that on ads1.2 , the constructor of the global objects are not called, which you can always find a way to workaround.

Really?
When I try to use lbmg.exe on my elf file I get :
[Error] More than one loadable segments exists
[Failed] (error code = 2003)
How does one fix this?

Really?
When I try to use lbmg.exe on my elf file I get :
[Error] More than one loadable segments exists
[Failed] (error code = 2003)
How does one fix this?

First you should remove all compiler and link flags that are related to "ropi" or "rwpi".
Then add "-reloc" to the linker cmd if it is not there and more importantely: REMOVE "-split" from the linker cmd. The error message from lbmg suggests that you are useing the "-split" switch which is required by elf2mod but is not supported by lbmg.
If it does not work, please post your make file please.

First you should remove all compiler and link flags that are related to "ropi" or "rwpi".
Then add "-reloc" to the linker cmd if it is not there and more importantely: REMOVE "-split" from the linker cmd. The error message from lbmg suggests that you are useing the "-split" switch which is required by elf2mod but is not supported by lbmg.
If it does not work, please post your make file please.