Page MenuHomeFreeBSD

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

Authored by markj on Jul 19 2025, 12:17 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Dec 6, 10:57 PM
Unknown Object (File)
Mon, Dec 1, 3:30 AM
Unknown Object (File)
Thu, Nov 27, 2:39 PM
Unknown Object (File)
Tue, Nov 25, 4:46 PM
Unknown Object (File)
Tue, Nov 18, 6:38 AM
Unknown Object (File)
Sat, Nov 15, 10:49 AM
Unknown Object (File)
Nov 3 2025, 9:33 AM
Unknown Object (File)
Nov 3 2025, 9:33 AM
Subscribers

Details

Summary

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.

MFC after: 1 month

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 65573
Build 62456: arc lint + arc unit