[SERVER-2883] gcc reports "array subscript is above array bounds" in stringToOid Created: 01/Apr/11  Updated: 05/Apr/12  Resolved: 27/Jan/12

Status: Closed
Project: Core Server
Component/s: Build
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Trevor Robinson Assignee: Mathias Stearn
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

gcc 4.5.2 on ubuntu natty armel, gcc 4.4.5 on ubuntu maverick armel


Attachments: Text File mongodb-bson-oid.patch    
Operating System: ALL
Participants:

 Description   

I get the following errors building from 1.8.1-rc0 or trunk:

g++ -o db/json.o -c -Wnon-virtual-dtor -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -fno-builtin-memcmp -O3 -D_SCONS -DMONGO_EXPOSE_MACROS -DXULRUNNER -DOLDJS -DXP_UNIX -I/usr/include/nspr -I/usr/include/xulrunner-2.0/stable -I/usr/include/xulrunner-2.0/unstable -I/usr/include/xulrunner-2.0 -I. -I/usr/local/home/trobinson/dev/v8/include db/json.cpp
cc1plus: warnings being treated as errors
db/json.cpp: In function 'mongo::OID mongo::stringToOid(const char*)':
db/json.cpp:331:49: error: array subscript is above array bounds
db/json.cpp:331:49: error: array subscript is above array bounds
db/json.cpp:331:49: error: array subscript is above array bounds
db/json.cpp:331:49: error: array subscript is above array bounds
db/json.cpp:331:49: error: array subscript is above array bounds
db/json.cpp:331:49: error: array subscript is above array bounds
db/json.cpp:331:49: error: array subscript is above array bounds
db/json.cpp:331:49: error: array subscript is above array bounds
scons: *** [db/json.o] Error 1
scons: building terminated because of errors.

This may be due to GCC bug 47418: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47418

The error can be fixed by editing bson/oid.h and moving unsigned char data[12]; to the top of the anonymous union in class OID.

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/arm-linux-gnueabi/gcc/arm-linux-gnueabi/4.5.2/lto-wrapper
Target: arm-linux-gnueabi
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.5.2-6ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs --enable-languages=c,c+,fortran,objc,obj-c+ --prefix=/usr --program-suffix=-4.5 --enable-shared --enable-multiarch --with-multiarch-defaults=arm-linux-gnueabi --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib/arm-linux-gnueabi --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib/arm-linux-gnueabi --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-plugin --enable-gold --enable-ld=default --with-plugin-ld=ld.gold --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv7-a --with-float=softfp --with-fpu=vfpv3-d16 --with-mode=thumb --disable-werror --enable-checking=release --build=arm-linux-gnueabi --host=arm-linux-gnueabi --target=arm-linux-gnueabi
Thread model: posix
gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-6ubuntu5)

Also occurs with gcc 4.4.5:

  1. gcc -v
    Using built-in specs.
    Target: arm-linux-gnueabi
    Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c+,fortran,objc,obj-c+ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv7-a --with-float=softfp --with-fpu=vfpv3-d16 --with-mode=thumb --disable-werror --enable-checking=release --build=arm-linux-gnueabi --host=arm-linux-gnueabi --target=arm-linux-gnueabi
    Thread model: posix
    gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)


 Comments   
Comment by Mathias Stearn [ 05/Apr/12 ]

What does gcc -v say? Note that arm isn't fully supported so you may run into further issues even if you get this resolved.

Comment by Brian Hutchinson [ 05/Apr/12 ]

I can confirm that it happens still on Ubuntu 11.04 ARM running on BeagleBoard native building 2.0.4.

root@localhost:/mnt/mongodb# scons all
scons: Reading SConscript files ...
scons version: 2.0.1
python version: 2 7 1 'final' 0
Checking whether the C++ compiler works(cached) yes
Checking for C library stdc++... (cached) yes
Checking for C++ header file execinfo.h... (cached) yes
Checking for C library pcap... (cached) yes
scons: done reading SConscript files.
scons: Building targets ...
generate_buildinfo(["build/buildinfo.cpp"], ['\n#include
<string>\n#include <boost/version.hpp>\n\n#include
"mongo/util/version.h"\n\nnamespace mongo {\n const char *
gitVersion()

{ return "%(git_version)s"; }

\n std::str)
g++ -o build/linux2/normal/mongo/db/json.o -c -Wnon-virtual-dtor
-Woverloaded-virtual -fPIC -fno-strict-aliasing -ggdb -pthread -Wall
-Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -pipe
-fno-builtin-memcmp -O3 -DBOp
cc1plus: warnings being treated as errors
src/mongo/db/json.cpp: In function 'mongo::OID mongo::stringToOid(const char*)':
src/mongo/db/json.cpp:365:49: error: array subscript is above array bounds
src/mongo/db/json.cpp:365:49: error: array subscript is above array bounds
src/mongo/db/json.cpp:365:49: error: array subscript is above array bounds
src/mongo/db/json.cpp:365:49: error: array subscript is above array bounds
src/mongo/db/json.cpp:365:49: error: array subscript is above array bounds
src/mongo/db/json.cpp:365:49: error: array subscript is above array bounds
src/mongo/db/json.cpp:365:49: error: array subscript is above array bounds
src/mongo/db/json.cpp:365:49: error: array subscript is above array bounds
scons: *** [build/linux2/normal/mongo/db/json.o] Error 1
scons: building terminated because of errors.

Regards,

Brian

Comment by Trevor Robinson [ 27/Jan/12 ]

Not anymore, since I've upgraded to Ubuntu Oneiric, which uses GCC 4.6. It's probably still an issue in GCC 4.4 and 4.5, but no one should be using those on ARM, given all the ARM fixes going into 4.6+.

Comment by Mathias Stearn [ 21/Jan/12 ]

Are you still seeing this? It isn't showing up in any of our buildbots.

Comment by Trevor Robinson [ 24/Jun/11 ]

Patch (against current trunk) to fix SERVER-2883 by moving 'unsigned char data[12];' to the top of the anonymous union in class OID.

Generated at Thu Feb 08 03:01:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.