mirror of
https://github.com/Maschell/dynamic_libs.git
synced 2025-02-16 19:29:18 +01:00
Move most of OS_FIND_EXPORT{,_EX} into a function
This brought the file size of os_functions.o (compiled at -O2, not stripped) from 15K to 9.7K. Section sizes changed in the following ways: .text .rela.text .data .rodata.str1.4 .syntab .strtab .shstrtab before 5660 2928 276 3111 1264 1255 89 after 2860 2376 276 1175 1296 1294 89 The most obvious win is due to not including two strings per imported function ("OSFoo" and "Function OSFoo is NULL") in the .rodata section anymore, but outlining the error-handling code also reduced the size of .text significantly.
This commit is contained in:
parent
81b1a92727
commit
775993a09b
@ -149,9 +149,40 @@ EXPORT_DECL(s32, IOS_Ioctl,s32 fd, u32 request, void *input_buffer,u32 input_buf
|
||||
EXPORT_DECL(s32, IOS_Open,char *path, u32 mode);
|
||||
EXPORT_DECL(s32, IOS_Close,s32 fd);
|
||||
|
||||
void _os_find_export(u32 handle, const char *funcName, void *funcPointer)
|
||||
{
|
||||
OSDynLoad_FindExport(handle, 0, funcName, funcPointer);
|
||||
|
||||
if(!*(u32 *)funcPointer) {
|
||||
/*
|
||||
* This is effectively OSFatal("Function %s is NULL", funcName),
|
||||
* but we can't rely on any library functions like snprintf or
|
||||
* strcpy at this point.
|
||||
*
|
||||
* Buffer bounds are not checked. Beware!
|
||||
*/
|
||||
char buf[256], *bufp = buf;
|
||||
const char a[] = "Function ", b[] = " is NULL", *p;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(a) - 1; i++)
|
||||
*bufp++ = a[i];
|
||||
|
||||
for (p = funcName; *p; p++)
|
||||
*bufp++ = *p;
|
||||
|
||||
for (i = 0; i < sizeof(b) - 1; i++)
|
||||
*bufp++ = b[i];
|
||||
|
||||
*bufp++ = '\0';
|
||||
|
||||
OSFatal(buf);
|
||||
}
|
||||
}
|
||||
|
||||
void InitAcquireOS(void)
|
||||
{
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Lib handle functions
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
EXPORT_FUNC_WRITE(OSDynLoad_Acquire, (s32 (*)(const char*, unsigned *))OS_SPECIFICS->addr_OSDynLoad_Acquire);
|
||||
|
@ -49,25 +49,20 @@ extern "C" {
|
||||
|
||||
#define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val
|
||||
|
||||
#define OS_FIND_EXPORT(handle, func) funcPointer = 0; \
|
||||
OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \
|
||||
if(!funcPointer) \
|
||||
OSFatal("Function " # func " is NULL"); \
|
||||
#define OS_FIND_EXPORT(handle, func) _os_find_export(handle, # func, &funcPointer); \
|
||||
EXPORT_FUNC_WRITE(func, funcPointer);
|
||||
|
||||
#define OS_FIND_EXPORT_EX(handle, func, func_p) \
|
||||
funcPointer = 0; \
|
||||
OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \
|
||||
if(!funcPointer) \
|
||||
OSFatal("Function " # func " is NULL"); \
|
||||
_os_find_export(handle, # func, &funcPointer); \
|
||||
EXPORT_FUNC_WRITE(func_p, funcPointer);
|
||||
|
||||
#define OS_MUTEX_SIZE 44
|
||||
|
||||
/* Handle for coreinit */
|
||||
extern u32 coreinit_handle;
|
||||
void InitOSFunctionPointers(void);
|
||||
void InitAcquireOS(void);
|
||||
extern void _os_find_export(u32 handle, const char *funcName, void *funcPointer);
|
||||
extern void InitAcquireOS(void);
|
||||
extern void InitOSFunctionPointers(void);
|
||||
|
||||
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
//! Lib handle functions
|
||||
|
Loading…
x
Reference in New Issue
Block a user