[DTrace-devel] [PATCH 2.0-branch] lexer: work around bug in flex <= 2.6.0 on OL7

Nick Alcock nick.alcock at oracle.com
Thu Jan 18 15:06:55 UTC 2024


Flex commit f863c949, released in 2.6.1, is a one-line fix to the
generated flex skeleton that fixes an old bug that breaks yywrap();
if it returns nonzero, input() is meant to return 0 to its caller
on EOF. This bug makes it return EOF instead, which no lexer expects
(and certainly the DTrace lexer does not).

Alas we cannot get around this bug just by defining %option noyywrap,
since that still emits the same buggy piece of the skeleton but just
introduces its own yywrap() which returns 1. And there's no way to
fix the skeleton from flex itself, and we can't require flex >= 2.6.1
since OL7 has 2.5.37.

So, for now, resort to a one-line patch to the generated lexer, silently
applied and skipped if it doesn't apply.  (Any generated lexer it doesn't
apply on will have this bug fixed.)

Apply it to OL7 only (via a patch in buildrpms/ol7) because it's ugly
to apply and the percentage of systems with a flex this old is low and
falling fast.

Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
---
 buildrpm/ol7/dt_lex.yywrap.diff | 11 +++++++++++
 buildrpm/ol7/dtrace.spec        |  8 +++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 buildrpm/ol7/dt_lex.yywrap.diff

Please review: if you like it, I'll push it directly to the 2.0-branch.

(It passes tests etc. I presume that the OL7 build picks up the
specfile from the directory, and no other builds do...)

diff --git a/buildrpm/ol7/dt_lex.yywrap.diff b/buildrpm/ol7/dt_lex.yywrap.diff
new file mode 100644
index 000000000000..78d15a118121
--- /dev/null
+++ b/buildrpm/ol7/dt_lex.yywrap.diff
@@ -0,0 +1,11 @@
+--- dt_lex.c.orig	2023-06-13 14:00:35.440457181 +0100
++++ dt_lex.c	2023-06-13 14:00:49.910469682 +0100
+@@ -2796,7 +2796,7 @@
+ 				case EOB_ACT_END_OF_FILE:
+ 					{
+ 					if ( yywrap( ) )
+-						return EOF;
++						return 0;
+ 
+ 					if ( ! (yy_did_buffer_switch_on_eof) )
+ 						YY_NEW_FILE;
diff --git a/buildrpm/ol7/dtrace.spec b/buildrpm/ol7/dtrace.spec
index 0dd233bbb28a..0d7eac971910 100644
--- a/buildrpm/ol7/dtrace.spec
+++ b/buildrpm/ol7/dtrace.spec
@@ -51,7 +51,7 @@
 %define glibc32 %{nil}
 %endif
 
-BuildRequires: rpm
+BuildRequires: rpm patch
 Name:         dtrace
 License:      Universal Permissive License (UPL), Version 1.0
 Group:        Development/Tools
@@ -168,6 +168,12 @@ make -j $(getconf _NPROCESSORS_ONLN) VERSION=%{version} \
 	KERNELDIRPREFIX=/usr/src/kernels KERNELDIRSUFFIX= \
 	KERNELS="%{kerneldirs}" %{maybe_use_fuse2}
 
+# Patch the buggy lexer generator and rebuild to pick up the patch
+(cd libdtrace; patch -r - -sNp0 < ../buildrpm/ol7/dt_lex.yywrap.diff)
+make -j $(getconf _NPROCESSORS_ONLN) VERSION=%{version} \
+	KERNELDIRPREFIX=/usr/src/kernels KERNELDIRSUFFIX= \
+	KERNELS="%{kerneldirs}" %{maybe_use_fuse2}
+
 # Force off debuginfo splitting.  We have no debuginfo in dtrace proper,
 # and the testsuite requires debuginfo for proper operation.
 %global debug_package %{nil}

base-commit: cfe780adb2439722942865292aaeaa5873d93e7d
-- 
2.43.0.272.gce700b77fd




More information about the DTrace-devel mailing list