Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc-8.0 error=class-memaccess compile failure due to memcpy in ./memtable/inlineskiplist.h #2705

Closed
grooverdan opened this issue Aug 9, 2017 · 14 comments
Labels
up-for-grabs Up for grabs

Comments

@grooverdan
Copy link
Contributor

This isn't occurring on the gcc-7-branch however the gcc master/trunk branch is enhancing its strictness

${CXX} --version
+ x86_64-pc-linux-gnu-g++ --version
x86_64-pc-linux-gnu-g++ (GCC) 8.0.0 20170808 (experimental)

x86_64-pc-linux-gnu-g++ -m64 -O3 -g -I /opt/ibm/java/include/ -mtune=native -std=c++11  -DROCKSDB_USE_RTTI -g -faligned-new -W -Wextra -Wall -Wsign-compare -Wshadow -Wno-unused-parameter -Werror -I. -I./include -std=c++11 -m64 -O3 -g -I /opt/ibm/java/include/ -mtune=native -std=c++11 -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -m64 -O3 -g -I /opt/ibm/java/include/ -mtune=native -DOS_LINUX -fno-builtin-memcmp -DROCKSDB_FALLOCATE_PRESENT -DSNAPPY -DGFLAGS=gflags -DZLIB -DBZIP2 -DLZ4 -DZSTD -DNUMA -DTBB -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_PTHREAD_ADAPTIVE_MUTEX -DROCKSDB_BACKTRACE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -march=native  -DHAVE_SSE42 -DROCKSDB_SUPPORT_THREAD_LOCAL -DROCKSDB_JEMALLOC -DJEMALLOC_NO_DEMANGLE  -isystem ./third-party/gtest-1.7.0/fused-src -DSNAPPY=1 -DLZ4=1 -DZLIB=1 -DJEMALLOC=1 -DZSTD=1 -DNUMA=1 -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -c memtable/skiplistrep.cc -o memtable/skiplistrep.o 
In file included from memtable/skiplistrep.cc:6:0:
./memtable/inlineskiplist.h: In instantiation of 'void rocksdb::InlineSkipList::Node::StashHeight(int) [with Comparator = const rocksdb::MemTableRep::KeyComparator&]':
./memtable/inlineskiplist.h:599:3:   required from 'rocksdb::InlineSkipList::Node* rocksdb::InlineSkipList::AllocateNode(size_t, int) [with Comparator = const rocksdb::MemTableRep::KeyComparator&; size_t = long unsigned int]'
./memtable/inlineskiplist.h:561:25:   required from 'rocksdb::InlineSkipList::InlineSkipList(Comparator, rocksdb::Allocator*, int32_t, int32_t) [with Comparator = const rocksdb::MemTableRep::KeyComparator&; int32_t = int]'
memtable/skiplistrep.cc:28:28:   required from here
./memtable/inlineskiplist.h:281:11: error: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct std::atomic::Node*>' with no trivial copy-assignment [-Werror=class-memaccess]
     memcpy(&next_[0], &height, sizeof(int));
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ./memtable/inlineskiplist.h:47:0,
                 from memtable/skiplistrep.cc:6:
/compiler/include/c++/8.0.0/atomic:352:12: note: 'struct std::atomic::Node*>' declared here
     struct atomic<_Tp*>
            ^~~~~~~~~~~~
cc1plus: all warnings being treated as errors
Makefile:1731: recipe for target 'memtable/skiplistrep.o' failed
make: *** [memtable/skiplistrep.o] Error 1
@yiwu-arbug
Copy link
Contributor

yiwu-arbug commented Aug 10, 2017

@grooverdan will replace &next_[0] with static_cast<void*>(&next_[0]) workaround the error? I don't have gcc8 at hand.

@grooverdan
Copy link
Contributor Author

Sorry - wasn't sufficient. Didn't really have time to do much else about it today.

${CXX} --version
+ powerpc64le-unknown-linux-gnu-g++ --version
powerpc64le-unknown-linux-gnu-g++ (GCC) 8.0.0 20170809 (experimental)


powerpc64le-unknown-linux-gnu-g++ -m64 -O3 -g -I /opt/ibm/java/include/ -mtune=native  -DROCKSDB_USE_RTTI -g -faligned-new -W -Wextra -Wall -Wsign-compare -Wshadow -Wno-unused-parameter -Werror -I. -I./include -std=c++11 -m64 -O3 -g -I /opt/ibm/java/include/ -mtune=native -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -m64 -O3 -g -I /opt/ibm/java/include/ -mtune=native -DOS_LINUX -fno-builtin-memcmp -DROCKSDB_FALLOCATE_PRESENT -DSNAPPY -DGFLAGS=gflags -DZLIB -DBZIP2 -DLZ4 -DZSTD -DNUMA -DTBB -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_PTHREAD_ADAPTIVE_MUTEX -DROCKSDB_BACKTRACE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -mcpu=power8 -mtune=power8  -DROCKSDB_SUPPORT_THREAD_LOCAL -DROCKSDB_JEMALLOC -DJEMALLOC_NO_DEMANGLE  -isystem ./third-party/gtest-1.7.0/fused-src  -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -c memtable/skiplistrep.cc -o memtable/skiplistrep.o 
In file included from memtable/skiplistrep.cc:6:0:
./memtable/inlineskiplist.h: In instantiation of 'void rocksdb::InlineSkipList::Node::StashHeight(int) [with Comparator = const rocksdb::MemTableRep::KeyComparator&]':
./memtable/inlineskiplist.h:599:3:   required from 'rocksdb::InlineSkipList::Node* rocksdb::InlineSkipList::AllocateNode(size_t, int) [with Comparator = const rocksdb::MemTableRep::KeyComparator&; size_t = long unsigned int]'
./memtable/inlineskiplist.h:561:25:   required from 'rocksdb::InlineSkipList::InlineSkipList(Comparator, rocksdb::Allocator*, int32_t, int32_t) [with Comparator = const rocksdb::MemTableRep::KeyComparator&; int32_t = int]'
memtable/skiplistrep.cc:28:28:   required from here
./memtable/inlineskiplist.h:281:11: error: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct std::atomic::Node*>' with no trivial copy-assignment [-Werror=class-memaccess]
     memcpy(static_cast(&next_[0]), &height, sizeof(int));
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ./memtable/inlineskiplist.h:47:0,
                 from memtable/skiplistrep.cc:6:
/compiler/include/c++/8.0.0/atomic:352:12: note: 'struct std::atomic::Node*>' declared here
     struct atomic<_Tp*>
            ^~~~~~~~~~~~
cc1plus: all warnings being treated as errors

@tamird
Copy link
Contributor

tamird commented Jan 10, 2018

Since this writing there are more errors under gcc 8:

$ g++ --version
g++ (GCC) 8.0.0 20180108 (experimental)
/home/tduberstein/local/rocksdb/db/c.cc: In function ‘void rocksdb_writebatch_wi_iterate(rocksdb_writebatch_wi_t*, void*, void (*)(void*, const char*, size_t, const char*, size_t), void (*)(void*, const char*, size_t))’:
/home/tduberstein/local/rocksdb/db/c.cc:1664:5: error: conflicting C language linkage declaration ‘rocksdb_writebatch_wi_iterate(rocksdb_writebatch_wi_t*, void*, void (*)(void*, const char*, size_t, const char*, size_t), void (*)(void*, const char*, size_t))::H handler’ [-Werror]
   H handler;
     ^~~~~~~
/home/tduberstein/local/rocksdb/db/c.cc:1408:5: note: previous declaration ‘rocksdb_writebatch_iterate(rocksdb_writebatch_t*, void*, void (*)(void*, const char*, size_t, const char*, size_t), void (*)(void*, const char*, size_t))::H handler’
   H handler;
     ^~~~~~~
/home/tduberstein/local/rocksdb/db/c.cc: In function ‘rocksdb_slicetransform_t* rocksdb_slicetransform_create_fixed_prefix(size_t)’:
/home/tduberstein/local/rocksdb/db/c.cc:3126:12: error: conflicting C language linkage declaration ‘rocksdb_slicetransform_create_fixed_prefix(size_t)::Wrapper* wrapper’ [-Werror]
   Wrapper* wrapper = new Wrapper;
            ^~~~~~~
/home/tduberstein/local/rocksdb/db/c.cc:2680:12: note: previous declaration ‘rocksdb_filterpolicy_create_bloom_format(int, bool)::Wrapper* wrapper’
   Wrapper* wrapper = new Wrapper;
            ^~~~~~~
/home/tduberstein/local/rocksdb/db/c.cc: In function ‘rocksdb_slicetransform_t* rocksdb_slicetransform_create_noop()’:
/home/tduberstein/local/rocksdb/db/c.cc:3147:12: error: conflicting C language linkage declaration ‘rocksdb_slicetransform_create_noop()::Wrapper* wrapper’ [-Werror]
   Wrapper* wrapper = new Wrapper;
            ^~~~~~~
/home/tduberstein/local/rocksdb/db/c.cc:2680:12: note: previous declaration ‘rocksdb_filterpolicy_create_bloom_format(int, bool)::Wrapper* wrapper’
   Wrapper* wrapper = new Wrapper;
            ^~~~~~~
cc1plus: all warnings being treated as errors

@siying
Copy link
Contributor

siying commented Jan 10, 2018

@grooverdan @tamird feel free to send pull requests for those fixes. As @yiwu-arbug said, we don't have such environment to fix it. As long as your PR looks reasonable, we'll just merge it.

@tamird
Copy link
Contributor

tamird commented Apr 23, 2018

This was fixed in #3736.

@grooverdan
Copy link
Contributor Author

thanks @inikep

@jonhoo
Copy link

jonhoo commented May 16, 2018

master still does not compile with gcc8 for me on Arch Linux:

  CC       shared-objects/util/status_message.o
util/status.cc: In static member function ‘static const char* rocksdb::Status::CopyState(const char*)’:
util/status.cc:28:15: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
   std::strncpy(result, state, cch - 1);
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
util/status.cc:19:18: note: length computed here
       std::strlen(state) + 1; // +1 for the null terminator
       ~~~~~~~~~~~^~~~~~~
cc1plus: all warnings being treated as errors
make: *** [Makefile:645: shared-objects/util/status.o] Error 1

This is with 8.1 though:

$ gcc --version
gcc (GCC) 8.1.0

@ajkr
Copy link
Contributor

ajkr commented May 18, 2018

@jonhoo are you interested in trying to fix it? We don't have access to that platform

@ajkr ajkr added the up-for-grabs Up for grabs label May 18, 2018
@jonhoo
Copy link

jonhoo commented May 18, 2018

@ajkr this should happen with any gcc8.1 install — I don't think it's Arch Linux specific. I don't have any experience with the codebase so don't think I'm the right person to write a patch; I was just trying to compile rocksdb as a dependency :)

@grooverdan
Copy link
Contributor Author

If you don't like the ugly hack of a workaround I won't be offended.

tested in gcc from fc28.

$ gcc --version
gcc (GCC) 8.1.1 20180502 (Red Hat 8.1.1-1)

might be https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82944

@inikep
Copy link
Contributor

inikep commented May 18, 2018

I can't reproduce you error with Ubuntu 16.04 and:

gcc version 8.1.0 (Ubuntu 8.1.0-1ubuntu3~16.04.york0) 

@vedatech
Copy link

@inikep, try in Docker container (similar error)

FROM rikorose/gcc-cmake:gcc-8
...

@grooverdan
Copy link
Contributor Author

#3433 has on other gcc8 fixes too.

@ryanwwest
Copy link

ryanwwest commented Jun 14, 2018

We depend on rocksdb too but it looks like I'm getting a similar error as @jonhoo when trying to run make shared_lib:

  CC       shared-objects/util/status.o
util/status.cc: In static member function ‘static const char* rocksdb::Status::CopyState(const char*)’:                                                             
util/status.cc:28:15: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-
Werror=stringop-truncation]
   std::strncpy(result, state, cch - 1);
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
util/status.cc:19:18: note: length computed here
       std::strlen(state) + 1; // +1 for the null terminator
       ~~~~~~~~~~~^~~~~~~

I'm on Fedora Linux using gcc 8.1.1.

rcane pushed a commit to rcane/rocksdb that referenced this issue Sep 13, 2018
Summary:
Various rearrangements of the cch maths failed or replacing = '\0' with
memset failed to convince the compiler it was nul terminated. So took
the perverse option of changing strncpy to strcpy.

Return null if memory couldn't be allocated.

util/status.cc: In static member function ‘static const char* rocksdb::Status::CopyState(const char*)’:
util/status.cc:28:15: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
   std::strncpy(result, state, cch - 1);
   ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
util/status.cc:19:18: note: length computed here
       std::strlen(state) + 1; // +1 for the null terminator
       ~~~~~~~~~~~^~~~~~~
cc1plus: all warnings being treated as errors
make: *** [Makefile:645: shared-objects/util/status.o] Error 1

closes facebook#2705
Closes facebook#3870

Differential Revision: D8594114

Pulled By: anand1976

fbshipit-source-id: ab20f3a456a711e4d29144ebe630e4fe3c99ec25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
up-for-grabs Up for grabs
Projects
None yet
Development

No branches or pull requests

9 participants