Re: AMD64: stack alignment

Claus Assmann <[email protected]> Wed, 18 Dec 2013 10:51:10 -0800
Newsgroups gmane.comp.lib.state-threads.devel
Message-ID <[email protected]>
--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

A small test program is attached.
It crashes with OpenSSL 1.0.1e on
OpenBSD 5.4 amd64
FreeBSD 8.4 amd64 gcc 4.2.1 20070831
It does not crash on Linux amd64 (CentOS 5.3? gcc 4.1.2)):

%rsp is different on Linux vs *BSD. I don't know why...

--------------------
FreeBSD:
$ gdb stack1
GNU gdb 6.1.1 [FreeBSD]
(gdb) b sha1_block_data_order_ssse3
Breakpoint 1 at 0x414cf0: file sha1-x86_64.s, line 1295.
(gdb) run a
Starting program: obj/statethreads/examples/stack1 a

Breakpoint 1, sha1_block_data_order_ssse3 () at sha1-x86_64.s:1295
1295            pushq   %rbx
Current language:  auto; currently asm
(gdb) p $rsp
$1 = (void *) 0x80064abe0

(gdb) c
Continuing.

Program received signal SIGBUS, Bus error.
sha1_block_data_order_ssse3 () at sha1-x86_64.s:1328
1328            movdqa  %xmm0,0(%rsp)
(gdb) where
#0  sha1_block_data_order_ssse3 () at sha1-x86_64.s:1328

--------------------
Linux:
$ gdb ./stack1
GNU gdb Fedora (6.8-27.el5)
...
This GDB was configured as "x86_64-redhat-linux-gnu"...
(gdb) b sha1_block_data_order_ssse3
Breakpoint 1 at 0x412ad0
(gdb) run a
Starting program: obj.Linux.2.6.18.64/statethreads/examples/stack1 a

Breakpoint 1, 0x0000000000412ad0 in sha1_block_data_order_ssse3 ()
(gdb) p $rsp
$1 = (void *) 0x2b961b87ac68
(gdb) cont
Continuing.
arg=a


--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="stack1.c"

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include "openssl/ssl.h"
#include "openssl/rand.h"
#include "st.h"

void *
myfunc(void *arg)
{
  char *a;
  unsigned long Time;

  Time=(unsigned long)time(NULL);
  RAND_add(&Time,sizeof(Time),0);
  a = (char *)arg;
  if (a != NULL) { printf("arg=%s\n", a); }
  return arg;
}

int
main(int argc, char *argv[])
{
  int i;

  if (st_init() < 0) { perror("st_init"); exit(1); }
  for (i = 1; i < argc; i++) {
    if (st_thread_create(myfunc, argv[i], 0, 0) == NULL) {
      perror("st_thread_create");
      exit(1);
    }
  }

  st_thread_exit(NULL);

  /* NOTREACHED */
  return 1;
}


--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
--RnlQjJ0d97Da+TV1
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
State-threads-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/state-threads-devel

--RnlQjJ0d97Da+TV1--