Add libdtrace support for arm64 USDT probes.
arm64 is still lacking a fasttrap implementation, which is required to actually enable userland probes, but this at least allows USDT probes to be linked into userland applications. Submitted by: Klaus Küchemann <maciphone2@googlemail.com> (original) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D22360
This commit is contained in:
parent
78347412c0
commit
a2ea78495a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=356187
@ -229,9 +229,10 @@ prepare_elf32(dtrace_hdl_t *dtp, const dof_hdr_t *dof, dof_elf32_t *dep)
|
|||||||
|
|
||||||
for (j = 0; j < nrel; j++) {
|
for (j = 0; j < nrel; j++) {
|
||||||
#if defined(__aarch64__)
|
#if defined(__aarch64__)
|
||||||
/* XXX */
|
rel->r_offset = s->dofs_offset +
|
||||||
printf("%s:%s(%d): aarch64 not implemented\n",
|
dofr[j].dofr_offset;
|
||||||
__FUNCTION__, __FILE__, __LINE__);
|
rel->r_info = ELF32_R_INFO(count + dep->de_global,
|
||||||
|
R_ARM_REL32);
|
||||||
#elif defined(__arm__)
|
#elif defined(__arm__)
|
||||||
/* XXX */
|
/* XXX */
|
||||||
printf("%s:%s(%d): arm not implemented\n",
|
printf("%s:%s(%d): arm not implemented\n",
|
||||||
@ -425,7 +426,10 @@ prepare_elf64(dtrace_hdl_t *dtp, const dof_hdr_t *dof, dof_elf64_t *dep)
|
|||||||
|
|
||||||
for (j = 0; j < nrel; j++) {
|
for (j = 0; j < nrel; j++) {
|
||||||
#if defined(__aarch64__)
|
#if defined(__aarch64__)
|
||||||
/* XXX */
|
rel->r_offset = s->dofs_offset +
|
||||||
|
dofr[j].dofr_offset;
|
||||||
|
rel->r_info = ELF64_R_INFO(count + dep->de_global,
|
||||||
|
R_AARCH64_PREL64);
|
||||||
#elif defined(__arm__)
|
#elif defined(__arm__)
|
||||||
/* XXX */
|
/* XXX */
|
||||||
#elif defined(__mips__)
|
#elif defined(__mips__)
|
||||||
@ -541,6 +545,8 @@ dump_elf32(dtrace_hdl_t *dtp, const dof_hdr_t *dof, int fd)
|
|||||||
elf_file.ehdr.e_machine = EM_SPARC;
|
elf_file.ehdr.e_machine = EM_SPARC;
|
||||||
#elif defined(__i386) || defined(__amd64)
|
#elif defined(__i386) || defined(__amd64)
|
||||||
elf_file.ehdr.e_machine = EM_386;
|
elf_file.ehdr.e_machine = EM_386;
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
elf_file.ehdr.e_machine = EM_AARCH64;
|
||||||
#endif
|
#endif
|
||||||
elf_file.ehdr.e_version = EV_CURRENT;
|
elf_file.ehdr.e_version = EV_CURRENT;
|
||||||
elf_file.ehdr.e_shoff = sizeof (Elf32_Ehdr);
|
elf_file.ehdr.e_shoff = sizeof (Elf32_Ehdr);
|
||||||
@ -687,6 +693,8 @@ dump_elf64(dtrace_hdl_t *dtp, const dof_hdr_t *dof, int fd)
|
|||||||
elf_file.ehdr.e_machine = EM_SPARCV9;
|
elf_file.ehdr.e_machine = EM_SPARCV9;
|
||||||
#elif defined(__i386) || defined(__amd64)
|
#elif defined(__i386) || defined(__amd64)
|
||||||
elf_file.ehdr.e_machine = EM_AMD64;
|
elf_file.ehdr.e_machine = EM_AMD64;
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
elf_file.ehdr.e_machine = EM_AARCH64;
|
||||||
#endif
|
#endif
|
||||||
elf_file.ehdr.e_version = EV_CURRENT;
|
elf_file.ehdr.e_version = EV_CURRENT;
|
||||||
elf_file.ehdr.e_shoff = sizeof (Elf64_Ehdr);
|
elf_file.ehdr.e_shoff = sizeof (Elf64_Ehdr);
|
||||||
@ -802,14 +810,66 @@ dt_symtab_lookup(Elf_Data *data_sym, int start, int end, uintptr_t addr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__aarch64__)
|
#if defined(__aarch64__)
|
||||||
/* XXX */
|
#define DT_OP_NOP 0xd503201f
|
||||||
|
#define DT_OP_RET 0xd65f03c0
|
||||||
|
#define DT_OP_CALL26 0x94000000
|
||||||
|
#define DT_OP_JUMP26 0x14000000
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dt_modtext(dtrace_hdl_t *dtp, char *p, int isenabled, GElf_Rela *rela,
|
dt_modtext(dtrace_hdl_t *dtp, char *p, int isenabled, GElf_Rela *rela,
|
||||||
uint32_t *off)
|
uint32_t *off)
|
||||||
{
|
{
|
||||||
printf("%s:%s(%d): aarch64 not implemented\n", __FUNCTION__, __FILE__,
|
uint32_t *ip;
|
||||||
__LINE__);
|
|
||||||
return (-1);
|
/*
|
||||||
|
* Ensure that the offset is aligned on an instruction boundary.
|
||||||
|
*/
|
||||||
|
if ((rela->r_offset & (sizeof (uint32_t) - 1)) != 0)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We only know about some specific relocation types.
|
||||||
|
* We also recognize relocation type NONE, since that gets used for
|
||||||
|
* relocations of USDT probes, and we might be re-processing a file.
|
||||||
|
*/
|
||||||
|
if (GELF_R_TYPE(rela->r_info) != R_AARCH64_CALL26 &&
|
||||||
|
GELF_R_TYPE(rela->r_info) != R_AARCH64_JUMP26 &&
|
||||||
|
GELF_R_TYPE(rela->r_info) != R_AARCH64_NONE)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
ip = (uint32_t *)(p + rela->r_offset);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We may have already processed this object file in an earlier linker
|
||||||
|
* invocation. Check to see if the present instruction sequence matches
|
||||||
|
* the one we would install below.
|
||||||
|
*/
|
||||||
|
if (ip[0] == DT_OP_NOP || ip[0] == DT_OP_RET)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We only expect call instructions with a displacement of 0, or a jump
|
||||||
|
* instruction acting as a tail call.
|
||||||
|
*/
|
||||||
|
if (ip[0] != DT_OP_CALL26 && ip[0] != DT_OP_JUMP26) {
|
||||||
|
dt_dprintf("found %x instead of a call or jmp instruction at "
|
||||||
|
"%llx\n", ip[0], (u_longlong_t)rela->r_offset);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* On arm64, we do not have to differentiate between regular probes and
|
||||||
|
* is-enabled probes. Both cases are encoded as a regular branch for
|
||||||
|
* non-tail call locations, and a jump for tail call locations. Calls
|
||||||
|
* are to be converted into a no-op whereas jumps should become a
|
||||||
|
* return.
|
||||||
|
*/
|
||||||
|
if (ip[0] == DT_OP_CALL26)
|
||||||
|
ip[0] = DT_OP_NOP;
|
||||||
|
else
|
||||||
|
ip[0] = DT_OP_RET;
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
#elif defined(__arm__)
|
#elif defined(__arm__)
|
||||||
/* XXX */
|
/* XXX */
|
||||||
@ -1254,6 +1314,8 @@ process_obj(dtrace_hdl_t *dtp, const char *obj, int *eprobesp)
|
|||||||
emachine1 = emachine2 = EM_SPARCV9;
|
emachine1 = emachine2 = EM_SPARCV9;
|
||||||
#elif defined(__i386) || defined(__amd64)
|
#elif defined(__i386) || defined(__amd64)
|
||||||
emachine1 = emachine2 = EM_AMD64;
|
emachine1 = emachine2 = EM_AMD64;
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
emachine1 = emachine2 = EM_AARCH64;
|
||||||
#endif
|
#endif
|
||||||
symsize = sizeof (Elf64_Sym);
|
symsize = sizeof (Elf64_Sym);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user