Port a couple more patches from upstream

This commit is contained in:
Petr Machata 2014-01-14 16:16:17 +01:00
parent cc2bc6c506
commit 3eda79ec21
4 changed files with 315 additions and 4 deletions

View File

@ -0,0 +1,69 @@
@@ -, +, @@
exe->mount("source", "target", "filesystemtype", 0, nil <unfinished ...>
mount@SYS("", "target", "filesystemtype", 0, nil) = -2
<... mount resumed> = -1
---
sysdeps/linux-gnu/s390/fetch.c | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
--- a/sysdeps/linux-gnu/s390/fetch.c
+++ a/sysdeps/linux-gnu/s390/fetch.c
@@ -23,6 +23,7 @@
#include <sys/ucontext.h>
#include <assert.h>
#include <errno.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -61,7 +62,8 @@ s390x(struct fetch_context *ctx)
}
static int
-fetch_register_banks(struct process *proc, struct fetch_context *ctx)
+fetch_register_banks(struct process *proc, struct fetch_context *ctx,
+ bool syscall_enter)
{
ptrace_area parea;
parea.len = sizeof(ctx->regs);
@@ -72,15 +74,20 @@ fetch_register_banks(struct process *proc, struct fetch_context *ctx)
strerror(errno));
return -1;
}
+
+ if (syscall_enter)
+ ctx->regs.gprs[2] = ctx->regs.orig_gpr2;
+
return 0;
}
static int
-fetch_context_init(struct process *proc, struct fetch_context *context)
+fetch_context_init(struct process *proc, struct fetch_context *context,
+ bool syscall_enter)
{
context->greg = 2;
context->freg = 0;
- return fetch_register_banks(proc, context);
+ return fetch_register_banks(proc, context, syscall_enter);
}
struct fetch_context *
@@ -89,7 +96,7 @@ arch_fetch_arg_init(enum tof type, struct process *proc,
{
struct fetch_context *context = malloc(sizeof(*context));
if (context == NULL
- || fetch_context_init(proc, context) < 0) {
+ || fetch_context_init(proc, context, type == LT_TOF_SYSCALL) < 0) {
fprintf(stderr, "arch_fetch_arg_init: %s\n",
strerror(errno));
free(context);
@@ -277,7 +284,7 @@ arch_fetch_retval(struct fetch_context *ctx, enum tof type,
return 0;
}
- if (fetch_context_init(proc, ctx) < 0)
+ if (fetch_context_init(proc, ctx, false) < 0)
return -1;
return arch_fetch_arg_next(ctx, type, proc, info, valuep);
}
--

View File

@ -0,0 +1,67 @@
@@ -, +, @@
---
sysdeps/linux-gnu/s390/arch.h | 2 ++
sysdeps/linux-gnu/s390/plt.c | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+)
--- a/sysdeps/linux-gnu/s390/arch.h
+++ a/sysdeps/linux-gnu/s390/arch.h
@@ -1,5 +1,6 @@
/*
* This file is part of ltrace.
+ * Copyright (C) 2013 Petr Machata, Red Hat Inc.
* Copyright (C) 2001 IBM Poughkeepsie, IBM Corporation
*
* This program is free software; you can redistribute it and/or
@@ -25,6 +26,7 @@
#define ARCH_HAVE_FETCH_ARG
#define ARCH_HAVE_SIZEOF
#define ARCH_HAVE_ALIGNOF
+#define ARCH_HAVE_ADD_PLT_ENTRY
#define LT_ELFCLASS ELFCLASS32
#define LT_ELF_MACHINE EM_S390
--- a/sysdeps/linux-gnu/s390/plt.c
+++ a/sysdeps/linux-gnu/s390/plt.c
@@ -1,5 +1,6 @@
/*
* This file is part of ltrace.
+ * Copyright (C) 2013 Petr Machata, Red Hat Inc.
* Copyright (C) 2004,2008,2009 Juan Cespedes
*
* This program is free software; you can redistribute it and/or
@@ -19,9 +20,12 @@
*/
#include <gelf.h>
+#include <stdbool.h>
+
#include "proc.h"
#include "common.h"
#include "library.h"
+#include "trace.h"
GElf_Addr
arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) {
@@ -33,3 +37,21 @@ sym2addr(struct process *proc, struct library_symbol *sym)
{
return sym->enter_addr;
}
+
+enum plt_status
+arch_elf_add_plt_entry(struct process *proc, struct ltelf *lte,
+ const char *a_name, GElf_Rela *rela, size_t ndx,
+ struct library_symbol **ret)
+{
+#ifdef R_390_IRELATIVE
+ bool irelative = GELF_R_TYPE(rela->r_info) == R_390_IRELATIVE;
+#else
+ bool irelative = false;
+#endif
+
+ if (irelative)
+ return linux_elf_add_plt_entry_irelative(proc, lte, rela,
+ ndx, ret);
+
+ return PLT_DEFAULT;
+}
--

View File

@ -0,0 +1,156 @@
@@ -, +, @@
relocation
- In general they are. But IRELATIVE relocations are sorted to come
last, and PLT entries are not sorted accordingly.
---
sysdeps/linux-gnu/x86/arch.h | 11 +++++
sysdeps/linux-gnu/x86/plt.c | 101 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 111 insertions(+), 1 deletions(-)
--- a/sysdeps/linux-gnu/x86/arch.h
+++ a/sysdeps/linux-gnu/x86/arch.h
@@ -19,6 +19,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
+#ifndef LTRACE_X86_ARCH_H
+#define LTRACE_X86_ARCH_H
+
+#include "vect.h"
#define BREAKPOINT_VALUE {0xcc}
#define BREAKPOINT_LENGTH 1
@@ -30,9 +34,16 @@
#define ARCH_HAVE_ADD_PLT_ENTRY
+#define ARCH_HAVE_LTELF_DATA
+struct arch_ltelf_data {
+ struct vect plt_map;
+};
+
#ifdef __x86_64__
#define LT_ELFCLASS ELFCLASS64
#define LT_ELF_MACHINE EM_X86_64
#endif
#define LT_ELFCLASS2 ELFCLASS32
#define LT_ELF_MACHINE2 EM_386
+
+#endif /* LTRACE_X86_ARCH_H */
--- a/sysdeps/linux-gnu/x86/plt.c
+++ a/sysdeps/linux-gnu/x86/plt.c
@@ -27,10 +27,19 @@
#include "library.h"
#include "trace.h"
+static GElf_Addr
+x86_plt_offset(uint32_t i)
+{
+ /* Skip the first PLT entry, which contains a stub to call the
+ * resolver. */
+ return (i + 1) * 16;
+}
+
GElf_Addr
arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela *rela)
{
- return lte->plt_addr + (ndx + 1) * 16;
+ uint32_t i = *VECT_ELEMENT(&lte->arch.plt_map, uint32_t, ndx);
+ return x86_plt_offset(i) + lte->plt_addr;
}
void *
@@ -62,3 +71,93 @@ arch_elf_add_plt_entry(struct process *proc, struct ltelf *lte,
return PLT_DEFAULT;
}
+
+int
+arch_elf_init(struct ltelf *lte, struct library *lib)
+{
+ VECT_INIT(&lte->arch.plt_map, unsigned int);
+
+ /* IRELATIVE slots may make the whole situation a fair deal
+ * more complex. On x86{,_64}, the PLT slots are not
+ * presented in the order of the corresponding relocations,
+ * but in the order it which these symbols are in the symbol
+ * table. That's static symbol table, which may be stripped
+ * off, not dynsym--that doesn't contain IFUNC symbols at all.
+ * So we have to decode each PLT entry to figure out what
+ * entry it corresponds to. We need to interpret the PLT
+ * table to figure this out.
+ *
+ * On i386, the PLT entry format is as follows:
+ *
+ * 8048300: ff 25 0c a0 04 08 jmp *0x804a00c
+ * 8048306: 68 20 00 00 00 push $0x20
+ * 804830b: e9 e0 ff ff ff jmp 80482f0 <_init+0x30>
+ *
+ * For PIE binaries it is the following:
+ *
+ * 410: ff a3 10 00 00 00 jmp *0x10(%ebx)
+ * 416: 68 00 00 00 00 push $0x0
+ * 41b: e9 d0 ff ff ff jmp 3f0 <_init+0x30>
+ *
+ * On x86_64, it is:
+ *
+ * 400420: ff 25 f2 0b 20 00 jmpq *0x200bf2(%rip) # 601018 <_GLOBAL_OFFSET_TABLE_+0x18>
+ * 400426: 68 00 00 00 00 pushq $0x0
+ * 40042b: e9 e0 ff ff ff jmpq 400410 <_init+0x18>
+ *
+ * On i386, the argument to push is an offset of relocation to
+ * use. The first PLT slot has an offset of 0x0, the second
+ * 0x8, etc. On x86_64, it's directly the index that we are
+ * looking for.
+ */
+
+ /* Here we scan the PLT table and initialize a map of
+ * relocation->slot number in lte->arch.plt_map. */
+
+ size_t i;
+ for (i = 0; i < vect_size(&lte->plt_relocs); ++i) {
+
+ GElf_Addr offset = x86_plt_offset(i);
+ uint32_t reloc_arg = 0;
+
+ uint8_t byte;
+ if (elf_read_next_u8(lte->plt_data, &offset, &byte) < 0
+ || byte != 0xff
+ || elf_read_next_u8(lte->plt_data, &offset, &byte) < 0
+ || (byte != 0xa3 && byte != 0x25))
+ goto next;
+
+ /* Skip immediate argument in the instruction. */
+ offset += 4;
+
+ if (elf_read_next_u8(lte->plt_data, &offset, &byte) < 0
+ || byte != 0x68
+ || elf_read_next_u32(lte->plt_data,
+ &offset, &reloc_arg) < 0) {
+ reloc_arg = 0;
+ goto next;
+ }
+
+ if (lte->ehdr.e_machine == EM_386) {
+ if (reloc_arg % 8 != 0) {
+ reloc_arg = 0;
+ goto next;
+ }
+ reloc_arg /= 8;
+ }
+
+ next:
+ if (VECT_PUSHBACK(&lte->arch.plt_map, &reloc_arg) < 0) {
+ arch_elf_destroy(lte);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+void
+arch_elf_destroy(struct ltelf *lte)
+{
+ VECT_DESTROY(&lte->arch.plt_map, uint32_t, NULL, NULL);
+}
--

View File

@ -21,17 +21,27 @@ Patch0: ltrace-0.7.91-arm.patch
# others in -c output.
Patch1: ltrace-0.7.91-account_execl.patch
# Upstream patch that fixes interpretation of PLT on x86_64 when
# IRELATIVE slots are present.
Patch2: ltrace-0.7.91-x86_64-irelative.patch
# Upstream patch that fixes fetching of system call arguments on s390.
Patch3: ltrace-0.7.91-s390-fetch-syscall.patch
# Upstream patch that enables tracing of IRELATIVE PLT slots on s390.
Patch4: ltrace-0.7.91-s390-irelative.patch
# Fix for a regression in tracing across fork. Upstream patch.
Patch2: ltrace-0.7.91-ppc64-fork.patch
Patch5: ltrace-0.7.91-ppc64-fork.patch
# Fix crashing a prelinked PPC64 binary which makes PLT calls through
# slots that ltrace doesn't trace.
# https://bugzilla.redhat.com/show_bug.cgi?id=1051221
Patch3: ltrace-0.7.91-breakpoint-on_install.patch
Patch4: ltrace-0.7.91-ppc64-unprelink.patch
Patch6: ltrace-0.7.91-breakpoint-on_install.patch
Patch7: ltrace-0.7.91-ppc64-unprelink.patch
# Man page nits. Backport of an upstream patch.
Patch5: ltrace-0.7.91-man.patch
Patch8: ltrace-0.7.91-man.patch
%description
Ltrace is a debugging program which runs a specified command until the
@ -51,6 +61,9 @@ execution of processes.
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%build
%configure --docdir=%{?_pkgdocdir}%{!?_pkgdocdir:%{_docdir}/%{name}-%{version}}
@ -76,6 +89,12 @@ echo ====================TESTING END=====================
%changelog
* Tue Jan 14 2014 Petr Machata <pmachata@redhat.com> - 0.7.91-5
- Fix interpretation of x86_64 PLT with IRELATIVE slots.
(ltrace-0.7.91-x86_64-irelative.patch)
- Fix fetching of system call arguments on s390.
(ltrace-0.7.91-s390-fetch-syscall.patch)
- Enable tracing of IRELATIVE PLT slots on s390.
(ltrace-0.7.91-s390-irelative.patch)
- Fix a couple nits in ltrace.1 (ltrace-0.7.91-man.patch)
* Fri Jan 10 2014 Petr Machata <pmachata@redhat.com> - 0.7.91-4