Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Von: Thomas Zimmermann

Betreff: [SDL] [PATCH] Make static variables const
Datum: Tue, 19 May 2009 19:45:37 +0200

Hi,

this is a set of simple changes which make some of SDL's internal static
arrays constant. The purpose is to shrink the number of write-able
static bytes and thus increase the number of memory pages shared between
SDL applications.

The patch set is against trunk@4513. Each of the attached patch files is
specific to a sub-system. The set is completed by a second mail, because
of the list's 40 KiB limit.

The files readelf-r4513.txt and readelf-const-patch.txt where made by
calling 'readelf -S libSDL.so'. They show the difference in ELF sections
without and with the patch. Some numbers measured on my x86-64:

Before

 [13] .rodata           PROGBITS         00000000000eaaa0  000eaaa0
      0000000000008170  0000000000000000   A       0     0     32
 [19] .data.rel.ro      PROGBITS         00000000003045e0  001045e0
      00000000000023d0  0000000000000000  WA       0     0     32
 [23] .data             PROGBITS         00000000003076e0  001076e0
      0000000000004988  0000000000000000  WA       0     0     32

After

 [13] .rodata           PROGBITS         00000000000eaaa0  000eaaa0
      0000000000009a50  0000000000000000   A       0     0     32
 [19] .data.rel.ro      PROGBITS         0000000000306040  00106040
      0000000000002608  0000000000000000  WA       0     0     32
 [23] .data             PROGBITS         0000000000309360  00109360
      0000000000002e88  0000000000000000  WA       0     0     32

The size of the write-able data section decreased considerably. Some
entries became const-after-relocation, while most of its content went
straight into the read-only data section.

Best regards, Thomas
  • Loading branch information
slouken committed Jun 3, 2009
1 parent 6b7fccd commit 8ec0e16b15c7875384594f1156e99d158b3b93fd
@@ -43,7 +43,7 @@ SDL_Parachute(int sig)
raise(sig);
}

static int SDL_fatal_signals[] = {
static const int SDL_fatal_signals[] = {
SIGSEGV,
#ifdef SIGBUS
SIGBUS,
@@ -77,7 +77,7 @@ extern AudioBootStrap FUSIONSOUND_bootstrap;


/* Available audio drivers */
static AudioBootStrap *bootstrap[] = {
static const AudioBootStrap *const bootstrap[] = {
#if SDL_AUDIO_DRIVER_BSD
&BSD_AUDIO_bootstrap,
#endif
@@ -60,9 +60,11 @@ static struct
{
const char *name;
void **func;
} esd_functions[] = {
SDL_ESD_SYM(esd_open_sound),
SDL_ESD_SYM(esd_close), SDL_ESD_SYM(esd_play_stream),};
} const esd_functions[] = {
SDL_ESD_SYM(esd_open_sound),
SDL_ESD_SYM(esd_close), SDL_ESD_SYM(esd_play_stream),
};

#undef SDL_ESD_SYM

static void
@@ -34,7 +34,7 @@ static int SDL_num_keyboards;
static int SDL_current_keyboard;
static SDL_Keyboard **SDL_keyboards;

static SDLKey SDL_default_keymap[SDL_NUM_SCANCODES] = {
static const SDLKey SDL_default_keymap[SDL_NUM_SCANCODES] = {
0, 0, 0, 0,
'a',
'b',
@@ -28,7 +28,7 @@
#define BLANK_CHOTX 0
#define BLANK_CHOTY 0

static unsigned char blank_cdata[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
static unsigned char blank_cmask[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
static const unsigned char blank_cdata[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
static const unsigned char blank_cmask[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

/* vi: set ts=4 sw=4 expandtab: */
@@ -33,7 +33,7 @@

#ifdef USE_MACOS_CURSOR

static unsigned char default_cdata[] = {
static const unsigned char default_cdata[] = {
0x00, 0x00,
0x40, 0x00,
0x60, 0x00,
@@ -52,7 +52,7 @@ static unsigned char default_cdata[] = {
0x00, 0x00
};

static unsigned char default_cmask[] = {
static const unsigned char default_cmask[] = {
0xC0, 0x00,
0xE0, 0x00,
0xF0, 0x00,
@@ -73,7 +73,7 @@ static unsigned char default_cmask[] = {

#else

static unsigned char default_cdata[] = {
static const unsigned char default_cdata[] = {
0x00, 0x00,
0x40, 0x00,
0x60, 0x00,
@@ -92,7 +92,7 @@ static unsigned char default_cdata[] = {
0x00, 0x00
};

static unsigned char default_cmask[] = {
static const unsigned char default_cmask[] = {
0x40, 0x00,
0xE0, 0x00,
0xF0, 0x00,
@@ -27,7 +27,7 @@
- experimentation on various ADB and USB ISO keyboards and one ADB ANSI keyboard
*/
/* *INDENT-OFF* */
static SDL_scancode darwin_scancode_table[] = {
static const SDL_scancode darwin_scancode_table[] = {
/* 0 */ SDL_SCANCODE_A,
/* 1 */ SDL_SCANCODE_S,
/* 2 */ SDL_SCANCODE_D,
@@ -26,7 +26,7 @@
- Linux kernel source input.h
*/
/* *INDENT-OFF* */
static SDL_scancode linux_scancode_table[] = {
static SDL_scancode const linux_scancode_table[] = {
/* 0 */ SDL_SCANCODE_UNKNOWN,
/* 1 */ SDL_SCANCODE_ESCAPE,
/* 2 */ SDL_SCANCODE_1,
@@ -26,7 +26,7 @@
- msdn.microsoft.com
*/
/* *INDENT-OFF* */
static SDL_scancode win32_scancode_table[] = {
static const SDL_scancode win32_scancode_table[] = {
/* 0, 0x00 */ SDL_SCANCODE_UNKNOWN,
/* 1, 0x01 */ SDL_SCANCODE_UNKNOWN,
/* 2, 0x02 */ SDL_SCANCODE_UNKNOWN,
@@ -26,7 +26,7 @@
- atKeyNames.h from XFree86 source code
*/
/* *INDENT-OFF* */
static SDL_scancode xfree86_scancode_table[] = {
static const SDL_scancode xfree86_scancode_table[] = {
/* 0 */ SDL_SCANCODE_UNKNOWN,
/* 1 */ SDL_SCANCODE_ESCAPE,
/* 2 */ SDL_SCANCODE_1,
@@ -177,7 +177,7 @@ static SDL_scancode xfree86_scancode_table[] = {
};

/* for wireless usb keyboard (manufacturer TRUST) without numpad. */
static SDL_scancode xfree86_scancode_table2[] = {
static const SDL_scancode xfree86_scancode_table2[] = {
/* 0 */ SDL_SCANCODE_UNKNOWN,
/* 1 */ SDL_SCANCODE_ESCAPE,
/* 2 */ SDL_SCANCODE_1,
@@ -11,7 +11,8 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_log.c,v 1.8 1995/05/10 20:45:49 jtc Exp $";
static const char rcsid[] =
"$NetBSD: e_log.c,v 1.8 1995/05/10 20:45:49 jtc Exp $";
#endif

/* __ieee754_log(x)
@@ -11,7 +11,7 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] =
static const char rcsid[] =
"$NetBSD: e_rem_pio2.c,v 1.8 1995/05/10 20:46:02 jtc Exp $";
#endif

@@ -11,7 +11,8 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: e_sqrt.c,v 1.8 1995/05/10 20:46:17 jtc Exp $";
static const char rcsid[] =
"$NetBSD: e_sqrt.c,v 1.8 1995/05/10 20:46:17 jtc Exp $";
#endif

/* __ieee754_sqrt(x)
@@ -11,7 +11,8 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: k_cos.c,v 1.8 1995/05/10 20:46:22 jtc Exp $";
static const char rcsid[] =
"$NetBSD: k_cos.c,v 1.8 1995/05/10 20:46:22 jtc Exp $";
#endif

/*
@@ -11,7 +11,7 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] =
static const char rcsid[] =
"$NetBSD: k_rem_pio2.c,v 1.7 1995/05/10 20:46:25 jtc Exp $";
#endif

@@ -11,7 +11,8 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: k_sin.c,v 1.8 1995/05/10 20:46:31 jtc Exp $";
static const char rcsid[] =
"$NetBSD: k_sin.c,v 1.8 1995/05/10 20:46:31 jtc Exp $";
#endif

/* __kernel_sin( x, y, iy)
@@ -11,7 +11,7 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] =
static const char rcsid[] =
"$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $";
#endif

@@ -11,7 +11,8 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: s_cos.c,v 1.7 1995/05/10 20:47:02 jtc Exp $";
static const char rcsid[] =
"$NetBSD: s_cos.c,v 1.7 1995/05/10 20:47:02 jtc Exp $";
#endif

/* cos(x)
@@ -11,7 +11,8 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: s_fabs.c,v 1.7 1995/05/10 20:47:13 jtc Exp $";
static const char rcsid[] =
"$NetBSD: s_fabs.c,v 1.7 1995/05/10 20:47:13 jtc Exp $";
#endif

/*
@@ -11,7 +11,7 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] =
static const char rcsid[] =
"$NetBSD: s_floor.c,v 1.8 1995/05/10 20:47:20 jtc Exp $";
#endif

@@ -11,7 +11,7 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] =
static const char rcsid[] =
"$NetBSD: s_scalbn.c,v 1.8 1995/05/10 20:48:08 jtc Exp $";
#endif

@@ -11,7 +11,8 @@
*/

#if defined(LIBM_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: s_sin.c,v 1.7 1995/05/10 20:48:15 jtc Exp $";
static const char rcsid[] =
"$NetBSD: s_sin.c,v 1.7 1995/05/10 20:48:15 jtc Exp $";
#endif

/* sin(x)
@@ -60,7 +60,7 @@

#ifndef HAVE_QSORT

static char _ID[] = "<qsort.c gjm 1.12 1998-03-19>";
static const char _ID[] = "<qsort.c gjm 1.12 1998-03-19>";

/* How many bytes are there per word? (Must be a power of 2,
* and must in fact equal sizeof(int).)
@@ -29,7 +29,7 @@
#include "../SDL_systhread.h"

/* List of signals to mask in the subthreads */
static int sig_list[] = {
static const int sig_list[] = {
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
SIGVTALRM, SIGPROF, 0
};
@@ -1259,7 +1259,7 @@ getpix_32(Uint8 * srcbuf)

typedef Uint32(*getpix_func) (Uint8 *);

static getpix_func getpixes[4] = {
static const getpix_func getpixes[4] = {
getpix_8, getpix_16, getpix_24, getpix_32
};

@@ -443,11 +443,11 @@ BlitBtoNAlphaKey(SDL_BlitInfo * info)
}
}

static SDL_BlitFunc bitmap_blit[] = {
static const SDL_BlitFunc bitmap_blit[] = {
NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4
};

static SDL_BlitFunc colorkey_blit[] = {
static const SDL_BlitFunc colorkey_blit[] = {
NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key
};

@@ -512,11 +512,11 @@ Blit1toNAlphaKey(SDL_BlitInfo * info)
}
}

static SDL_BlitFunc one_blit[] = {
static const SDL_BlitFunc one_blit[] = {
NULL, Blit1to1, Blit1to2, Blit1to3, Blit1to4
};

static SDL_BlitFunc one_blitkey[] = {
static const SDL_BlitFunc one_blitkey[] = {
NULL, Blit1to1Key, Blit1to2Key, Blit1to3Key, Blit1to4Key
};

@@ -113,7 +113,7 @@ calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt)
* leave alpha with a zero mask, but we should still swizzle the bits.
*/
/* ARGB */
const static struct SDL_PixelFormat default_pixel_format = {
const static const struct SDL_PixelFormat default_pixel_format = {
NULL, 32, 4,
0, 0, 0, 0,
16, 8, 0, 24,
@@ -2404,7 +2404,7 @@ static const struct blit_table normal_blit_4[] = {
{0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0}
};

static const struct blit_table *normal_blit[] = {
static const struct blit_table *const normal_blit[] = {
normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4
};

@@ -48,7 +48,7 @@
#endif /* SDL_VIDEO_OPENGL */

/* Available video drivers */
static VideoBootStrap *bootstrap[] = {
static const VideoBootStrap *const bootstrap[] = {
#if SDL_VIDEO_DRIVER_COCOA
&COCOA_bootstrap,
#endif
@@ -32,7 +32,7 @@
#include "imKStoUCS.h"

/* *INDENT-OFF* */
static struct {
static const struct {
KeySym keysym;
SDLKey sdlkey;
} KeySymToSDLKey[] = {
@@ -132,9 +132,9 @@ static struct {
{ XK_Mode_switch, SDLK_MODE },
};

static struct
static const struct
{
SDL_scancode *table;
const SDL_scancode const *table;
int table_size;
} scancode_set[] = {
{ darwin_scancode_table, SDL_arraysize(darwin_scancode_table) },
@@ -102,7 +102,7 @@ static unsigned short const keysym_to_unicode_590_5fe[] = {
0x06a9, 0x06af, 0x06ba, 0x06be, 0x06cc, 0x06d2, 0x06c1 /* 0x05f8-0x05fe */
};

static unsigned short keysym_to_unicode_680_6ff[] = {
static unsigned short const keysym_to_unicode_680_6ff[] = {
0x0492, 0x0496, 0x049a, 0x049c, 0x04a2, 0x04ae, 0x04b0, 0x04b2, /* 0x0680-0x0687 */
0x04b6, 0x04b8, 0x04ba, 0x0000, 0x04d8, 0x04e2, 0x04e8, 0x04ee, /* 0x0688-0x068f */
0x0493, 0x0497, 0x049b, 0x049d, 0x04a3, 0x04af, 0x04b1, 0x04b3, /* 0x0690-0x0697 */
@@ -214,7 +214,7 @@ static unsigned short const keysym_to_unicode_ea0_eff[] = {
0x11eb, 0x0000, 0x11f9, 0x0000, 0x0000, 0x0000, 0x0000, 0x20a9, /* 0x0ef8-0x0eff */
};

static unsigned short keysym_to_unicode_12a1_12fe[] = {
static unsigned short const keysym_to_unicode_12a1_12fe[] = {
0x1e02, 0x1e03, 0x0000, 0x0000, 0x0000, 0x1e0a, 0x0000, /* 0x12a0-0x12a7 */
0x1e80, 0x0000, 0x1e82, 0x1e0b, 0x1ef2, 0x0000, 0x0000, 0x0000, /* 0x12a8-0x12af */
0x1e1e, 0x1e1f, 0x0000, 0x0000, 0x1e40, 0x1e41, 0x0000, 0x1e56, /* 0x12b0-0x12b7 */
@@ -233,7 +233,7 @@ static unsigned short const keysym_to_unicode_13bc_13be[] = {
0x0152, 0x0153, 0x0178 /* 0x13b8-0x13bf */
};

static unsigned short keysym_to_unicode_14a1_14ff[] = {
static unsigned short const keysym_to_unicode_14a1_14ff[] = {
0x2741, 0x00a7, 0x0589, 0x0029, 0x0028, 0x00bb, 0x00ab, /* 0x14a0-0x14a7 */
0x2014, 0x002e, 0x055d, 0x002c, 0x2013, 0x058a, 0x2026, 0x055c, /* 0x14a8-0x14af */
0x055b, 0x055e, 0x0531, 0x0561, 0x0532, 0x0562, 0x0533, 0x0563, /* 0x14b0-0x14b7 */
@@ -248,15 +248,15 @@ static unsigned short keysym_to_unicode_14a1_14ff[] = {
0x0554, 0x0584, 0x0555, 0x0585, 0x0556, 0x0586, 0x2019, 0x0027, /* 0x14f8-0x14ff */
};

static unsigned short keysym_to_unicode_15d0_15f6[] = {
static unsigned short const keysym_to_unicode_15d0_15f6[] = {
0x10d0, 0x10d1, 0x10d2, 0x10d3, 0x10d4, 0x10d5, 0x10d6, 0x10d7, /* 0x15d0-0x15d7 */
0x10d8, 0x10d9, 0x10da, 0x10db, 0x10dc, 0x10dd, 0x10de, 0x10df, /* 0x15d8-0x15df */
0x10e0, 0x10e1, 0x10e2, 0x10e3, 0x10e4, 0x10e5, 0x10e6, 0x10e7, /* 0x15e0-0x15e7 */
0x10e8, 0x10e9, 0x10ea, 0x10eb, 0x10ec, 0x10ed, 0x10ee, 0x10ef, /* 0x15e8-0x15ef */
0x10f0, 0x10f1, 0x10f2, 0x10f3, 0x10f4, 0x10f5, 0x10f6 /* 0x15f0-0x15f7 */
};

static unsigned short keysym_to_unicode_16a0_16f6[] = {
static unsigned short const keysym_to_unicode_16a0_16f6[] = {
0x0000, 0x0000, 0xf0a2, 0x1e8a, 0x0000, 0xf0a5, 0x012c, 0xf0a7, /* 0x16a0-0x16a7 */
0xf0a8, 0x01b5, 0x01e6, 0x0000, 0x0000, 0x0000, 0x0000, 0x019f, /* 0x16a8-0x16af */
0x0000, 0x0000, 0xf0b2, 0x1e8b, 0x01d1, 0xf0b5, 0x012d, 0xf0b7, /* 0x16b0-0x16b7 */

0 comments on commit 8ec0e16

Please sign in to comment.