oneTBB icon indicating copy to clipboard operation
oneTBB copied to clipboard

Fix build against musl libc

Open ismaell opened this issue 3 years ago • 9 comments

Description

Fix build against musl libc.

Probably MALLOC_UNIXLIKE_OVERLOAD_ENABLED only works with glibc, so use __GLIBC__ in addition to __linux__ to define it.

  • [x] - git commit message contains an appropriate signed-off-by string (see CONTRIBUTING.md for details)

Type of change

Choose one or multiple, leave empty if none of the other choices apply

Add a respective label(s) to PR if you have permissions

  • [x] bug fix - change that fixes an issue
  • [x] new feature - change that adds functionality
  • [ ] tests - change in tests
  • [ ] infrastructure - change in infrastructure and CI
  • [ ] documentation - documentation update

Tests

  • [ ] added - required for new features and some bug fixes
  • [x] not needed

Documentation

  • [ ] updated in # - add PR number
  • [ ] needs to be updated
  • [x] not needed

Breaks backward compatibility

  • [ ] Yes
  • [x] No
  • [ ] Unknown

Notify the following users

Other information

ismaell avatar Sep 09 '22 14:09 ismaell

can you link back to a build log of the failed compile, or a bug report where this is discussed? I was unable to reproduce with tbb-2021.7.0

stefson avatar Nov 14 '22 06:11 stefson

The error:

In file included from .../oneTBB/test/common/test.h:32,
                 from .../oneTBB/test/tbbmalloc/test_malloc_overload.cpp:45:
.../oneTBB/test/tbbmalloc/test_malloc_overload.cpp: In function 'void DOCTEST_ANON_FUNC_41()':
.../oneTBB/test/tbbmalloc/test_malloc_overload.cpp:400:13: error: 'mallopt' was not declared in this scope; did you mean 'malloc'?
  400 |     REQUIRE(mallopt(0, 0)); // add dummy mallopt call for coverage
      |             ^~~~~~~
.../oneTBB/test/common/doctest.h:1997:9: note: in definition of macro 'DOCTEST_WRAP_IN_TRY'
 1997 |         x;                                                                                         \
      |         ^
.../oneTBB/test/common/doctest.h:2249:9: note: in expansion of macro 'DOCTEST_ASSERT_IMPLEMENT_2'
 2249 |         DOCTEST_ASSERT_IMPLEMENT_2(assert_type, __VA_ARGS__);                                      \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
.../oneTBB/test/common/doctest.h:2268:30: note: in expansion of macro 'DOCTEST_ASSERT_IMPLEMENT_1'
 2268 | #define DOCTEST_REQUIRE(...) DOCTEST_ASSERT_IMPLEMENT_1(DT_REQUIRE, __VA_ARGS__)
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~
.../oneTBB/test/common/doctest.h:2743:22: note: in expansion of macro 'DOCTEST_REQUIRE'
 2743 | #define REQUIRE(...) DOCTEST_REQUIRE(__VA_ARGS__)
      |                      ^~~~~~~~~~~~~~~
.../oneTBB/test/tbbmalloc/test_malloc_overload.cpp:400:5: note: in expansion of macro 'REQUIRE'
  400 |     REQUIRE(mallopt(0, 0)); // add dummy mallopt call for coverage
      |     ^~~~~~~
compilation terminated due to -Wfatal-errors.
make[2]: *** [test/CMakeFiles/test_malloc_overload.dir/build.make:76: test/CMakeFiles/test_malloc_overload.dir/tbbmalloc/test_malloc_overload.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:4110: test/CMakeFiles/test_malloc_overload.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

ismaell avatar Nov 14 '22 10:11 ismaell

so this is a test failure?

stefson avatar Nov 14 '22 10:11 stefson

Musl doesn't provide mallopt nor mallinfo, so I guess it's more than that.

ismaell avatar Nov 14 '22 11:11 ismaell

In any case, assuming anything based on __linux__ alone is inappropriate.

ismaell avatar Nov 14 '22 11:11 ismaell

Musl does provide some non-standard bits like function malloc_usable_size, but it doesn't (and will never) provide any test macros.

ismaell avatar Nov 14 '22 11:11 ismaell

In any case, assuming anything based on __linux__ alone is inappropriate.

Is there specific macro for musl? If no, is it possible to pass it through cmake?

pavelkumbrasev avatar Nov 16 '22 12:11 pavelkumbrasev

In any case, assuming anything based on __linux__ alone is inappropriate.

Is there specific macro for musl? If no, is it possible to pass it through cmake?

No, musl doesn't define any such macros, intentionally.

Isn't this GLIBC-specific anyway?

The proper way would be to test the implementation to see if it's there, then define a macro based on that... but if that's not desirable, relying on the __GLIBC__ macro is a better way than relying on __linux__, in fact, these interfaces should be available with Glibc on non-Linux systems too...

ismaell avatar Nov 16 '22 13:11 ismaell

It seems that mallopt and mallinfo implemented in __GLIBC__ so we can use proposed approach. @ismaell Could you please update a copyright year from 2022 to 2023?

pavelkumbrasev avatar Jan 09 '23 13:01 pavelkumbrasev