in the interest of removing all .text relocations from Gentoo, the Imlib2 mmx code came up ... the files in question here are: asm_blend.S asm_blend_cmod.S asm_rgba.S
each of these uses memory masks to load into mmx registers ... the problem is, they dont use PIC-aware memory references so every time one of these masks are utilized, a text relocation is generated ... so when the dynamic loader loads the library, it has to fix up each of these memory references. on many hardened systems, the library won't even be loaded because the kernel/loader refuses to process text relocations. find attached a PoC patch ive been toying with lately for asm_blend.S which fixes each memory reference so that it is PIC aware. i can understand if some people could care less if their library has textrel's in them and would rather sacrifice a bit of slowdown at load time rather than slowdown at runtime, so if someone objects to having this be the default PIC behavior, i'm okay with hiding it behind a configure flag: ./configure --enable-mmx --enable-pic-mmx where normally pic-mmx is disabled and user has to specify it themselves btw, the patch is untested beyond compiling since ive never really used imlib2 before so coming up with a test case would be a bit hard for me :) -mike
Index: src/lib/asm_blend.S =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/imlib2/src/lib/asm_blend.S,v retrieving revision 1.2 diff -u -p -r1.2 asm_blend.S --- src/lib/asm_blend.S 5 Aug 2005 21:45:56 -0000 1.2 +++ src/lib/asm_blend.S 5 Aug 2005 21:56:59 -0000 @@ -157,12 +157,34 @@ c1: .word 0x1, 0x1, 0x1, 0x1 popl %ebp ;\ ret +#ifdef __PIC__ + +# define LOAD_PIC_REG(func) \ + pushl %ebx ; \ + call .L0##func ; \ +.L0##func: popl %ebx +# define UNLOAD_PIC_REG \ + popl %ebx +# define LOAD_MASK(maskvar, reg) \ + mov [EMAIL PROTECTED](%ebx), %ecx ; \ + movq (%ecx), reg + +#else + +# define LOAD_PIC_REG(func) +# define UNLOAD_PIC_REG +# define LOAD_MASK(maskvar, reg) movq maskvar, reg + +#endif /* __PIC__ */ + PR_(imlib_mmx_blend_rgba_to_rgb): ENTER pxor %mm4, %mm4 - movq c1, %mm5 + LOAD_PIC_REG(imlib_mmx_blend_rgba_to_rgb) + LOAD_MASK(c1, %mm5) + UNLOAD_PIC_REG LOOP_START 1: @@ -218,9 +240,11 @@ PR_(imlib_mmx_blend_rgba_to_rgba): ENTER pxor %mm4, %mm4 - movq m0X000000, %mm5 - movq m00XXXXXX, %mm6 - movq c1, %mm7 + LOAD_PIC_REG(imlib_mmx_blend_rgba_to_rgba) + LOAD_MASK(m0X000000, %mm5) + LOAD_MASK(m00XXXXXX, %mm6) + LOAD_MASK(c1, %mm7) + UNLOAD_PIC_REG LOOP_START 1: @@ -272,8 +296,10 @@ SIZE(imlib_mmx_blend_rgba_to_rgba) PR_(imlib_mmx_copy_rgba_to_rgb): ENTER - movq m0XXX0XXX, %mm5 - movq mX000X000, %mm6 + LOAD_PIC_REG(imlib_mmx_copy_rgba_to_rgb) + LOAD_MASK(m0XXX0XXX, %mm5) + LOAD_MASK(mX000X000, %mm6) + UNLOAD_PIC_REG /*\ Two at a time: last item is at %ecx = 0 \*/ subl $4, %esi @@ -342,7 +368,9 @@ SIZE(imlib_mmx_copy_rgba_to_rgba) PR_(imlib_mmx_copy_rgb_to_rgba): ENTER - movq mX000X000, %mm5 + LOAD_PIC_REG(imlib_mmx_copy_rgb_to_rgba) + LOAD_MASK(mX000X000, %mm5) + UNLOAD_PIC_REG subl $4, %esi subl $4, %edi @@ -415,8 +443,10 @@ PR_(imlib_mmx_add_blend_rgba_to_rgba): ENTER pxor %mm4, %mm4 - movq mVX000000, %mm5 - movq m00XXXXXX, %mm6 + LOAD_PIC_REG(imlib_mmx_add_blend_rgba_to_rgba) + LOAD_MASK(mVX000000, %mm5) + LOAD_MASK(m00XXXXXX, %mm6) + UNLOAD_PIC_REG LOOP_START 1: @@ -463,7 +493,9 @@ SIZE(imlib_mmx_add_blend_rgba_to_rgba) PR_(imlib_mmx_add_copy_rgba_to_rgb): ENTER - movq m0XXX0XXX, %mm5 + LOAD_PIC_REG(imlib_mmx_add_copy_rgba_to_rgb) + LOAD_MASK(m0XXX0XXX, %mm5) + UNLOAD_PIC_REG subl $4, %esi subl $4, %edi @@ -533,7 +565,9 @@ SIZE(imlib_mmx_add_copy_rgba_to_rgba) PR_(imlib_mmx_add_copy_rgb_to_rgba): ENTER - movq mX000X000, %mm5 + LOAD_PIC_REG(imlib_mmx_add_copy_rgb_to_rgba) + LOAD_MASK(mX000X000, %mm5) + UNLOAD_PIC_REG subl $4, %esi subl $4, %edi @@ -613,8 +647,10 @@ PR_(imlib_mmx_subtract_blend_rgba_to_rgb ENTER pxor %mm4, %mm4 - movq mV0000000, %mm5 - movq m00XXXXXX, %mm6 + LOAD_PIC_REG(imlib_mmx_subtract_blend_rgba_to_rgba) + LOAD_MASK(mV0000000, %mm5) + LOAD_MASK(m00XXXXXX, %mm6) + UNLOAD_PIC_REG LOOP_START 1: @@ -661,7 +697,9 @@ SIZE(imlib_mmx_subtract_blend_rgba_to_rg PR_(imlib_mmx_subtract_copy_rgba_to_rgb): ENTER - movq m0XXX0XXX, %mm5 + LOAD_PIC_REG(imlib_mmx_subtract_copy_rgba_to_rgb) + LOAD_MASK(m0XXX0XXX, %mm5) + UNLOAD_PIC_REG subl $4, %esi subl $4, %edi @@ -699,7 +737,9 @@ SIZE(imlib_mmx_subtract_copy_rgba_to_rgb PR_(imlib_mmx_subtract_copy_rgba_to_rgba): ENTER - movq mX000X000, %mm5 + LOAD_PIC_REG(imlib_mmx_subtract_copy_rgba_to_rgba) + LOAD_MASK(mX000X000, %mm5) + UNLOAD_PIC_REG subl $4, %esi subl $4, %edi @@ -741,7 +781,9 @@ SIZE(imlib_mmx_subtract_copy_rgba_to_rgb PR_(imlib_mmx_subtract_copy_rgb_to_rgba): ENTER - movq mX000X000, %mm5 + LOAD_PIC_REG(imlib_mmx_subtract_copy_rgb_to_rgba) + LOAD_MASK(mX000X000, %mm5) + UNLOAD_PIC_REG subl $4, %esi subl $4, %edi @@ -780,7 +822,9 @@ PR_(imlib_mmx_reshade_blend_rgba_to_rgb) ENTER pxor %mm4, %mm4 - movq m000V0V0V, %mm6 + LOAD_PIC_REG(imlib_mmx_reshade_blend_rgba_to_rgb) + LOAD_MASK(m000V0V0V, %mm6) + UNLOAD_PIC_REG LOOP_START 1: @@ -823,9 +867,11 @@ PR_(imlib_mmx_reshade_blend_rgba_to_rgba ENTER pxor %mm4, %mm4 - movq mI0000000, %mm5 - movq m000V0V0V, %mm6 - movq m00XXXXXX, %mm7 + LOAD_PIC_REG(imlib_mmx_reshade_blend_rgba_to_rgba) + LOAD_MASK(mI0000000, %mm5) + LOAD_MASK(m000V0V0V, %mm6) + LOAD_MASK(m00XXXXXX, %mm7) + UNLOAD_PIC_REG LOOP_START 1: @@ -875,8 +921,10 @@ PR_(imlib_mmx_reshade_copy_rgba_to_rgb): ENTER pxor %mm4, %mm4 - movq m0XXX0XXX, %mm5 - movq m0VVV0VVV, %mm6 + LOAD_PIC_REG(imlib_mmx_reshade_copy_rgba_to_rgb) + LOAD_MASK(m0XXX0XXX, %mm5) + LOAD_MASK(m0VVV0VVV, %mm6) + UNLOAD_PIC_REG subl $4, %esi subl $4, %edi @@ -939,8 +987,10 @@ PR_(imlib_mmx_reshade_copy_rgba_to_rgba) ENTER pxor %mm4, %mm4 - movq m0XXX0XXX, %mm5 - movq m0VVV0VVV, %mm6 + LOAD_PIC_REG(imlib_mmx_reshade_copy_rgba_to_rgba) + LOAD_MASK(m0XXX0XXX, %mm5) + LOAD_MASK(m0VVV0VVV, %mm6) + UNLOAD_PIC_REG subl $4, %esi subl $4, %edi @@ -1004,9 +1054,11 @@ PR_(imlib_mmx_reshade_copy_rgb_to_rgba): ENTER pxor %mm4, %mm4 - movq m0XXX0XXX, %mm5 - movq m0VVV0VVV, %mm6 - movq mX000X000, %mm7 + LOAD_PIC_REG(imlib_mmx_reshade_copy_rgb_to_rgba) + LOAD_MASK(m0XXX0XXX, %mm5) + LOAD_MASK(m0VVV0VVV, %mm6) + LOAD_MASK(mX000X000, %mm7) + UNLOAD_PIC_REG subl $4, %esi subl $4, %edi