Introduction
The Symbian operating system does not support the use of writable static data in DLL’s. This can be a major problem if your application uses global variables. 字串2
There are a number of quick tricks that can be used in the Symbian tool chain to fix this problem quickly and easily. So whilst your application may build and run without problems on the emulator, it will fail to build using the ARM chipsets. Typically the error you will see will be
“ERROR: Dll (null)'” has initialised data”
Symbian do a good job of explaining why the error occurs in FAQ-0329, however they unfortunately left out how to find out which variable(s) is/are causing this error.
Finding uninitialized data
As with most things identifying you have a problem with non-const data is easy, you will find that your DLL does not build. Fixing it is harder however. 字串9
Below are the steps that need to be taken to identify and then isolate the offending variables in the source code.
字串8
Configuring your Project
A little used feature of the mmp file format is the OPTION command. In this case we use it to tell the Tool Chain that we want to add to the build flags for GCC compiler.
字串4
This option avoids either patching the perl script (ugly) or patching the generated make file from abld which are overwritten each time the build process is triggered. 字串3
The MMP file will need to be changed and the line below added to the top of the mmp file, after the UID declaration.
字串9
OPTION GCC -save-temps.
字串5
This line will add thus the “-save-temps” configuration to the GCC make file when it is built using the bldmake/makmake process. This command informs GCC to save the intermediate files that it generated so that it can be used later to see what went wrong. In our case it holds lots of clues about where we can find the static data that should not be there.
The project can now be regenerated using the BLDMAKE or MAKMAKE programs in the Symbian tool chain. Once these have been run and the make file created, it can be built. 字串8
During the build process a warning may be displayed “Warning: -pipe ignored since -save-temps specified” This message can safely be ignored as it is just indicating that we have overridden a GCC option.
Identifying the Writeable Data
By adding the “-save-temps” command to the compiler command line, this will generate a “.i” and a “.s” file in the directory where abld was created, this is normally the same directory as your bld.inf file.
字串6
If you are a command line wiz you can use grep command to find out which files have a “.data” and/or a “.bss” section in them. Alternatively just use the find in files functionality that is in most IDE’s to search the project directory (i.e. the bld.inf directory) for all files the have an extension of “.s” and contain the phrase “.bss” or “.data” “.bss” is the uninitinalized data section “.data” is the initialized data section. It is now a simple case of finding all the files with a .bss or a .data section in them, locating them in the “.s” file and then finding out the variable associated with the section. 字串2
Appropriate action can then be taken to fix the problem with the writable data.
字串9
A Short Example
This bit of code itself is very simple: 字串8
static char* NonConstData[1] = NULL;
We have two declarations for the variables, either one of which will cause build problems. 字串5
First you will need to comment out all the lines. Next, uncomment NoConstData and see that it generates a DLL has initialized data error in linking. 字串9
Next, comment out the NonConstData line and uncomment the UnInitializedData line and see that it generates a DLL has Uninitialized data error. Make sure both the lines are uncommented and do a build.
You will get errors. Open the generated “StaticData.s” file and search for the “.bss” string which is the uninitialised data section. You will see the intermediate code as below:
字串7
.file "Staticdata.cpp"
.gcc2_compiled.:
.section .rdata
.align 0
.LC0:
.ascii "test\000"
.data
.align 0
NonConstData:
.word .LC0
.text
.align 0
.global E32Dll__F10TDllReason
E32Dll__F10TDllReason:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, current_function_anonymous_args = 0
mov r0, #0
mov pc,
lr
.bss
UnInitializeData: .space 4
The .data and .bss data sections are the variables that have writeable data, in this case it is both initialized and uninitialized data. Fixing both these so that they are const and initialized will make the DLL build correctly 字串7
Acknowlegements
I would also like to extend my thanks to Simon Woodside who showed the -save-temps trick in GCC on his blog.
字串9
![我要研发网[www.51dev.com]](/templets/images/toplogo.gif)
