git: b5a5feb60d96 - main - libsysdecode: Avoid non-portable \> word end boundary in mktables

From: Jessica Clarke <jrtc27_at_FreeBSD.org>
Date: Fri, 20 Nov 2026 14:38:46 UTC
The branch main has been updated by jrtc27:

URL: https://cgit.FreeBSD.org/src/commit/?id=b5a5feb60d96d7db472bcc3a4562b76ad3b09c2c

commit b5a5feb60d96d7db472bcc3a4562b76ad3b09c2c
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2026-11-20 14:37:14 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2026-11-20 14:37:14 +0000

    libsysdecode: Avoid non-portable \> word end boundary in mktables
    
    Whilst we bootstrap our own sed when building on non-FreeBSD, it uses
    the system regex(3) implementation, and so inherits its extensions, not
    our own. Our implementation and glibc's both include this extension to
    POSIX, but macOS's does not, and so even with our bootstrap sed we
    cannot use the \> extension when built and run on macOS.
    
    Unfortunately, there is no alternative form we can use; whilst macOS
    implements [[:>:]] as an extension that provides this same feature, and
    so do we, the regex(3) implementation in glibc does not, and the only
    alternative glibc offers is \b, which neither us nor macOS implement.
    
    We could make the form used conditional on the OS, but that starts to
    get messy once other Linux libcs enter the picture, which in theory we
    somewhat support.
    
    Rewrite both uses to avoid the need for \>. For gen_table, use a pattern
    to match the identifier that is precisely the (non-extended) C99
    identifier pattern, and therefore by virtue of longer submatches being
    preferred left-to-right will capture the entire identifier before the .*
    matches anything, with no need to check for a boundary. However, for
    gen_table_enum, the input pattern (${grep}) can be more specific, so we
    should check for a word boundary, which we can do by explicitly matching
    on a non-identifier character (or the end of the line).
    
    With and without this patch applied to releng/15.2 at time of writing,
    building on both FreeBSD 15.1 and Ubuntu 22.04, make tinderbox produces
    identical tables.h files across all four possible such configurations;
    specifically:
    
      find $MAKEOBJDIRPREFIX -path '*/libsysdecode/tables.h' -exec md5sum {} + | LC_ALL=C sort
    
    is identical for the four OS * patched configurations. Additionally, make
    tinderbox for the same patched tree on macOS 27.2.1 (noting the unpatched tree
    doesn't build) also identical produces identical tables.h files to these four
    configurations.
    
    Reviewed by:    des
    Fixes:          8b197806dcdf ("libsysdecode: Teach mktables to handle enums")
    MFC after:      1 day
    Differential Revision:  https://reviews.freebsd.org/D61783
---
 lib/libsysdecode/mktables | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/libsysdecode/mktables b/lib/libsysdecode/mktables
index bb784c853e48..61dc089a42c4 100644
--- a/lib/libsysdecode/mktables
+++ b/lib/libsysdecode/mktables
@@ -64,7 +64,7 @@ _EOF_
 		sed -nE ${excl:+-e "/${excl}/d"} \
 		    -e "/^#[[:space:]]*define[[:space:]]+${grep}/p" \
 		    "${include_dir}/${file}" | \
-		sed -Ee 's/.*define[[:space:]]+([^[:space:]]+)\>.*/TABLE_ENTRY(\1)/'
+		sed -Ee 's/.*define[[:space:]]+([_[:alpha:]][_[:alnum:]]*).*/TABLE_ENTRY(\1)/'
 	fi
 cat <<_EOF_
 TABLE_END
@@ -95,7 +95,7 @@ _EOF_
 		awk '/^(typedef[[:space:]]*)?enum([[:space:]].*)?\{/,
                      /^\}([[:space:]].*)?;/' |
 		# pick out the constants we want
-		sed -Ene 's/^[[:space:]]*('"${grep}"')\>.*/TABLE_ENTRY(\1)/p'
+		sed -Ene 's/^[[:space:]]*('"${grep}"')([^_[:alnum:]].*|$)/TABLE_ENTRY(\1)/p'
 	fi
 cat <<_EOF_
 TABLE_END