https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71070

            Bug ID: 71070
           Summary: MPX gives a false positive when allocating a string
                    longer than 16 bytes on the stack
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alexo_o at ukr dot net
  Target Milestone: ---

Created attachment 38471
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38471&action=edit
Preprocessed file

It works only if:
* it is a string, not an array of chars
* the string is longer than 16 bytes
* the string is allocated on the stack

For example, #BR is thrown in the following line:

    string long_string("A long string with more than 16 symbols");

Full preprocessed source is attached.

System setup:

* GCC version: 6.1.0 (also appears with 5.3.0)
* the system type: Linux f8714f7988cf 4.2.0-35-generic #40-Ubuntu SMP Tue Mar
15 22:15:45 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
* Configured with: gcc/src/configure --enable-languages=c,c++
--disable-multilib --enable-libmpx
* Compilation flags: -O3 -fcheck-pointer-bounds -mmpx -lmpx

Output:

short string: short string
Allocated a big object
Saw a #BR! status 1 at 0x7f8eb754f148



That is, the last line is a false positive. 

Full output with -v -save-temps:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /root/bin/gcc/src/configure --enable-languages=c,c++
--disable-multilib --enable-libmpx : (reconfigured) ../src/configure
--enable-languages=c,c++ --disable-multilib --enable-libmpx
Thread model: posix
gcc version 5.3.0 (GCC) 
COLLECT_GCC_OPTIONS='-O3' '-fcheck-pointer-bounds' '-mmpx' '-v' '-save-temps'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/cc1plus -E -quiet -v
-imultiarch x86_64-linux-gnu -D_GNU_SOURCE test.cpp -mmpx -mtune=generic
-march=x86-64 -fcheck-pointer-bounds -O3 -fpch-preprocess -o test.ii
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0

/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/x86_64-unknown-linux-gnu

/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/backward
 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/include
 /usr/local/include
 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-O3' '-fcheck-pointer-bounds' '-mmpx' '-v' '-save-temps'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/cc1plus -fpreprocessed
test.ii -quiet -dumpbase test.cpp -mmpx -mtune=generic -march=x86-64 -auxbase
test -O3 -version -fcheck-pointer-bounds -o test.s
GNU C++ (GCC) version 5.3.0 (x86_64-unknown-linux-gnu)
        compiled by GNU C version 5.3.0, GMP version 5.1.3, MPFR version
3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (GCC) version 5.3.0 (x86_64-unknown-linux-gnu)
        compiled by GNU C version 5.3.0, GMP version 5.1.3, MPFR version
3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 316654f71ace181278f48334ff2cbcb8
COLLECT_GCC_OPTIONS='-O3' '-fcheck-pointer-bounds' '-mmpx' '-v' '-save-temps'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as -v --64 -o test.o test.s
GNU assembler version 2.26 (x86_64-pc-linux-gnu) using BFD version (GNU
Binutils) 2.26.20160125
COMPILER_PATH=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/:/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/:/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/:/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/:/usr/local/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/:/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../lib64/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../:/lib/:/usr/lib/
Reading specs from
/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../lib64/libmpx.spec
COLLECT_GCC_OPTIONS='-O3' '-fcheck-pointer-bounds' '-mmpx' '-v' '-save-temps'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/collect2 -plugin
/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/liblto_plugin.so
-plugin-opt=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.3.0/lto-wrapper
-plugin-opt=-fresolution=test.res -plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc
--eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2
/usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o
/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/crtbegin.o
-L/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0
-L/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../lib64
-L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu
-L/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../.. test.o -lmpx
-lstdc++ -lm -lmpx -lmpxwrappers -z bndplt -lgcc_s -lgcc -lc -lgcc_s -lgcc
/usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/crtend.o
/usr/lib/x86_64-linux-gnu/crtn.o
short string: short string
Allocated a big object
Saw a #BR! status 1 at 0x7f3220319148

Reply via email to