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

Add inline with SNAPPY_ATTRIBUTE_ALWAYS_INLINE #128

Closed
wants to merge 2 commits into from

Conversation

gdsotirov
Copy link

@gdsotirov gdsotirov commented May 5, 2021

Add inline with SNAPPY_ATTRIBUTE_ALWAYS_INLINE on AdvanceToNextTag to fix the following compilation errors and a warning with GCC:

[  2%] Building CXX object CMakeFiles/snappy.dir/snappy.cc.o
/usr/bin/c++   -DHAVE_CONFIG_H -Dsnappy_EXPORTS -I/usr/src/tmp/snappy-1.1.9/build -I/usr/src/tmp/snappy-1.1.9  -O3 -march=i586 -mtune=i686 -Wall -Wextra -fno-exceptions -fno-rtti -O3 -DNDEBUG -fPIC   -std=c++11 -o CMakeFiles/snappy.dir/snappy.cc.o -c /usr/src/tmp/snappy-1.1.9/snappy.cc
/usr/src/tmp/snappy-1.1.9/snappy.cc:1017:8: warning: always_inline function might not be inlinable [-Wattributes]
 size_t AdvanceToNextTag(const uint8_t** ip_p, size_t* tag) {
        ^
/usr/src/tmp/snappy-1.1.9/snappy.cc: In function 'std::pair<const unsigned char*, int> snappy::DecompressBranchless(const uint8_t*, const uint8_t*, ptrdiff_t, T, ptrdiff_t) [with T = char*; uint8_t = unsigned char; ptrdiff_t = int]':
/usr/src/tmp/snappy-1.1.9/snappy.cc:1017:8: error: inlining failed in call to always_inline 'size_t snappy::AdvanceToNextTag(const uint8_t**, size_t*)': function body can be overwritten at link time
/usr/src/tmp/snappy-1.1.9/snappy.cc:1097:53: error: called from here
         size_t tag_type = AdvanceToNextTag(&ip, &tag);
                                                     ^
/usr/src/tmp/snappy-1.1.9/snappy.cc:1017:8: error: inlining failed in call to always_inline 'size_t snappy::AdvanceToNextTag(const uint8_t**, size_t*)': function body can be overwritten at link time
 size_t AdvanceToNextTag(const uint8_t** ip_p, size_t* tag) {
        ^
/usr/src/tmp/snappy-1.1.9/snappy.cc:1097:53: error: called from here
         size_t tag_type = AdvanceToNextTag(&ip, &tag);
                                                     ^
/usr/src/tmp/snappy-1.1.9/snappy.cc:1017:8: error: inlining failed in call to always_inline 'size_t snappy::AdvanceToNextTag(const uint8_t**, size_t*)': function body can be overwritten at link time
 size_t AdvanceToNextTag(const uint8_t** ip_p, size_t* tag) {
        ^
/usr/src/tmp/snappy-1.1.9/snappy.cc:1097:53: error: called from here
         size_t tag_type = AdvanceToNextTag(&ip, &tag);
                                                     ^
CMakeFiles/snappy.dir/build.make:137: recipe for target 'CMakeFiles/snappy.dir/snappy.cc.o' failed

Just like with other functions using SNAPPY_ATTRIBUTE_ALWAYS_INLINE macro (i.e. __attribute__((always_inline)) ) it is necessary to use C++ inline specifier.

Add inline with SNAPPY_ATTRIBUTE_ALWAYS_INLINE on AdvanceToNextTag to
fix the following compilation errors and a warning with GCC:

[  2%] Building CXX object CMakeFiles/snappy.dir/snappy.cc.o
/usr/bin/c++   -DHAVE_CONFIG_H -Dsnappy_EXPORTS
-I/tmp/snappy-1.1.9/build -I/tmp/snappy-1.1.9  -O3
-march=i586 -mtune=i686 -Wall -Wextra -fno-exceptions -fno-rtti -O3
-DNDEBUG -fPIC   -std=c++11 -o CMakeFiles/snappy.dir/snappy.cc.o -c
/tmp/snappy-1.1.9/snappy.cc
/tmp/snappy-1.1.9/snappy.cc:1017:8: warning: always_inline
function might not be inlinable [-Wattributes]
 size_t AdvanceToNextTag(const uint8_t** ip_p, size_t* tag) {
        ^
/tmp/snappy-1.1.9/snappy.cc: In function 'std::pair<const
unsigned char*, int> snappy::DecompressBranchless(const uint8_t*, const
uint8_t*, ptrdiff_t, T, ptrdiff_t) [with T = char*; uint8_t = unsigned
char; ptrdiff_t = int]':
/tmp/snappy-1.1.9/snappy.cc:1017:8: error: inlining failed in
call to always_inline 'size_t snappy::AdvanceToNextTag(const uint8_t**,
size_t*)': function body can be overwritten at link time
/tmp/snappy-1.1.9/snappy.cc:1097:53: error: called from here
         size_t tag_type = AdvanceToNextTag(&ip, &tag);
                                                     ^
/tmp/snappy-1.1.9/snappy.cc:1017:8: error: inlining failed in
call to always_inline 'size_t snappy::AdvanceToNextTag(const uint8_t**,
size_t*)': function body can be overwritten at link time
 size_t AdvanceToNextTag(const uint8_t** ip_p, size_t* tag) {
        ^
/tmp/snappy-1.1.9/snappy.cc:1097:53: error: called from here
         size_t tag_type = AdvanceToNextTag(&ip, &tag);
                                                     ^
/tmp/snappy-1.1.9/snappy.cc:1017:8: error: inlining failed in
call to always_inline 'size_t snappy::AdvanceToNextTag(const uint8_t**,
size_t*)': function body can be overwritten at link time
 size_t AdvanceToNextTag(const uint8_t** ip_p, size_t* tag) {
        ^
/tmp/snappy-1.1.9/snappy.cc:1097:53: error: called from here
         size_t tag_type = AdvanceToNextTag(&ip, &tag);
                                                     ^
CMakeFiles/snappy.dir/build.make:137: recipe for target
'CMakeFiles/snappy.dir/snappy.cc.o' failed

Just like with other functions using SNAPPY_ATTRIBUTE_ALWAYS_INLINE
macro (i.e. __attribute__((always_inline)) ) it is necessary to use C++
inline specifier.
@google-cla google-cla bot added the cla: yes label May 5, 2021
@winterheart
Copy link

Please note, this error appears only with GCC and -DBUILD_SHARED_LIBS=ON. Need to add this configuration to Travis matrix to cover this problem.

@SpaceIm
Copy link

SpaceIm commented May 6, 2021

It also fails with -DBUILD_SHARED_LIBS=OFF actually. As well as clang < 9 or apple-clang < 11 with an other error.

@gdsotirov
Copy link
Author

To clarify my build configuration that lead to reported errors was:

-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-O3" \
-DCMAKE_C_FLAGS="-O3" \
-DCMAKE_INSTALL_LIBDIR=/usr/lib \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_VERBOSE_MAKEFILE=TRUE

I'm not familiar with project's CI configuration (what compilers, OSes and configuration options are used), but I believe it is better to have code that supports most of the compilers, instead of just latest versions. Right now I'm compiling with GCC 5.5.0 for Slackware 14.2, but soon I'll be compiling the same with GCC 10.3 for Slackware 15.0 and there are variety of other configurations with other distributions.

@xkszltl
Copy link

xkszltl commented May 10, 2021

Great! We hit this error as well in 1.1.9 with gcc-8 (but only for shared libs).
Build log was commented to the related commit 3b57165

[1/5] Building CXX object CMakeFiles/snappy.dir/snappy.cc.o
FAILED: CMakeFiles/snappy.dir/snappy.cc.o 
ccache /usr/bin/g++-8 -DHAVE_CONFIG_H -Dsnappy_EXPORTS -I. -I../ -fdebug-prefix-map='/tmp/scratch'='/usr/local/src' -g -Wall -Wextra -fno-exceptions -fno-rtti -mavx -mbmi2 -O3 -DNDEBUG -fPIC -std=c++11 -MD -MT CMakeFiles/snappy.dir/snappy.cc.o -MF CMakeFiles/snappy.dir/snappy.cc.o.d -o CMakeFiles/snappy.dir/snappy.cc.o -c ../snappy.cc
../snappy.cc:292:76: warning: ignoring attributes on template argument ‘__m128i’ {aka ‘__vector(2) long long int’} [-Wignored-attributes]
 static inline std::pair<__m128i /* pattern */, __m128i /* reshuffle_mask */>
                                                                            ^
../snappy.cc:292:76: warning: ignoring attributes on template argument ‘__m128i’ {aka ‘__vector(2) long long int’} [-Wignored-attributes]
../snappy.cc:1017:8: warning: always_inline function might not be inlinable [-Wattributes]
 size_t AdvanceToNextTag(const uint8_t** ip_p, size_t* tag) {
        ^~~~~~~~~~~~~~~~
../snappy.cc: In function ‘std::pair<const unsigned char*, long int> snappy::DecompressBranchless(const uint8_t*, const uint8_t*, ptrdiff_t, T, ptrdiff_t) [with T = char*]’:
../snappy.cc:1017:8: error: inlining failed in call to always_inline ‘size_t snappy::AdvanceToNextTag(const uint8_t**, size_t*)’: function body can be overwritten at link time
../snappy.cc:1097:43: note: called from here
         size_t tag_type = AdvanceToNextTag(&ip, &tag);
                           ~~~~~~~~~~~~~~~~^~~~~~~~~~~
../snappy.cc:1017:8: error: inlining failed in call to always_inline ‘size_t snappy::AdvanceToNextTag(const uint8_t**, size_t*)’: function body can be overwritten at link time
 size_t AdvanceToNextTag(const uint8_t** ip_p, size_t* tag) {
        ^~~~~~~~~~~~~~~~
../snappy.cc:1097:43: note: called from here
         size_t tag_type = AdvanceToNextTag(&ip, &tag);
                           ~~~~~~~~~~~~~~~~^~~~~~~~~~~
../snappy.cc:1017:8: error: inlining failed in call to always_inline ‘size_t snappy::AdvanceToNextTag(const uint8_t**, size_t*)’: function body can be overwritten at link time
 size_t AdvanceToNextTag(const uint8_t** ip_p, size_t* tag) {
        ^~~~~~~~~~~~~~~~
../snappy.cc:1097:43: note: called from here
         size_t tag_type = AdvanceToNextTag(&ip, &tag);
                           ~~~~~~~~~~~~~~~~^~~~~~~~~~~
ninja: build stopped: cannot make progress due to previous errors.

xkszltl added a commit to xkszltl/Roaster that referenced this pull request May 10, 2021
skmpz added a commit to skmpz/void-packages that referenced this pull request Jun 11, 2021
ericonr pushed a commit to void-linux/void-packages that referenced this pull request Jun 11, 2021
hazayan pushed a commit to hazayan/void-packages that referenced this pull request Jun 12, 2021
@xkszltl
Copy link

xkszltl commented Jul 14, 2021

@pwnall Could you take a look? You recently break this function into 2 arch-optimized versions (b4888f7) but still have the issue.

@gdsotirov
Copy link
Author

Although the total ignorance I updated the patch to avoid conflicts with the base branch.

xkszltl added a commit to xkszltl/Roaster that referenced this pull request Jul 20, 2021
@DmitryLukyanov
Copy link

Is there any updates here? We also see this when we try to build the snappy on linux

@andypost
Copy link

andypost commented Sep 2, 2021

Current changes allow to build on linux

@gdsotirov
Copy link
Author

@andypost Can you please, explain (i.e. what changed or give a commit reference)?

@andypost
Copy link

andypost commented Oct 7, 2021

@gdsotirov I'm building it for Alpinelinux (musl) you can see it in https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/24894

@gdsotirov
Copy link
Author

@andypost Ah, OK. I misunderstood you. I though you mean that "current changes" in this repository allow to build on Linux. Anyway, we'll apparently continue use the patch until upstream considers fixing the problem.

algitbot pushed a commit to alpinelinux/aports that referenced this pull request Nov 15, 2021
- using patch for inlining google/snappy#128
- tests and benchmark are third-party, using additional sources and unittests
dconeybe added a commit to firebase/firebase-cpp-sdk that referenced this pull request Apr 13, 2022
dconeybe added a commit to firebase/firebase-ios-sdk that referenced this pull request Apr 13, 2022
mbautin added a commit to yugabyte/snappy that referenced this pull request May 24, 2022
@Catwowo
Copy link

Catwowo commented Aug 4, 2022

Why don't you fix it!! Debian gives different modification methods https://sources.debian.org/patches/snappy/1.1.9-2/0001-Add-inline-with-SNAPPY_ATTRIBUTE_ALWAYS_INLINE.patch/,and I also encountered this problem on MPIS.

@ffontaine
Copy link

Patch seems to be applied with d644ca8. I assume that this PR can be closed.

@gdsotirov
Copy link
Author

Sure. It took more than 2 years to add one word in the code to fix compilation...

@gdsotirov gdsotirov closed this Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants