stransky / berusky2

Berusky 2 (Bugs Escape 3D) is a game that challenges your visual/spatial thinking and ability to find a way to resolve a logic task. Using five bugs, you'll go through an adventure full of various puzzles spread across nine episodes. Individual episodes differ in appearance and difficulty, which increases throughout the game.
http://anakreon.cz/en/Berusky2.htm
GNU General Public License v3.0
14 stars 3 forks source link

undefined reference to `mmalloc' improper usage of inline functions #28

Closed apoleon closed 10 years ago

apoleon commented 10 years ago

Hi,

during a recent rebuild of Berusky2 on Debian's mips and mipsel ports we discovered that Berusky2 fails to build from source with gcc/g++ 4.9.

https://bugs.debian.org/755561

The same issue is reproducible when compiling Berusky2 with the clang compiler.

http://clang.debian.net/status.php?version=3.4.2&key=UNDEF_REF

Dejan Latinovic investigated the issue and provided a patch which I'm attaching to this bug report.

https://gist.github.com/7cbb86b3fd8ea36dce0f.git

Here are his findings:

"I have investigated this a little bit more This seems not to be a compile issue.

The reason for build failure on mips/mipsel is improper usage of inline functions.

For example in a file: src/age/graph/mesh.cpp a functions mmalloc is used. Declaration of mmalloc function is included from src/age/utils/mem_alloc.h, but a definition of the mentioned function is in src/komat/mmalloc.h.

mmalloc.h is not visible to mesh.cpp, and during compilation of mesh.cpp it is not possible to inline mmalloc function. So, object file mesh.o is created, but implementation of mmalloc function is missing. This is the reason of an error: mesh.cpp:59: undefined reference to `mmalloc' durign linking of berusky2on mips/mipsel with gcc-4.9.

Using gcc-4.8 on mips, in some other object file (in this case Berusky3d_light.o) it seems that compiler decided not to inline mmalloc function. As a result, during creating of berusky2, linker is capable to resolve mmalloc symbol, because Berusky3d_light.o contains implementation of mmalloc function. In ./komat/Berusky3d_light.cpp definition of mmalloc function is visible from src/komat/mmalloc.h

The same situation happens on amd64 with gcc-4.9, but in other object file: Keyframe.o.

The point is that we could not guarantee that inline function mmalloc would not be inlined in some cases. For mesh.cpp which is not aware of mmalloc definition, implementation of mmalloc during linking is needed.

Of course, we could use -fno-inline flag but, this seems to be wrong solution to me.

The same usage of mmalloc function without a definition visible, is noticed in files: age/utils/mem_alloc.cpp age/graph/gext.cpp age/utils/utils.cpp

The solution could be to include mmalloc.h in mem_alloc.h, so the definition of mmalloc function will be visible in all files where mmalloc function is used."

apoleon commented 10 years ago

https://gist.github.com/apoleon/7cbb86b3fd8ea36dce0f

stransky commented 10 years ago

Fixed by b282a3d2691d15fdf648f30bd7494fbb68078e9a Thanks!