I am using Falch.net (2.7.2) to produce a simple shared library.  When I
compile the shared library with no optimization everything is fine.  When it
is compiled with optimization turned on, the compilation fails stating that
it can't find the dispatch table.  I presume that the optimization is
stripping out the dispatch table but I can't figure out why.  Any pointers
would be appreciated.

Thanks,
John

A snippet from the code:

/***************************************************************************
*/

// This macro specifies number of functions implemented in library in
addition to the four
// standard ones. When adding a function, this counter must be increased in
order for the
// library to work.
#define NUM_LIB_FUNCTIONS 4

#define _STR(x) #x // Defines x as "x"
#define DEFINE_STRING(x) _STR(x) // Needed for correct evaluation of macro
strings

#define NUM_FUNCTIONS (4 + NUM_LIB_FUNCTIONS) // Total number of entry
points in library function table
#define OFFSET_SIZE 2 // Size of offset
#define JMP_SIZE 4 // Size of jmp instruction
#define OFFSET_TABLE_SIZE ((NUM_FUNCTIONS + 1) * OFFSET_SIZE) // Size of
offset table

#define LIBENTRY_OFFSET(x) (OFFSET_TABLE_SIZE + ((x) * JMP_SIZE)) //
Calculate offset of function entry in jump table
#define LIBNAME_OFFSET LIBENTRY_OFFSET(NUM_FUNCTIONS) // Calculate offset of
library name string in jump table

#define LIBNAME_DEFINE "dc.w " DEFINE_STRING(LIBNAME_OFFSET) ";" // Define
library name string offset in jump table
#define LIBENTRY_DEFINE(x) "dc.w " DEFINE_STRING(LIBENTRY_OFFSET(x)) ";" //
Define library function offset in jump table
#define FUNCTION_DEFINE(func) "jmp " DEFINE_STRING(func) "(%%pc);" // Define
jump in jump table

/***************************************************************************
*/

// Global data structure for library
typedef struct tagDATA_PACKET
{
UInt16 ref_count; // Reference counter

// Library specific data goes here
} DATA_PACKET;

// Dummy prototype needed in order to get address of jump table
void jump_table(void);

/*
* Start function for library
*
* This HAS to be the first function defined in the object file.
* A library object file can also not contain any global data.
* This is why the global data structure is used instead.
*/
static UInt32 start(UInt16 refNum, SysLibTblEntryPtr entryP)
{
// Set dispatch table pointer to point to our jump table,
// and set global data pointer to NULL
entryP->dispatchTblP = (MemPtr) jump_table;
entryP->globalsP = NULL;
return 0;

// Library jump table
//
// Use LIBENTRY_DEFINE and FUNCTION_DEFINE macros to add functions to
// jump table. All functions must be defined here in same order as they are
// defined in the header file (with SYS_TRAP macro).
//
// *IMPORTANT*
// Block must appear exactly as is, and only LIBENTRY_DEFINE(x) and
// FUNCTION_DEFINE(func_name) entries can be added.
// Comments are also not allowed in the following code block.
// This is because of the way the GCC assembler works.
//
// When adding a function, the value of the NUM_LIB_FUNCTIONS macro must
// be increased!
__asm __volatile("jump_table:"
LIBNAME_DEFINE
LIBENTRY_DEFINE(0)
LIBENTRY_DEFINE(1)
LIBENTRY_DEFINE(2)
LIBENTRY_DEFINE(3)
LIBENTRY_DEFINE(4)
LIBENTRY_DEFINE(5)
LIBENTRY_DEFINE(6)
LIBENTRY_DEFINE(7)
FUNCTION_DEFINE(Open)
FUNCTION_DEFINE(Close)
FUNCTION_DEFINE(Sleep)
FUNCTION_DEFINE(Wake)
FUNCTION_DEFINE(LibCreate)
FUNCTION_DEFINE(LibRead)
FUNCTION_DEFINE(LibAdd)
FUNCTION_DEFINE(LibMul)
".asciz \"" Lib_NAME "\";"
".even;"::);
}



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to