[haiku-bugs] Re: [Haiku] #10509: Stack is not aligned

  • From: "simonsouth" <trac@xxxxxxxxxxxx>
  • Date: Wed, 28 Oct 2015 14:15:29 -0000

#10509: Stack is not aligned
-----------------------------+----------------------------
Reporter: pulkomandy | Owner: axeld
Type: enhancement | Status: new
Priority: normal | Milestone: Unscheduled
Component: System/Kernel | Version: R1/Development
Resolution: | Keywords:
Blocked By: | Blocking:
Has a Patch: 1 | Platform: x86-64
-----------------------------+----------------------------

Comment (by simonsouth):

Trying to use a `libroot.so` built with debugging information on x86_64
will reliably reproduce this issue with a general protection fault in
`runtime_loader`. The victim is [http://cgit.haiku-

os.org/haiku/tree/src/system/libroot/posix/string/arch/x86_64/arch_string.cpp#n153
memset_sse], whose first line creates a variable on the stack that
''must'' be 16-byte-aligned. (When compiled with `-O2` gcc places this
variable in a register, so a non-debug build works.)

Applying korli's patch helps but doesn't resolve the issue, since the
debugger shows the stack becomes misaligned again once `runtime_loader`
calls the initialization routine of the image it loads from disk.

This is because the glue code for x86_64 upsets the stack alignment by
[http://cgit.haiku-
os.org/haiku/tree/src/system/glue/arch/x86_64/crti.S#n32 pushing a single
register onto the stack] before calling initialization code that
eventually calls into libroot.

I've added a patch that modifies the glue code to keep the stack 16-byte-
aligned. With korli's patch and this one applied the issue seems to be
completely resolved; I can produce a stable nightly image (and a fully
debuggable `libroot.so`) though the packages the build system downloads,
notably WebKit and the OpenGL renderer, will need to be rebuilt with the
new glue code before everything works normally again.

--
Ticket URL: <https://dev.haiku-os.org/ticket/10509#comment:16>
Haiku <https://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: