Bill Sommerfeld
2024-02-13 5f4d07db8cd24ae74c072de826a0d29235aad3c3
shared-macros.mk: define USE_CTF to enable CTF

CTF is the "Compact Type Format", a compressed debugging metadata
format used by dtrace and mdb. Most of illumos-gate is built with
CTF; it would be helpful for observability if a few other packages
from userland were also built with CTF.
3 files modified
52 ■■■■ changed files
make-rules/ips.mk 3 ●●●●● patch | view | raw | blame | history
make-rules/shared-macros.mk 26 ●●●●● patch | view | raw | blame | history
tools/userland-mangler 23 ●●●● patch | view | raw | blame | history
make-rules/ips.mk
@@ -484,6 +484,9 @@
    $(MKDIR) $@
PKGMANGLE_OPTIONS = -D $(MANGLED_DIR) $(PKG_PROTO_DIRS:%=-d %)
ifeq ($(strip $(USE_CTF)),yes)
PKGMANGLE_OPTIONS += -c $(CTFCONVERT)
endif
$(MANIFEST_BASE)-%.mangled:    $(MANIFEST_BASE)-%.mogrified $(MANGLED_DIR)
    $(PKGMANGLE) $(PKGMANGLE_OPTIONS) -m $< >$@
make-rules/shared-macros.mk
@@ -1097,6 +1097,7 @@
DOS2UNIX =    /usr/bin/dos2unix
TAC =        /usr/bin/tac
QUILT =        /usr/bin/quilt
CTFCONVERT =    /opt/onbld/bin/$(MACH)/ctfconvert
INS.dir=        $(INSTALL) -d $@
INS.file=       $(INSTALL) -m 444 $< $(@D)
@@ -1244,6 +1245,31 @@
# Add compiler specific 'default' features
CFLAGS +=    $(CFLAGS.$(COMPILER))
# Per-compiler CFLAGS to use when building for CTF.  Currently only defined
# for gcc; could be made to work with other compilers.
# -gdwarf-4 is the newest DWARF revision understood by illumos libctf
#
# -gstrict-dwarf prevents the compiler from including newer DWARF features
CTF_CFLAGS.gcc = -g -gdwarf-4 -gstrict-dwarf
# -msave-args makes it possible for debugging tools (specifically pstack and
# mdb) to retrieve function arguments, and is required for the python pstack
# hooks.
CTF_CFLAGS.gcc += -msave-args
# By default, GCC may put parts of functions in different named sub-sections
# of .text based on their presumed or measured calling frequency.  This is not
# currently handled by libctf and other illumos tools which assume that a
# function's text lies in a single contiguous range of virtual addresses.
# Disable this optimization if building with CTF.
CTF_CFLAGS.gcc += -fno-reorder-functions -fno-reorder-blocks-and-partition
# Enable CTF if desired
ifeq ($(strip $(USE_CTF)),yes)
CFLAGS += $(if $(CTF_CFLAGS.$(COMPILER)), \
    $(CTF_CFLAGS.$(COMPILER)), \
    $(error Error: CTF_CFLAGS.$(COMPILER) must be defined to use CTF with $(COMPILER)))
endif
# Build 32 or 64 bit objects in C++ as well.
CXXFLAGS +=    $(CC_BITS)
tools/userland-mangler
@@ -300,8 +300,15 @@
                             re.MULTILINE|re.DOTALL)
        return cddl_re.sub('', text)
def mangle_path(manifest, action, src, dest):
def do_ctfconvert(converter, file):
        args = [converter, '-i', '-m', '-k', file]
        print(*args, file=sys.stderr)
        subprocess.call(args)
def mangle_path(manifest, action, src, dest, ctfconvert):
        if elf.is_elf_object(src):
                if ctfconvert is not None:
                        do_ctfconvert(ctfconvert, src)
                mangle_elf(manifest, action, src, dest)
        else:
                # a 'text' document (script, man page, config file, ...
@@ -329,7 +336,7 @@
#
# mangler.bypass = (true|false)
#
def mangle_paths(manifest, search_paths, destination):
def mangle_paths(manifest, search_paths, destination, ctfconvert):
        for action in manifest.gen_actions_by_type("file"):
                bypass = action.attrs.pop('mangler.bypass', 'false').lower()
                if bypass == 'true':
@@ -351,7 +358,8 @@
                        if directory != destination:
                                src = os.path.join(directory, path)
                                if os.path.isfile(src):
                                        mangle_path(manifest, action, src, dest)
                                        mangle_path(manifest, action,
                                                    src, dest, ctfconvert)
                                        break
def load_manifest(manifest_file):
@@ -372,10 +380,11 @@
        search_paths = []
        destination = None
        manifests = []
        ctfconvert = None
        try:
                opts, args = getopt.getopt(sys.argv[1:], "D:d:m:",
                        ["destination=", "search-directory=", "manifest="])
                opts, args = getopt.getopt(sys.argv[1:], "c:D:d:m:",
                        ["ctf=", "destination=", "search-directory=", "manifest="])
        except getopt.GetoptError as err:
                print(str(err))
                usage()
@@ -393,6 +402,8 @@
                                usage()
                        else:
                                manifests.append(manifest)
                elif opt in [ "-c", "--ctf" ]:
                        ctfconvert = arg
                else:
                        usage()
@@ -400,7 +411,7 @@
                usage()
        for manifest in manifests:
                mangle_paths(manifest, search_paths, destination)
                mangle_paths(manifest, search_paths, destination, ctfconvert)
                print(manifest)
        sys.exit(0)