From owner-svn-src-all@FreeBSD.ORG Mon Jun 22 19:43:09 2015 Return-Path: Delivered-To: svn-src-all@nevdull.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7FDCE2F2; Mon, 22 Jun 2015 19:43:09 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 53D3BA7C; Mon, 22 Jun 2015 19:43:09 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t5MJh9h3064088; Mon, 22 Jun 2015 19:43:09 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t5MJh8ZY064085; Mon, 22 Jun 2015 19:43:08 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201506221943.t5MJh8ZY064085@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Mon, 22 Jun 2015 19:43:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284707 - in head: lib/csu/aarch64 libexec/rtld-elf/aarch64 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Jun 2015 19:43:09 -0000 Author: andrew Date: Mon Jun 22 19:43:08 2015 New Revision: 284707 URL: https://svnweb.freebsd.org/changeset/base/284707 Log: Add a workaround to correctly align the stack before calling into C code. When enough time has passed for users to update their userland the kernel fix will be applied. This will change the ABI to have x0 point to the args and sp be correctly aligned. It is expected this compatibility code can be removed when the kernel and qemu usermode emulation have both been updated for the new ABI. This fixes clang failures, and most likely other crashes. Obtained from: ABT Systems Ltd Sponsored by: The FreeBSD Foundation Modified: head/lib/csu/aarch64/crt1.c head/libexec/rtld-elf/aarch64/rtld_start.S Modified: head/lib/csu/aarch64/crt1.c ============================================================================== --- head/lib/csu/aarch64/crt1.c Mon Jun 22 19:37:04 2015 (r284706) +++ head/lib/csu/aarch64/crt1.c Mon Jun 22 19:43:08 2015 (r284707) @@ -58,9 +58,13 @@ __asm(" .text \n" " .align 0 \n" " .globl _start \n" " _start: \n" -" mov x3, x2 \n" /* cleanup */ -" ldr x0, [sp] \n" /* Load argc */ -" add x1, sp, #8 \n" /* load argv */ +/* TODO: Remove this when the kernel correctly aligns the stack */ +" cbnz x0, 1f \n" /* Are we using a new kernel? */ +" mov x0, sp \n" /* No, load the args from sp */ +" and sp, x0, #~0xf \n" /* And align the stack */ +"1: mov x3, x2 \n" /* cleanup */ +" add x1, x0, #8 \n" /* load argv */ +" ldr x0, [x0] \n" /* load argc */ " add x2, x1, x0, lsl #3 \n" /* env is after argv */ " add x2, x2, #8 \n" /* argv is null terminated */ " b __start "); Modified: head/libexec/rtld-elf/aarch64/rtld_start.S ============================================================================== --- head/libexec/rtld-elf/aarch64/rtld_start.S Mon Jun 22 19:37:04 2015 (r284706) +++ head/libexec/rtld-elf/aarch64/rtld_start.S Mon Jun 22 19:43:08 2015 (r284707) @@ -34,10 +34,14 @@ ENTRY(.rtld_start) mov x19, x0 /* Put ps_strings in a callee-saved register */ mov x20, sp /* And the stack pointer */ - sub x8, x20, #16 /* Make room for obj_main & exit proc */ - mov sp, x8 /* Update the stack pointer */ + /* Handle the old style stack */ + /* TODO: Remove this when the kernel correctly aligns the stack */ + cbnz x0, 1f + mov x0, sp /* sp points to the args */ + and sp, x0, #~0xf /* Align the stack as needed */ + +1: sub sp, sp, #16 /* Make room for obj_main & exit proc */ - mov x0, x20 /* Pass the stack we were given to _rtld */ mov x1, sp /* exit_proc */ add x2, x1, #8 /* obj_main */ bl _rtld /* Call the loader */