From patchwork Wed Jun 4 15:30:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omair Javaid X-Patchwork-Id: 31368 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 58203208CF for ; Wed, 4 Jun 2014 15:31:32 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rd18sf43384793iec.4 for ; Wed, 04 Jun 2014 08:31:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:mailing-list :precedence:list-id:list-unsubscribe:list-subscribe:list-archive :list-post:list-help:sender:delivered-to:from:to:cc:subject:date :message-id:x-original-sender:x-original-authentication-results; bh=ExSf4NhmzPHFrkjZ7bkLAWHrw2t07ahOxrgQFBb+67s=; b=NGAecpTJ+BW6Sda6MRe/EO1v5bZ2ucY94EIqYaKbnl9bcOWUihHs6aWMo7QztQbOmP fss1EEwgJuee1JbQHshYCnN5MDqU5L3/O5tKHn7vRAUWTPE8iwTxr8iXN+aIfM6ign5S 6wC6M1zLUFjqOGDkqgkRXHo0kSppvRVcptNM0qSMevgL2vbUVNcmvLXPsajlIJ5dQ4mY LloITphczbSdGALVoA4usjSaq+KKZ0EEFpWEweyZXhFmTwJzI9j0ZyJESgnDAs6mF6KR uqMNZQUVAY/GrckB8cLXTLLNYH39eVMq+x+EUEHgapnQH/i3hCo4TWaWRJsAZGY1B4cC 5ebw== X-Gm-Message-State: ALoCoQkbQPI0pbPDJaubGCR3dHAvIYwV/GWfSOYJvhuWnJw0JKnQLg49O1hsepHgQxthBdSveY5X X-Received: by 10.50.239.196 with SMTP id vu4mr2369653igc.8.1401895891764; Wed, 04 Jun 2014 08:31:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.86.100 with SMTP id o91ls3184504qgd.30.gmail; Wed, 04 Jun 2014 08:31:31 -0700 (PDT) X-Received: by 10.58.22.164 with SMTP id e4mr2489076vef.71.1401895891541; Wed, 04 Jun 2014 08:31:31 -0700 (PDT) Received: from mail-vc0-x234.google.com (mail-vc0-x234.google.com [2607:f8b0:400c:c03::234]) by mx.google.com with ESMTPS id ht8si1884610vdb.61.2014.06.04.08.31.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 04 Jun 2014 08:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::234 as permitted sender) client-ip=2607:f8b0:400c:c03::234; Received: by mail-vc0-f180.google.com with SMTP id hq11so6868339vcb.11 for ; Wed, 04 Jun 2014 08:31:31 -0700 (PDT) X-Received: by 10.220.53.72 with SMTP id l8mr44770903vcg.16.1401895891458; Wed, 04 Jun 2014 08:31:31 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.54.6 with SMTP id vs6csp54139vcb; Wed, 4 Jun 2014 08:31:30 -0700 (PDT) X-Received: by 10.15.49.137 with SMTP id j9mr2336735eew.26.1401895890340; Wed, 04 Jun 2014 08:31:30 -0700 (PDT) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id em4si6478821pbc.141.2014.06.04.08.31.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jun 2014 08:31:30 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-return-83937-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 16802 invoked by alias); 4 Jun 2014 15:31:13 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list List-Id: List-Unsubscribe: , List-Subscribe: List-Archive: List-Post: , List-Help: , Sender: binutils-owner@sourceware.org Delivered-To: mailing list binutils@sourceware.org Received: (qmail 16789 invoked by uid 89); 4 Jun 2014 15:31:11 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_WEB, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f50.google.com Received: from mail-wg0-f50.google.com (HELO mail-wg0-f50.google.com) (74.125.82.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 04 Jun 2014 15:31:00 +0000 Received: by mail-wg0-f50.google.com with SMTP id x12so8778554wgg.9 for ; Wed, 04 Jun 2014 08:30:57 -0700 (PDT) X-Received: by 10.194.89.168 with SMTP id bp8mr6024424wjb.73.1401895857336; Wed, 04 Jun 2014 08:30:57 -0700 (PDT) Received: from localhost.localdomain ([182.178.209.38]) by mx.google.com with ESMTPSA id um7sm2513945wjc.12.2014.06.04.08.30.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Jun 2014 08:30:56 -0700 (PDT) From: Omair Javaid To: binutils@sourceware.org Cc: Omair Javaid Subject: [PATCH v2] Fix core file support on aarch64 targets Date: Wed, 4 Jun 2014 20:30:41 +0500 Message-Id: <1401895841-22708-1-git-send-email-omair.javaid@linaro.org> X-Original-Sender: omair.javaid@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::234 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@sourceware.org X-Google-Group-Id: 836684582541 This patch fixes core file support on aarch64 targets. It updates grok_prstatus method and adds the grok_psinfo and write_core_note methods for the aarch64 targets. This patch is tested on aarch64*-linux* target. 2014-06-04 Omair Javaid bfd/ * elfxx-aarch64.c (stdarg.h): Include. (string.h): Include. (_bfd_aarch64_elf_grok_prstatus): Updated. (_bfd_aarch64_elf_grok_psinfo): New function. (_bfd_aarch64_elf_write_core_note): New function. * elfxx-aarch64.h (elf_backend_grok_psinfo): Define. (elf_backend_write_core_note): Define. --- bfd/elfxx-aarch64.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ bfd/elfxx-aarch64.h | 7 +++++ 2 files changed, 84 insertions(+) diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c index 7db6295..96cff52 100644 --- a/bfd/elfxx-aarch64.c +++ b/bfd/elfxx-aarch64.c @@ -20,6 +20,8 @@ #include "sysdep.h" #include "elfxx-aarch64.h" +#include +#include #define MASK(n) ((1u << (n)) - 1) @@ -520,3 +522,78 @@ _bfd_aarch64_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) return _bfd_elfcore_make_pseudosection (abfd, ".reg", size, note->descpos + offset); } + +bfd_boolean +_bfd_aarch64_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) +{ + switch (note->descsz) + { + default: + return FALSE; + + case 136: /* sizeof(struct elf_prpsinfo) on Linux/aarch64 */ + elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24); + elf_tdata (abfd)->core->program + = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); + elf_tdata (abfd)->core->command + = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); + } + + /* Note that for some reason, a spurious space is tacked + onto the end of the args in some (at least one anyway) + implementations, so strip it off if it exists. */ + + { + char *command = elf_tdata (abfd)->core->command; + int n = strlen (command); + + if (0 < n && command[n - 1] == ' ') + command[n - 1] = '\0'; + } + + return TRUE; +} + +char * +_bfd_aarch64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, + ...) +{ + switch (note_type) + { + default: + return NULL; + + case NT_PRPSINFO: + { + char data[136]; + va_list ap; + va_start (ap, note_type); + memset (data, 0, sizeof (data)); + strncpy (data + 40, va_arg (ap, const char *), 16); + strncpy (data + 56, va_arg (ap, const char *), 80); + va_end (ap); + return elfcore_write_note (abfd, buf, bufsiz, + "CORE", note_type, data, sizeof (data)); + } + + case NT_PRSTATUS: + { + char data[392]; + va_list ap; + long pid; + int cursig; + const void *greg; + va_start (ap, note_type); + memset (data, 0, sizeof (data)); + pid = va_arg (ap, long); + bfd_put_32 (abfd, pid, data + 32); + cursig = va_arg (ap, int); + bfd_put_16 (abfd, cursig, data + 12); + greg = va_arg (ap, const void *); + memcpy (data + 112, greg, 272); + va_end (ap); + return elfcore_write_note (abfd, buf, bufsiz, + "CORE", note_type, data, sizeof (data)); + } + } +} diff --git a/bfd/elfxx-aarch64.h b/bfd/elfxx-aarch64.h index 5ca3b7f..c21bf06 100644 --- a/bfd/elfxx-aarch64.h +++ b/bfd/elfxx-aarch64.h @@ -42,6 +42,13 @@ _bfd_aarch64_elf_add_symbol_hook (bfd *, struct bfd_link_info *, extern bfd_boolean _bfd_aarch64_elf_grok_prstatus (bfd *, Elf_Internal_Note *); +extern bfd_boolean +_bfd_aarch64_elf_grok_psinfo (bfd *, Elf_Internal_Note *); +extern char * +_bfd_aarch64_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, + int note_type, ...); #define elf_backend_add_symbol_hook _bfd_aarch64_elf_add_symbol_hook #define elf_backend_grok_prstatus _bfd_aarch64_elf_grok_prstatus +#define elf_backend_grok_psinfo _bfd_aarch64_elf_grok_psinfo +#define elf_backend_write_core_note _bfd_aarch64_elf_write_core_note