This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] 32-bit cxa_finalize calls into user code; must have proper stack alignment for SSE2


Greetings,

As the test case below shows, 32-bit glibc does not properly align stack
for SSE2 code called from destructors.

A fix is trivial.

Thanks,

Test case:

--- cut --- misaligned.cc ---
#include <xmmintrin.h>
#include <assert.h>
#include <inttypes.h>
#include <stdio.h>

void foo()
{
  __m128 m;
  uintptr_t addr = (uintptr_t)&m;
  printf("addr = %x\n", addr);
  assert((addr & 0xF) == 0);
}

struct Foo {
  ~Foo() { foo(); }
};

Foo f;
--- cut --- misaligned.cc ---

--- cut --- misaligned-main.cc ---
extern int foo();

int main()
{
  foo();
}
--- cut --- misaligned-main.cc ---

g++ -m32 -msse2 -fPIC -shared -o misaligned.so misaligned.cc &&
g++ -m32 misaligned-main.cc ./misaligned.so &&
./a.out

addr = ff94c280
addr = ff94c12c
a.out: misaligned.cc:11: void foo(): Assertion `(addr & 0xF) == 0' failed.
Aborted



--
Paul Pluzhnikov


2011-01-10  Paul Pluzhnikov  <ppluzhnikov@google.com>

	* sysdeps/i386/Makefile: stdlib/cxa_finalize.c needs 16-byte
	stack alignment for SSE2.


diff --git a/sysdeps/i386/Makefile b/sysdeps/i386/Makefile
index ef45ce6..3d9f3fc 100644
--- a/sysdeps/i386/Makefile
+++ b/sysdeps/i386/Makefile
@@ -47,6 +47,7 @@ endif
 # And a couple of other routines
 ifeq ($(subdir),stdlib)
 CFLAGS-exit.c += -mpreferred-stack-boundary=4
+CFLAGS-cxa_finalize.c += -mpreferred-stack-boundary=4
 endif
 ifeq ($(subdir),elf)
 CFLAGS-dl-init.c += -mpreferred-stack-boundary=4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]