From patchwork Mon Jul 4 17:38:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keno Fischer X-Patchwork-Id: 644306 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rjvRG2Kplz9s5M for ; Tue, 5 Jul 2016 03:39:54 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=mANbgpXP; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; q=dns; s=default; b=jxEacOpZyR8x+qFxAX+QLKcMSNPN6 7jENDLEe0lX72cmeI/s5VQHGq9Ljs/vuTe6BbTN0/OxDKey4Qbj+BInSrbN00skF Oe2Y8DCzMpUy1s3QXu6ixi5x4h/GzCWKf3ZQVcuavMX5L/IGdMaGL7/i2MSzXkba esQHZa6foEYEvQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:from:date:message-id:subject:to :content-type; s=default; bh=0BNhIBZIOD8oGxAfP7lw45G0Ut0=; b=mAN bgpXPeKunUc+q6jxvV/6eXTXt+ySYNSKtOez80F8dYMBp1M7F9aIadAr3k8qWs8g kJL3TG3HC1zeVH/YrRk0fjtKDzunSwYIC1mckrMM+cEGUV320ZxauIKydmwGqDhB MZUntjf7TZAmKxygnxzfJI2adpYnk6Xmpwt0cIBA= Received: (qmail 78358 invoked by alias); 4 Jul 2016 17:39:48 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 78345 invoked by uid 89); 4 Jul 2016 17:39:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mail-vk0-f54.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=IRjiwM8bTgopMwYh9k+YB7Ursi8GTUeGayMscLPZFNc=; b=nJ36+w9Xnxa4yBM+qhpGR4fWMpimu2d9QkSEsEtIsCRAEmAFLJMxTpRo3WxCmaO5Zg juapFaBNcWyhiksodz4YtaqGhyGrkcwKdZ5ZDAgjtk7yOmNYdjaQYIzIw0wDVinTaAcX MIA0K+EMGugLbXncAzAur0BkD0QPt7eHiPA/0Pzt8upUemcu98pEX8G6t5+ib56Fq+22 K4Wu4PpFdDluFby1hrF4Y6EGJ1g/JFkqk00joP44yeLqcWFm3soGrkmA+OjOHnPHFf4M ZeptvgBhKME9EsB3YQmGN3tyD1Scw0rHmNIPOWhZUv5eOEATGtVOBBWA3nYFhwyU0hj0 uHXQ== X-Gm-Message-State: ALyK8tJdqntAjL6QeyKdD9fvBCDh5/z8hQXefCNqptTlA3ESCcw4sNUSewO1Len8FMRO1JzAbPo2v1hlPnDcJ3Vf X-Received: by 10.159.33.248 with SMTP id 111mr3540806uac.99.1467653970715; Mon, 04 Jul 2016 10:39:30 -0700 (PDT) MIME-Version: 1.0 From: Keno Fischer Date: Mon, 4 Jul 2016 13:38:51 -0400 Message-ID: Subject: [PATCH] Add CFI to x86_64 RTLD_START To: libc-alpha@sourceware.org The application's entry point already has the appropriate CFI to indicate to tools that the end of the stack has been reached. This CFI was lacking from the dynamic linker, causing garbled backtraces after hitting _dl_start. Fix this by adding the appropriate CFI. Example gdb output before: ``` (gdb) bt #0 0x00007f10a2cee2d0 in _start () from /lib64/ld-linux-x86-64.so.2 #1 0x0000000000000003 in ?? () #2 0x00007ffd2ba54ce9 in ?? () #3 0x00007ffd2ba54d04 in ?? () #4 0x00007ffd2ba54d07 in ?? () #5 0x0000000000000000 in ?? () ``` after: ``` (gdb) bt #0 0x00007f36273551b0 in _start () from /home/kfischer/replacement-usr/lib/ld-2.23.90.so ``` This is likely applicable to other architectures as well, but I only have access to x86_64, so this patch is limited to that architecture. --- sysdeps/x86_64/dl-machine.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) # See if we were run as a command with the executable file\n\ @@ -180,7 +185,8 @@ _dl_start_user:\n\ # And make sure %rsp points to argc stored on the stack.\n\ movq %r13, %rsp\n\ # Jump to the user's entry point.\n\ - jmp *%r12\n\ + jmp *%r12\n"\ +CFI_ENDPROC "\n\ .previous\n\ "); diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h index ed0c1a8..7a246d4 100644 --- a/sysdeps/x86_64/dl-machine.h +++ b/sysdeps/x86_64/dl-machine.h @@ -141,10 +141,15 @@ elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) .align 16\n\ .globl _start\n\ .globl _dl_start_user\n\ -_start:\n\ +_start:\n"\ +CFI_STARTPROC "\n"\ +CFI_UNDEFINED(%rip) "\n\ movq %rsp, %rdi\n\ - call _dl_start\n\ -_dl_start_user:\n\ + call _dl_start\n"\ +CFI_ENDPROC "\n\ +_dl_start_user:\n"\ +CFI_STARTPROC "\n"\ +CFI_UNDEFINED(%rip) "\n\ # Save the user entry point address in %r12.\n\ movq %rax, %r12\n\