php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27104 CLI/CGI SAPI module variable name conflict
Submitted: 2004-01-31 08:30 UTC Modified: 2004-02-11 16:54 UTC
From: alex dot php at epathology dot com dot au Assigned: helly (profile)
Status: Closed Package: CGI/CLI related
PHP Version: 4.3.4, 5CVS OS: OpenBSD 3.3
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alex dot php at epathology dot com dot au
New email:
PHP Version: OS:

 

 [2004-01-31 08:30 UTC] alex dot php at epathology dot com dot au
Description:
------------
Trying to compile PHP 4.3.4 with the CLI SAPI module on OpenBSD 3.3 gives the warnings listed under 'actual result' related to the optind and optarg variables.

The CLI binary produced then doesn't interpret its command line arguments properly.

Fix:
This seems to be due to the static optarg and optind variables in sapi/cli/php_cli.c conflicting with those of the standard library. The problem went away when I renamed these two variables.

Reproduce code:
---------------
./configure \
        --with-config-file-path=/var/www/conf \
        --with-apxs \
        --with-openssl \
        --with-zlib \
        --with-iconv \
        --with-gettext \
        --with-recode \
        --with-pgsql \
        --without-mysql \
        --without-xml \
        --enable-inline-optimization \
        --enable-shared \
        --enable-dio \
        --enable-bcmath \
        --enable-calendar \
        --enable-sockets \
        --disable-static
make
sapi/cli/php --help

Expected result:
----------------
Compilation without problems, with help text shown when running 'sapi/cli/php --help'.

Actual result:
--------------
When the CLI is being compiled the following warnings appear, and then 'sapi/cli/php --help' ignores the --help argument.

/bin/sh /home/alex/src/php-4.3.4/libtool --silent --preserve-dup-deps --mode=compile gcc  -Isapi/cli/ -I/home/alex/src/php-4.3.4/sapi/cli/ -DPHP_ATOM_INC -I/home/alex/src/php-4.3.4/include -I/home/alex/src/php-4.3.4/main -I/home/alex/src/php-4.3.4 -I/home/alex/src/php-4.3.4/Zend -I/usr/local/include -I/usr/local/pgsql/include -I/home/alex/src/php-4.3.4/ext/xml/expat  -I/home/alex/src/php-4.3.4/TSRM  -g -O2  -prefer-pic -c /home/alex/src/php-4.3.4/sapi/cli/php_cli.c -o sapi/cli/php_cli.lo
/tmp/ccN17837.s: Assembler messages:
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optind' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optarg' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optind' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optarg' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optarg' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optarg' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optarg' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optarg' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optarg' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optind' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optarg' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optind' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optarg' should be global
/tmp/ccN17837.s:3786: Warning: GOT relocation burb: `_optind' should be global
/bin/sh /home/alex/src/php-4.3.4/libtool --silent --preserve-dup-deps --mode=link gcc -export-dynamic -g -O2  -L/usr/local/lib -L/usr/local/pgsql/lib  -R /usr/local/lib -R /usr/local/pgsql/lib ext/openssl/openssl.lo ext/zlib/zlib.lo (many .lo files) main/internal_functions_cli.lo -lrecode -lpq -liconv -lintl -lz -lssl -lcrypto -lm  -o sapi/cli/php
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x1872
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x1742
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x1735
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x1711
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x16bd
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x1661
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x164a
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x1609
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x1420
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x1413
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x11c4
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x11bd
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x1100
ld: sapi/cli/php_cli.lo: relocation must refer to global symbol at 0x10f5


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-01 08:35 UTC] alex dot php at epathology dot com dot au
$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-unknown-openbsd3.3/2.95.3/specs
gcc version 2.95.3 20010125 (prerelease, propolice)

This is the default compiler that comes with OpenBSD 3.3.

I just checked a draft copy of the ISO C99 specification, and it would seem that defining static optind and optarg variables after including unistd.h, which has extern declarations with the same name, results in undefined behaviour (6.2.2.7). So I guess the code violates standard C regardless of whether it works with some versions GCC.
 [2004-02-08 12:00 UTC] sniper@php.net
Assigned to Marcus who broke this in both CLI and CGI sapis.

 [2004-02-11 16:54 UTC] helly@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 16:01:29 2024 UTC