RSS
热门关键字:
当前位置 : 主页>嵌入式开发>手机操作系统>列表

Finding Initialized or Uninitialised static data in a DLL

来源:我要研发网 作者: 时间:1970-01-01 点击:




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

字串5

“ERROR: Dll (null)'” has initialised data”

字串5

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.

字串8

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.

字串6

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.

字串8

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 unsigned char UnInitializeData[4];
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.

字串1

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

@ Generated by gcc 2.9-psion-98r2(Symbian build 542) for ARM/pe

.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

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
相关文章