HomeFreeBSD

libdtrace: Permit taking the address of an identifier without type info

Description

libdtrace: Permit taking the address of an identifier without type info

Symbols defined using assembler directives lack type info, but in this
case one ought to be able to cast a pointer to the symbol and
dereference the pointer to get a value. Without this change, D
disallows this trick since it requires all identifiers to have a type.

Relax the rules slightly and allow an identifier to have type "void" if
we know we're just taking its address.

As a result, the following dtrace invocation works:

dtrace -n 'tick-1s {printf("%d", *(int *)&`ticks);}'

In particular, since commit b2b974f7ef4c ("clock: Simplify subr_ticks
and rename"), "ticks" does not have any type info associated with it, so
its value couldn't be printed. This trick provides a workaround and is
probably generally useful.

Add a regression test which exercises this functionality.

PR: 287752
Reviewed by: avg
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D51417

Details

Provenance
markjAuthored on Jul 21 2025, 1:34 PM
Reviewer
avg
Differential Revision
D51417: libdtrace: Permit taking the address of an identifier without type info
Parents
rG654dea596703: libdtrace: Use a designated array initializer for dt_cook_funcs[]
Branches
Unknown
Tags
Unknown