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

            Bug ID: 68337
           Summary: [MPX] memcpy() for arrays with function pointers
                    results in huge resource usage and binaries
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jussi.judin at ericsson dot com
  Target Milestone: ---

Created attachment 36703
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36703&action=edit
Preprocessed source file including string.h

If I compile following program with GCC 5.2.0 with following options, it takes
around 7.6 seconds to compile and uses over 500 megabytes of memory (Maximum
resident set size):

$ gcc -save-temps -fcheck-pointer-bounds -mmpx -o mpx-funcptr-explosion -c
mpx-funcptr-explosion.c

#include <string.h>

#define ARRAY_SIZE 8192

typedef int (* funcptr_t) (void);

typedef struct {
    int data;
    funcptr_t callback1;
    funcptr_t callback2;
    funcptr_t callback3;
    funcptr_t callback4;
} funcptr_struct_t;

funcptr_struct_t source[ARRAY_SIZE];

void memcpy_user(void) {
    funcptr_struct_t target[ARRAY_SIZE];
    memcpy(target, source, sizeof(source));
}

The resulting binary takes 4197096 bytes and assembly file 8117029 bytes. Every
funcptr_t instance I add to the structure adds around 2.6 seconds to execution
time of the compilation. This basically makes it impossible to use static
memory with callback functions with MPX support, as it explodes the compilation
resources and the resulting binary.

GCC has following specifications:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/local/ejusjud/intel-mpx/bin/../libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-5.2.0/configure --enable-libmpx
--with-as=/home/ejusjud/local/intel-mpx/bin/as
--with-ld=/home/ejusjud/local/intel-mpx/bin/ld
--prefix=/home/ejusjud/local/intel-mpx
Thread model: posix
gcc version 5.2.0 (GCC)

Reply via email to