Skip to content

Commit

Permalink
Build against libctf (from binutils) if available
Browse files Browse the repository at this point in the history
CTF suypport can be provided by the libdtrace-ctf library (originally
part of the legacy DTrace implementation) or by the libctf that is
included in newer binutils versions.  The config detection mechanism
added to determine whether libctf is available provides a HAVE_LIBCTF
define to use in source code and also a HAVE_LIBCTF symbol that can be
tested for in makefiles.

This patch provides the changes in the DTrace v2 source tree to build
against libctf when it is available.  When it is not available, building
agaist libdtrace-ctf is attempted (and if that is not found a build
error will result).

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
kvanhees authored and nickalcock committed Apr 12, 2021
1 parent 002fc5b commit 188bf56
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 11 deletions.
8 changes: 8 additions & 0 deletions cmd/Build
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@ dtrace_DIR := $(current-dir)
dtrace_SOURCES = dtrace.c
dtrace_DEPS = libdtrace.so libport.a
dtrace_SRCDEPS := $(objdir)/dt_git_version.h
ifdef HAVE_LIBCTF
dtrace_LIBS = -ldtrace -lctf -lport -lelf
else
dtrace_LIBS = -ldtrace -ldtrace-ctf -lport -lelf
endif

ctf_module_dump_CPPFLAGS = -Ilibdtrace -Ilibproc -D_LONGLONG_TYPE
ctf_module_dump_TARGET = ctf_module_dump
ctf_module_dump_DIR := $(current-dir)
ctf_module_dump_SOURCES = ctf_module_dump.c
ctf_module_dump_DEPS = libdtrace.so libport.a
ifdef HAVE_LIBCTF
ctf_module_dump_LIBS = -ldtrace -lctf -lelf
else
ctf_module_dump_LIBS = -ldtrace -ldtrace-ctf -lelf
endif

$(objdir)/run-dtrace: $(DTRACE)
printf > $@ "\
Expand Down
20 changes: 20 additions & 0 deletions include/sys/ctf-api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#ifndef _DT_CTF_API_H
#define _DT_CTF_API_H

#include <config.h>

#ifdef HAVE_LIBCTF
# include <ctf-api.h>
# define ctf_close(fp) ctf_file_close(fp)
#else
# include <sys/ctf_api.h>
#endif

#endif /* _DT_CTF_API_H */
4 changes: 4 additions & 0 deletions libdtrace/Build
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ SHLIBS += libdtrace

libdtrace_DIR := $(current-dir)
libdtrace_TARGET = libdtrace
ifdef HAVE_LIBCTF
libdtrace_LIBS := -lctf -lelf -lz -lrt -lpcap -lpthread -ldl -lm
else
libdtrace_LIBS := -ldtrace-ctf -lelf -lz -lrt -lpcap -lpthread -ldl -lm
endif
libdtrace_VERSION := 1.0.0
libdtrace_SONAME := libdtrace.so.1
libdtrace_VERSCRIPT := $(libdtrace_DIR)libdtrace.ver
Expand Down
29 changes: 29 additions & 0 deletions libdtrace/dt_bpf_maps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/

#ifndef _DT_BPF_MAPS_H
#define _DT_BPF_MAPS_H

#ifdef FIXME
#ifdef __cplusplus
extern "C" {
#endif

typedef struct dt_bpf_probe dt_bpf_probe_t;
struct dt_bpf_probe {
uint_t prvv; /* probeprov string offset in strtab */
uint_t mod; /* probemod string offset in strtab */
uint_t fun; /* probefunc string offset in strtab */
uint_t prb; /* probename string offset in strtab */
};

#ifdef __cplusplus
}
#endif
#endif

#endif /* _DT_BPF_FUNCS_H */
2 changes: 1 addition & 1 deletion libdtrace/dt_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define _DT_DECL_H

#include <sys/types.h>
#include <sys/ctf_api.h>
#include <sys/ctf-api.h>
#include <dtrace.h>
#include <stdio.h>

Expand Down
2 changes: 1 addition & 1 deletion libdtrace/dt_ident.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef _DT_IDENT_H
#define _DT_IDENT_H

#include <sys/ctf_api.h>
#include <sys/ctf-api.h>
#include <dtrace.h>

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion libdtrace/dt_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <sys/param.h>
#include <setjmp.h>
#include <sys/ctf_api.h>
#include <sys/ctf-api.h>
#include <dtrace.h>
#include <pthread.h>

Expand Down
18 changes: 15 additions & 3 deletions libdtrace/dt_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,16 @@ dt_module_load_sect(dtrace_hdl_t *dtp, dt_module_t *dmp, ctf_sect_t *ctsp)
(s = elf_strptr(dmp->dm_elf, shstrs, sh.sh_name)) == NULL)
continue; /* skip any malformed sections */

#ifdef HAVE_LIBCTF
if (sh.sh_entsize == ctsp->cts_entsize &&
strcmp(s, ctsp->cts_name) == 0)
break; /* section matches specification */
#else
if (sh.sh_type == ctsp->cts_type &&
sh.sh_entsize == ctsp->cts_entsize &&
strcmp(s, ctsp->cts_name) == 0)
break; /* section matches specification */
#endif
}

/*
Expand Down Expand Up @@ -400,12 +406,14 @@ dt_module_load(dtrace_hdl_t *dtp, dt_module_t *dmp)
goto oom;
}

#ifndef HAVE_LIBCTF
dmp->dm_ctdata.cts_type = SHT_PROGBITS;
dmp->dm_ctdata.cts_flags = 0;
dmp->dm_ctdata.cts_offset = 0;
#endif
dmp->dm_ctdata.cts_data = NULL;
dmp->dm_ctdata.cts_size = 0;
dmp->dm_ctdata.cts_entsize = 0;
dmp->dm_ctdata.cts_offset = 0;

/*
* Attempt to load and uncompress the module's CTF section.
Expand Down Expand Up @@ -441,21 +449,25 @@ dt_module_load(dtrace_hdl_t *dtp, dt_module_t *dmp)
}

dmp->dm_symtab.cts_name = ".symtab";
#ifndef HAVE_LIBCTF
dmp->dm_symtab.cts_type = SHT_SYMTAB;
dmp->dm_symtab.cts_flags = 0;
dmp->dm_symtab.cts_offset = 0;
#endif
dmp->dm_symtab.cts_data = NULL;
dmp->dm_symtab.cts_size = 0;
dmp->dm_symtab.cts_entsize = dmp->dm_ops == &dt_modops_64 ?
sizeof (Elf64_Sym) : sizeof (Elf32_Sym);
dmp->dm_symtab.cts_offset = 0;

dmp->dm_strtab.cts_name = ".strtab";
#ifndef HAVE_LIBCTF
dmp->dm_strtab.cts_type = SHT_STRTAB;
dmp->dm_strtab.cts_flags = 0;
dmp->dm_strtab.cts_offset = 0;
#endif
dmp->dm_strtab.cts_data = NULL;
dmp->dm_strtab.cts_size = 0;
dmp->dm_strtab.cts_entsize = 0;
dmp->dm_strtab.cts_offset = 0;

/*
* Now load the module's symbol and string table sections.
Expand Down
2 changes: 1 addition & 1 deletion libdtrace/dt_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <sys/types.h>
#include <sys/dtrace.h>
#include <sys/compiler.h>
#include <sys/ctf_api.h>
#include <sys/ctf-api.h>

#include <stdarg.h>
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion libdtrace/dt_printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define _DT_PRINTF_H

#include <sys/types.h>
#include <sys/ctf_api.h>
#include <sys/ctf-api.h>
#include <dtrace.h>
#include <stdio.h>

Expand Down
2 changes: 1 addition & 1 deletion libdtrace/dt_xlator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef _DT_XLATOR_H
#define _DT_XLATOR_H

#include <sys/ctf_api.h>
#include <sys/ctf-api.h>
#include <dtrace.h>
#include <dt_ident.h>
#include <dt_list.h>
Expand Down
2 changes: 1 addition & 1 deletion libdtrace/dtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <gelf.h>
#include <sys/ctf_api.h>
#include <sys/ctf-api.h>

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion libproc/libproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <sys/statvfs.h>
#include <sys/wait.h>
#include <rtld_db.h>
#include <sys/ctf_api.h>
#include <sys/ctf-api.h>
#include <sys/ptrace.h>
#include <sys/sol_procfs.h>
#include <sys/dtrace_types.h>
Expand Down

0 comments on commit 188bf56

Please sign in to comment.