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

Crash while building #460

Closed
emil-peters opened this issue Jun 19, 2023 · 12 comments · Fixed by #496
Closed

Crash while building #460

emil-peters opened this issue Jun 19, 2023 · 12 comments · Fixed by #496

Comments

@emil-peters
Copy link

emil-peters commented Jun 19, 2023

While building on my computer I get the following error:

[ 22%] Building CXX object src/manifold/CMakeFiles/manifold.dir/src/boolean_result.cpp.o
cd /app/manifold/build/src/manifold && /usr/bin/c++ -Dmanifold_EXPORTS -I/app/manifold/src/manifold/include -I/app/manifold/src/utilities/include -I/app/manifold/src/third_party/thrust/dependencies/libcudacxx/include -I/app/manifold/src/third_party/thrust -I/app/manifold/src/third_party/glm/glm/.. -I/app/manifold/src/cross_section/include -I/app/manifold/src/third_party/clipper2/CPP/Clipper2Lib/include -I/app/manifold/src/collider/include -I/app/manifold/src/polygon/include -I/app/manifold/src/third_party/graphlite/include -O3 -DNDEBUG -fPIC -fPIC -Werror -Wall -Wno-sign-compare -Wno-unused -O3 -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP -std=gnu++17 -MD -MT src/manifold/CMakeFiles/manifold.dir/src/boolean_result.cpp.o -MF CMakeFiles/manifold.dir/src/boolean_result.cpp.o.d -o CMakeFiles/manifold.dir/src/boolean_result.cpp.o -c /app/manifold/src/manifold/src/boolean_result.cpp
In file included from /app/manifold/src/utilities/include/sparse.h:22,
                 from /app/manifold/src/collider/include/collider.h:17,
                 from /app/manifold/src/manifold/src/impl.h:18,
                 from /app/manifold/src/manifold/src/boolean3.h:16,
                 from /app/manifold/src/manifold/src/boolean_result.cpp:18:
In static member function ‘static void manifold::ManagedVec<T>::mallocManaged(T**, size_t) [with T = int]’,
    inlined from ‘std::tuple<manifold::VecDH<int>, manifold::VecDH<int> > {anonymous}::SizeOutput(manifold::Manifold::Impl&, const manifold::Manifold::Impl&, const manifold::Manifold::Impl&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::SparseIndices&, const manifold::SparseIndices&, bool, manifold::ExecutionPolicy)’ at /app/manifold/src/utilities/include/vec_dh.h:155:20:
/app/manifold/src/utilities/include/vec_dh.h:261:42: error: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
       *ptr = reinterpret_cast<T *>(malloc(bytes));
                                    ~~~~~~^~~~~~~
In file included from /usr/include/c++/8/cstdlib:75,
                 from /usr/include/c++/8/bits/stl_algo.h:59,
                 from /usr/include/c++/8/algorithm:62,
                 from /app/manifold/src/manifold/src/boolean_result.cpp:15:
/usr/include/stdlib.h: In function ‘std::tuple<manifold::VecDH<int>, manifold::VecDH<int> > {anonymous}::SizeOutput(manifold::Manifold::Impl&, const manifold::Manifold::Impl&, const manifold::Manifold::Impl&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::SparseIndices&, const manifold::SparseIndices&, bool, manifold::ExecutionPolicy)’:
/usr/include/stdlib.h:539:14: note: in a call to allocation function ‘void* malloc(size_t)’ declared here
 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
              ^~~~~~
cc1plus: all warnings being treated as errors
src/manifold/CMakeFiles/manifold.dir/build.make:92: recipe for target 'src/manifold/CMakeFiles/manifold.dir/src/boolean_result.cpp.o' failed
make[2]: *** [src/manifold/CMakeFiles/manifold.dir/src/boolean_result.cpp.o] Error 1
make[2]: Leaving directory '/app/manifold/build'
CMakeFiles/Makefile2:668: recipe for target 'src/manifold/CMakeFiles/manifold.dir/all' failed
make[1]: *** [src/manifold/CMakeFiles/manifold.dir/all] Error 2
make[1]: Leaving directory '/app/manifold/build'
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

Any idea what might cause this?

@geoffder
Copy link
Collaborator

Was this on a fresh clone/pull of the repo? It's definitely related to #450, I'll look more closely later to see which place it is coming from this time if this is indeed something still present after my did PR.

If it is another spot, I may make a branch and apply the same fix at the other similar malloc calls in that class and ask that you try to compile it on your machine.

@geoffder
Copy link
Collaborator

Can you try building this branch?

@emil-peters
Copy link
Author

Hi, it was indeed a fresh clone from the repo.
On your branch I'm getting the same error, now only at 24% completion. But it seems to be in the same file.

[ 24%] Building CXX object src/manifold/CMakeFiles/manifold.dir/src/boolean_result.cpp.o
cd /app/manifold/build/src/manifold && /usr/bin/c++ -Dmanifold_EXPORTS -I/app/manifold/src/manifold/include -I/app/manifold/src/utilities/include -I/app/manifold/src/third_party/thrust/dependencies/libcudacxx/include -I/app/manifold/src/third_party/thrust -I/app/manifold/src/third_party/glm/glm/.. -I/app/manifold/src/cross_section/include -I/app/manifold/src/third_party/clipper2/CPP/Clipper2Lib/include -I/app/manifold/src/collider/include -I/app/manifold/src/polygon/include -I/app/manifold/src/third_party/graphlite/include -O3 -DNDEBUG -fPIC -fPIC -Werror -Wall -Wno-sign-compare -Wno-unused -O3 -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP -std=gnu++17 -MD -MT src/manifold/CMakeFiles/manifold.dir/src/boolean_result.cpp.o -MF CMakeFiles/manifold.dir/src/boolean_result.cpp.o.d -o CMakeFiles/manifold.dir/src/boolean_result.cpp.o -c /app/manifold/src/manifold/src/boolean_result.cpp
In file included from /app/manifold/src/utilities/include/sparse.h:22,
                 from /app/manifold/src/collider/include/collider.h:17,
                 from /app/manifold/src/manifold/src/impl.h:18,
                 from /app/manifold/src/manifold/src/boolean3.h:16,
                 from /app/manifold/src/manifold/src/boolean_result.cpp:18:
In static member function ‘static void manifold::ManagedVec<T>::mallocManaged(T**, size_t) [with T = int]’,
    inlined from ‘std::tuple<manifold::VecDH<int>, manifold::VecDH<int> > {anonymous}::SizeOutput(manifold::Manifold::Impl&, const manifold::Manifold::Impl&, const manifold::Manifold::Impl&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::SparseIndices&, const manifold::SparseIndices&, bool, manifold::ExecutionPolicy)’ at /app/manifold/src/utilities/include/vec_dh.h:155:20:
/app/manifold/src/utilities/include/vec_dh.h:261:42: error: argument 1 value ‘18446744073709551612’ exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
       *ptr = reinterpret_cast<T *>(malloc(bytes));
                                    ~~~~~~^~~~~~~
In file included from /usr/include/c++/8/cstdlib:75,
                 from /usr/include/c++/8/bits/stl_algo.h:59,
                 from /usr/include/c++/8/algorithm:62,
                 from /app/manifold/src/manifold/src/boolean_result.cpp:15:
/usr/include/stdlib.h: In function ‘std::tuple<manifold::VecDH<int>, manifold::VecDH<int> > {anonymous}::SizeOutput(manifold::Manifold::Impl&, const manifold::Manifold::Impl&, const manifold::Manifold::Impl&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::VecDH<int>&, const manifold::SparseIndices&, const manifold::SparseIndices&, bool, manifold::ExecutionPolicy)’:
/usr/include/stdlib.h:539:14: note: in a call to allocation function ‘void* malloc(size_t)’ declared here
 extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
              ^~~~~~
cc1plus: all warnings being treated as errors
src/manifold/CMakeFiles/manifold.dir/build.make:92: recipe for target 'src/manifold/CMakeFiles/manifold.dir/src/boolean_result.cpp.o' failed
make[2]: *** [src/manifold/CMakeFiles/manifold.dir/src/boolean_result.cpp.o] Error 1
make[2]: Leaving directory '/app/manifold/build'
CMakeFiles/Makefile2:668: recipe for target 'src/manifold/CMakeFiles/manifold.dir/all' failed
make[1]: *** [src/manifold/CMakeFiles/manifold.dir/all] Error 2
make[1]: Leaving directory '/app/manifold/build'
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

@geoffder
Copy link
Collaborator

I'll push another thing for you to try tomorrow. What is your system and compiler by the way? GCC?

@emil-peters
Copy link
Author

I'm running Ubuntu 22

gccgcc (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0
cmakecmake version 3.20.1

@pca006132
Copy link
Collaborator

This is very weird, I feel like this may be due to interaction between signed and unsigned integers. I tried using GCC 8.4.1 and GCC 13.1.0 (a bit more complicated for other versions) and cannot reproduce this error. I forgot why I use signed integer for VecDH. This should probably be fixed as well.

@pca006132
Copy link
Collaborator

I wonder if this helps: https://github.com/pca006132/manifold/tree/size_t

If not, I will need to compile GCC 8.4.0 and have a look...

@geoffder
Copy link
Collaborator

Here is a more direct fix https://github.com/geoffder/manifold/tree/vec-dh-noinline (adding gcc's __attribute__((noinline)) to mallocManaged). Since the issue seems to only be with gcc so far, this may be all we need. If it somehow crops up in other compilers, we can always make a conditional #define INLINE that picks the correct invocation.

@pca006132
Copy link
Collaborator

Maybe we should just pass a -Wno-alloca-larger-than... Should be better than asking GCC to avoid inlining the functions (if it does not misoptimize the code)

@pca006132
Copy link
Collaborator

OK I found the following issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87544
Which includes an example very similar to our case, and it is known that GCC 8.4 will trigger that bug. I think we should just disable that warning.

@geoffder That allocation bug should be fixed for GCC 13.1, so it is weird that you triggered it in #450. At least for the example program in 87544, it did not trigger with GCC 13.1 and trunk, I cannot find the release info for 13.1.1 so this is pretty weird...

@geoffder
Copy link
Collaborator

🤔 it is definitely weird, as that is the version that I'm compiling with. Anyway, I'm sure that there are others out there that will be using gcc versions suffering from this for quite some time, so it may be a good idea to rule out the error with the noinline directive for now (at least it works for me, I'm curious to hear the results @emil-peters has on your branch and mine).

pca006132 added a commit to pca006132/manifold that referenced this issue Jun 21, 2023
@pca006132
Copy link
Collaborator

@geoffder wondering if your compiler will reproduce the bug in 87544:

#include <complex>
#include <iostream>
#include <limits>
#include <vector>

template<class T>
class my_allocator : public std::allocator<T>
{
public:
  typedef std::size_t     size_type;
  typedef std::ptrdiff_t  difference_type;
  typedef T*              pointer;
  typedef const T*        const_pointer;
  typedef T&              reference;
  typedef const T&        const_reference;
  typedef T               value_type;

  template<class U>
  struct rebind { typedef my_allocator<U> other; };

  my_allocator() : std::allocator<T>() {}
  my_allocator(const my_allocator& other) : std::allocator<T>(other) {}
  template<class U>
  my_allocator(const my_allocator<U>& other) : std::allocator<T>(other) {}
  ~my_allocator() {}

  pointer allocate(size_type num, const void* hint = 0)
  {
    std::size_t size = num * sizeof(T);
    void *result = std::malloc(size);
    if(size>16 && (std::size_t(result) & 15)!=0) {
      std::free(result);
      return 0;
    }
    return static_cast<pointer>( result );
  }

  void deallocate(pointer p, size_type /*num*/) { std::free(p); }
};


typedef std::complex<float> cplx;
int main() {
  std::vector<cplx, my_allocator<cplx> > v;
  v.push_back(cplx());
  return 0;
}

and I will open a PR to fix size_t inconsistency and disable the alloc size larger than warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants