Bug #80083 [Com]: Optimizer pass 6 removes variables used for data binding

From: Date: Tue, 15 Sep 2020 17:23:38 +0000
Subject: Bug #80083 [Com]: Optimizer pass 6 removes variables used for data binding
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-229018@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80083&edit=1

 ID:                 80083
 Comment by:         calvin at cmpct dot info
 Reported by:        calvin at cmpct dot info
 Summary:            Optimizer pass 6 removes variables used for data
                     binding
 Status:             Open
 Type:               Bug
 Package:            opcache
 Operating System:   IBM i 7.2
 PHP Version:        7.4.10
 Block user comment: N
 Private report:     N

 New Comment:

I skimmed the source and I think the only symbol table mangling code is in execute called code;
though perhaps the bind code in ibm_db2 could also signal something to opcache?. I also didn't
know opcache was willing to accept a workaround - has that happened before?


Previous Comments:
------------------------------------------------------------------------
[2020-09-15 12:32:14] nikic@php.net

Agree. I think it's okay for us to hardcode these functions as modifying the symtable in
opcache.

Do you know which functions are affected? Is it just db2_execute() that accesses local variables, or
also other functions?

------------------------------------------------------------------------
[2020-09-10 16:53:55] calvin at cmpct dot info

Yeah, I agree this is API is malpractice. (Looking at the db2 binding code and having it manipulate
local/global scope symbol tables when no other modules did so was a bit of a head-scratcher.)
Changing the db2 API would probably result in a breaking change though, and most code on ibm_db2
instead of (PDO_)ODBC is legacy; so I suspect most users running into this will either detune
opcache or migrate to ODBC. (Of course, this is the IBM i perspective. I don't know what LUW
people are doing here; perhaps they consider that extension more important.)

------------------------------------------------------------------------
[2020-09-10 15:39:17] nikic@php.net

The db2 extension needs to change its API to not work on variable names -- it needs to accept
variables by reference instead.

------------------------------------------------------------------------
[2020-09-10 15:24:44] calvin at cmpct dot info

Description:
------------
I'm not sure if this is an ibm_db2 module bug or an opcache bug, but I figured I'd report
here first.

Script, debug output at different optimization levels, and a diff between them available in this
gist (let me know if anything else is needed for repro and I can add to it): https://gist.github.com/NattyNarwhal/09679e177b11de22aeceaaffdc62012b

The summary is when optimizer pass 6 (DFA) runs through the program, it elides the variables used
for a data bound stored procedure call using the ibm_db2 extension, resulting in failure. Masking
the bit for pass 6 out (that is, setting optimization level 0x7FFEBFFF to 0x7FFEBFDF) is enough to
mitigate the failure.

Expected result:
----------------
Résultat : bar (or whatever the stored procedure used sets)

Actual result:
--------------
PHP Warning:  db2_execute(): Value Not Bound in /home/calvin/test/gautier.php on line 31
PHP Warning:  db2_execute(): Binding Error 3 in /home/calvin/test/gautier.php on line 31
Résultat :


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80083&edit=1


Thread (8 messages)

« previous php.bugs (#229018) next »